Skip to content

Tag interpolation#239

Open
char101 wants to merge 3 commits intosyrusakbary:masterfrom
char101:feature/element-interpolation
Open

Tag interpolation#239
char101 wants to merge 3 commits intosyrusakbary:masterfrom
char101:feature/element-interpolation

Conversation

@char101
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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
Copy Markdown

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