mirror of https://github.com/yandex/gixy
add provide-variables to IfBlock, modifier ^~ to LocationBlock
parent
9f3c5768f8
commit
b6c71d62fd
|
@ -111,7 +111,7 @@ class LocationBlock(Block):
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def variables(self):
|
def variables(self):
|
||||||
if not self.modifier or self.modifier not in ('~', '~*'):
|
if not self.modifier or self.modifier not in ('~', '~*', '^~'):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
regexp = Regexp(self.path, case_sensitive=self.modifier == '~')
|
regexp = Regexp(self.path, case_sensitive=self.modifier == '~')
|
||||||
|
@ -124,6 +124,7 @@ class LocationBlock(Block):
|
||||||
class IfBlock(Block):
|
class IfBlock(Block):
|
||||||
nginx_name = 'if'
|
nginx_name = 'if'
|
||||||
self_context = False
|
self_context = False
|
||||||
|
provide_variables = True
|
||||||
|
|
||||||
def __init__(self, name, args):
|
def __init__(self, name, args):
|
||||||
super(IfBlock, self).__init__(name, args)
|
super(IfBlock, self).__init__(name, args)
|
||||||
|
@ -143,6 +144,17 @@ class IfBlock(Block):
|
||||||
else:
|
else:
|
||||||
raise Exception('Unknown "if" definition, args: {0!r}'.format(args))
|
raise Exception('Unknown "if" definition, args: {0!r}'.format(args))
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def variables(self):
|
||||||
|
if self.operand != '~':
|
||||||
|
return []
|
||||||
|
|
||||||
|
regexp = Regexp(self.value, case_sensitive=self.operand == '~')
|
||||||
|
result = []
|
||||||
|
for name, group in regexp.groups.items():
|
||||||
|
result.append(Variable(name=name, value=group, boundary=None, provider=self))
|
||||||
|
return result
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{name} ({args}) {{'.format(name=self.name, args=' '.join(self.args))
|
return '{name} ({args}) {{'.format(name=self.name, args=' '.join(self.args))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue