pyjade icon indicating copy to clipboard operation
pyjade copied to clipboard

Include and Extends support for mixins in Django

Open andrewboltachev opened this issue 11 years ago • 1 comments

Include and extends support was already discussed here (https://github.com/SyrusAkbary/pyjade/issues/38 and https://github.com/SyrusAkbary/pyjade/issues/112). So, for now support of that features is only for Django and Jinja2 template engines (if I'm correct).

And, I'm using Django and have figured out interesting things regarding Django and PyJade:

  1. include for Django transformes into just {% include %} tag, that means that, e,g. file with mixins only transforms into nothing (it's possible only to use mixins defined in the same file).
  2. There is __pyjade__loadkwacros template tag, but it is unused by compiler.
  3. Macros support for Django (which doesn't exists by default) is implemented by using https://gist.github.com/skyl/1715202 or suchlike snippet, where tags prefixed with "__pyjade" (btw, last version seems to be there https://gist.github.com/SAPikachu/5097591).

I decided to try to implement some support of "loading macros via include and extends: and there's the result https://github.com/andrewboltachev/pyjade/tree/9ec8c77e6b04866632c8ea5f7327e23e712575a4 Run testproj Django project for test and you must see sth like that:

hicolorname

Two things that I used to do that, are:

  1. To combine {% include %} and {% extends %} tags with {% __pyjade_loadkwacros %} for corresponding template
  2. To add support for recursive kwarco loading with { __pyjade_loadkwacro %}

So, I want to hear, is that good/useful idea, or not, are is there another ways to do that?

andrewboltachev avatar Aug 07 '13 22:08 andrewboltachev

If you want to imitate the javascript jade version, your solution seems to be practical. The only problem is sometimes you may not need the 1:1 parity, and enabling this always could affect the performance.

Anyway, I think this behavior should be enabled vía some var in django settings (for example)

:+1:

syrusakbary avatar Aug 07 '13 22:08 syrusakbary