Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set data/locals for processing #276

Open
danr opened this issue Mar 21, 2017 · 0 comments
Open

Set data/locals for processing #276

danr opened this issue Mar 21, 2017 · 0 comments

Comments

@danr
Copy link

danr commented Mar 21, 2017

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant