pugjs/then-pug

precompiled mixins & just-in-time mixins

Opened this issue · 0 comments

With commit c4950ea I added the capability to share a jade_mixins store between renderings.

if locals.jade_mixins is an object when a rendering is done, then this object will be filled with all the mixin functions that were found and compiled in the template (this is an upsert mechanism)

The rendering of another template with the same locals.jade_mixins object will be able to reuse those mixins via the dynamic mixins notation +#{name}(...)

With this commit, nothing is done to make sure that the shared mixin will use the same bufas a new rendering. In effect, they DO NOT have the same bufso a trivial setup will not work.

At this stage, the recommended way to make sure that a shared mixin is effectively rendered where it should be is to make sure that the mixins begin with the prototype (jade, buf, ..) and are called with those 2 vars :

// - template1.jade
mixin myMixin(jade, buf, message)
  h2= message

// - template2.jade
+#{"myMixin"}(jade, buf, "hello world");

This feature not only enables mixin sharing, but can also be used for just-in-time mixin compilation since a mixin yields and can take care of the mixin compilation asynchronously.

@ForbesLindesay I moved the discussion we started on jade here. Any toughts are welcome !