dundee / express-hogan.js Goto Github PK
View Code? Open in Web Editor NEWNode.js module for using Hogan templating system within Express framework
Node.js module for using Hogan templating system within Express framework
Hi, i've an issue with preparePartials
PROJECT_PATH/node_modules/express/lib/application.js:506
fn(err);
^
TypeError: object is not a function
at Function.app.render (PROJECT_PATH/pushserver/node_modules/express/lib/application.js:506:5)
at ServerResponse.res.render (PROJECT_PATH/DEV/pushserver/node_modules/express/lib/response.js:601:7)
at exports.index (PROJECT_PATH/pushserver/routes/dashboard.js:40:25)
at _.after (PROJECT_PATH/pushserver/node_modules/express-hogan.js/node_modules/underscore/underscore.js:609:38)
at expressHogan.preparePartials (PROJECT_PATH/DEV/pushserver/node_modules/express-hogan.js/lib/express-hogan.js:47:12)
at fs.readFile (fs.js:176:14)
at Object.oncomplete (fs.js:297:15)
my apps crash and no partials is loade... actually nothing is loaded :P
i need some help please :(
Currently tj merged in hjs - which seems way worse then what you have here (doesn't seem to support partials, etc.).
Would be cool to update this plugin and get it merged instead
I just installed this, using npm. When requiring your lib within nodejs, the package name appears to be "express-hogan.js", and that is how you have to require it (require('express-hogan.js')).
I'm not sure if this was intended or not, but based on your test application it doesn't look like it was. Just thought I'd mention this. I don't know how to fix this, because I've never submitted anything to npm before, otherwise I'd try to offer more assistance and perhaps a pull request.
In the preparePartials function, the readFile function should be called as a closure. Currently only the last partial is being loaded. Please see the code with the fix below.
expressHogan.preparePartials = function(root, partials, func) {
var sources = {};
var ready = _.after(partials.length, func);
for (var i in partials) {
(function(i){
fs.readFile(root + '/' + partials[i] + '.html', function(err, data) {
if (err) {
console.log(err);
return;
}
sources[partials[i]] = data.toString('utf8');
ready(sources);
})})(i);
}
};
Hello,
The variables defined in the dynamicHelpers are not available in the views. I tried applying the fix suggested in Medium/matador#28 and it worked. Below is the modified code.
expressHogan.compile = function(source, options) {
if (typeof source == 'string') {
return function(options) {
options.locals = options.locals || {};
options.partials = options.partials || {};
if (options.body) {
options.locals.body = options.body;
}
for (var i in options.app.dynamicViewHelpers) {
options.locals[i] = options[i];
}
var template = hogan.compile(source);
for (var i in options.partials) {
if (typeof options.partials[i].r == 'function') continue;
options.partials[i] = hogan.compile(options.partials[i]);
}
return template.render(options.locals, options.partials);
};
} else {
return source;
}
};
I have my index.mustache
including a partial tag {{> form}}
and the partial is put under the same path.
However, the partial doesn't load at all.
There is not enough doc in the testapp.js
to indicate correct usage of partials, would you help in this case?
I use the following code to render the template:
app.get('/', function (req, res) {
res.render('home');
})
In my layout.html file (app/views/layout.html)
, I've got the following:
{{> _header }}
which I'd like to basically render the partial from app/views/partials/_header.html
. That partials' never being loaded when I access the page, though. This worked great in Matador, but isn't working with express.
Any ideas on what else I'd need to do?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.