Skip to content

precompiled mixins & just-in-time mixins #10

@jeromew

Description

@jeromew

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 !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions