SakartveloSoft / jade-dynamic-includes

Dynamic includes support for Jade rendering engine
MIT License
3 stars 1 forks source link

Gulp example #2

Open AbraaoAlves opened 9 years ago

AbraaoAlves commented 9 years ago

I use gulp to process jade with gulp-jade and I have this:

each section in ['init', 'about', 'sales']
  != renderTemplate(section)

What do I do?

koteisaev commented 9 years ago

There is a problem with current version of this package. It strictly bound to response lifecycle/context. Code needs upgrade to work with other contexts like jade-gulp. When I created that package, I was unaware of pre-compilation of jade to html and other gulp-related stuff. I think that while it is possible to cook good parameters initTemplates right now in the gulp context, the true problems will go with this piece of code: attachTemplatesToRequest : function() { return function (req, res, next) {

        if (!req.locals) {
            req.locals = {};
        }
        var requestTemplates = getTemplates(res);
        req.locals.templates = requestTemplates;
        req.locals.knownTemplates = knownTemplates;
        if (!res.locals) {
            res.locals = {};
        }
        res.locals.templates = requestTemplates;
        res.locals.knownTemplates = knownTemplates;
        res.locals.renderTemplate = invokeRenderTemplate.bind(null, res.locals);

        return next();
    };
},

And the invokeRenderTemplate implementation is following (guess this code does not need a change, but just pasting it to give clear understanding how it all works):

function invokeRenderTemplate(requestOptons, name, options) { var opts = {}; for(var p in requestOptons) { opts[p] = requestOptons[p]; } if (options) { for (var p in options) { opts[p] = requestOptons[p]; } } return templates.itemsname; }