def parse(self, parser):
lineno = next(parser.stream).lineno
parts = [parser.stream.expect('name').value]
while parser.stream.current.type != 'block_end':
parser.stream.expect('dot')
parts.append(parser.stream.expect('name').value)
body = parser.parse_statements(['name:endeditable'], drop_needle=True)
call = self.call_method(
'_editable_loader',
[nodes.Name(parts[-2], 'load'), nodes.Const(parts[-1])])
output_nodes = [nodes.Output([
nodes.MarkSafe(nodes.TemplateData('<div class="editable-container">')),
nodes.MarkSafe(nodes.TemplateData('<div class="editable-content">'))])
]
output_nodes.extend(body)
output_nodes.extend([
nodes.Output([nodes.MarkSafe(nodes.TemplateData('</div>'))]),
nodes.Output([nodes.MarkSafe(call)]),
nodes.Output([nodes.MarkSafe(nodes.TemplateData('</div>'))])
])
block_name = '%s_%s_%d' %(parts[-2], parts[-1], random.randint(0, 500))
return nodes.Block(block_name, output_nodes, True)
评论列表
文章目录