pyjade icon indicating copy to clipboard operation
pyjade copied to clipboard

Set data/locals for processing

Open danr opened this issue 7 years ago • 0 comments

I cannot find a function to set the locals for processing jade. I'm attaching the workaround I'm using for now below (a little test included), but I'm surprised that this does not seem to be in the API out of the box, so I'm reporting this as a missing feature.

import pyjade
from pyjade.ext.html import HTMLCompiler

def process_jade(src, data={}):
    parser = pyjade.parser.Parser(src)
    block = parser.parse()
    compiler = HTMLCompiler(block, pretty=True)
    compiler.global_context.update(data)
    return compiler.compile()

print(process_jade("""
!!! 5
html
  body
    ul
      each val in my_list
        li= val
""", dict(my_list=[1, 2, 3])))

Thanks!

danr avatar Mar 21 '17 15:03 danr