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

Tag interpolation #239

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

char101
Copy link
Contributor

@char101 char101 commented Dec 30, 2015

Tag interpolation [jade issue] [jade commit]

mixin test(tag)
  #{tag} text

+test('div')

Also fix a bug in ext/html.py

def _make_mixin(self, mixin):
    arg_names = [arg.strip() for arg in mixin.args.split(",")]
    def _mixin(self, args):
        if args:
            arg_values = self._do_eval(args)
        else:
            arg_values = []
        if not isinstance(arg_values, (list, tuple)):
            arg_values = [arg_values]
        local_context = dict(zip(arg_names, arg_values))
        with local_context_manager(self, local_context):
            self.visitBlock(mixin.block)
    return _mixin

If arg_values is a string, then local_context will map the parameters into the characters of the string instead of the string value.

@smaudet
Copy link

smaudet commented Dec 30, 2015

I confirmed that at least one extension is broken, and added a test case.

I have merged this locally and will re-issue a new PR with test-cases/fixes.

@smaudet smaudet mentioned this pull request Dec 30, 2015
@char101
Copy link
Contributor Author

char101 commented Dec 31, 2015

RE_BLOCK = re.compile(r'''^block(( +(?:(prepend|append) +)?([^\n]*))|(?=\n))''')

Changed \n at the end to be a lookahead, otherwise the else statement in the example below will not be parsed as a conditional.

mixin test(a)
  if a
    block
  else
    block

@kakulukia
Copy link

Since there are no updates to pyjade and its successor recently was deleted from pypi, I took the liberty to revive it: https://github.com/kakulukia/pypugjs

Version 5.0.1 has fixed the incompatibility with recent Django versions.

I have never really worked with mixins so far because i found no clever way of using them in extended templates and thus keep using partials instead. I'd be happy to include this fix in a new release tho if you resubmit the PR to my repo.

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

Successfully merging this pull request may close these issues.

3 participants