Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load_template(self, path):
""" Load and compile a template. """
if not path.startswith('/'):
path = op.join(self.options['template_folder'], path)
with open(path, 'rb') as f:
source = f.read().decode(self.options['encoding'])
return ExtendCompiler(
pyjade.parser.Parser(source).parse(), pretty=self.options['pretty'],
env=self, compileDebug=True
)
def __init__(self, node, env, **options):
""" Initialize the compiler. """
super(ExtendCompiler, self).__init__(node, **options)
self.env = env
self.blocks = {node.name: node for node in self.node.nodes if isinstance(node, CodeBlock)}
while self.node.nodes and isinstance(self.node.nodes[0], Extends):
compiler = self.env.get_template(self.node.nodes[0].path)
self.node = compiler.node
for cblock in compiler.blocks.values():
if cblock.name in self.blocks:
sblock = self.blocks[cblock.name]
if sblock.mode == 'prepend':
sblock.nodes = sblock.nodes + cblock.nodes
elif sblock.mode == 'append':
sblock.nodes = cblock.nodes + sblock.nodes
else:
self.blocks[cblock.name] = cblock