def parse(self, parser):
# the first token is the token that started the tag. In our case
# we only listen to ``'webpack'`` so this will be a name token with
# `webpack` as value. We get the line number so that we can give
# that line number to the nodes we create by hand.
lineno = six.next(parser.stream).lineno
ctx_ref = nodes.ContextReference()
# Parse a single expression that is the 'bundle' or 'config:bundle'
args = [ctx_ref, parser.parse_expression()]
# if there is a comma, the user provided an 'extensions' arg
if parser.stream.skip_if('comma'):
args.append(parser.parse_expression())
else:
args.append(nodes.Const(None))
# now we parse the body of the cache block up to `endwebpack` and
# drop the needle (which would always be `endwebpack` in that case)
body = parser.parse_statements(['name:endwebpack'], drop_needle=True)
call_args = [nodes.Name('ASSET', 'param')]
return nodes.CallBlock(self.call_method('_get_graph', args), call_args,
[], body).set_lineno(lineno)
python类ContextReference()的实例源码
def parse(self, parser):
lineno = next(parser.stream).lineno
# get the context
context = nodes.ContextReference()
# get the arguments
args = [context]
try:
while True:
args.append(parser.parse_expression())
except TemplateSyntaxError:
pass # no more arguments
# get the tag_name for use in looking up callable
self.active_tag = parser._tag_stack[-1]
# create the node
node = self.call_method('_invoke_tag', args=args, lineno=lineno)
return nodes.Output(
[node],
lineno=lineno
)
def parse(self, parser):
return nodes.Output([self.call_method('_dump', [
nodes.EnvironmentAttribute('sandboxed'),
self.attr('ext_attr'),
nodes.ImportedName(__name__ + '.importable_object'),
nodes.ContextReference()
])]).set_lineno(next(parser.stream).lineno)
def parse(self, parser):
return nodes.Output([self.call_method('_dump', [
nodes.EnvironmentAttribute('sandboxed'),
self.attr('ext_attr'),
nodes.ImportedName(__name__ + '.importable_object'),
nodes.ContextReference()
])]).set_lineno(next(parser.stream).lineno)
def parse(self, parser):
return nodes.Output([self.call_method('_dump', [
nodes.EnvironmentAttribute('sandboxed'),
self.attr('ext_attr'),
nodes.ImportedName(__name__ + '.importable_object'),
nodes.ContextReference()
])]).set_lineno(next(parser.stream).lineno)
def parse(self, parser):
return nodes.Output([self.call_method('_dump', [
nodes.EnvironmentAttribute('sandboxed'),
self.attr('ext_attr'),
nodes.ImportedName(__name__ + '.importable_object'),
nodes.ContextReference()
])]).set_lineno(next(parser.stream).lineno)
def parse(self, parser):
return nodes.Output([self.call_method('_dump', [
nodes.EnvironmentAttribute('sandboxed'),
self.attr('ext_attr'),
nodes.ImportedName(__name__ + '.importable_object'),
nodes.ContextReference()
])]).set_lineno(next(parser.stream).lineno)