Skip to content

Commit

Permalink
Changed jade.render to jade.compile and moved it to helpers.render in…
Browse files Browse the repository at this point in the history
…stead
  • Loading branch information
Alex Young committed Sep 3, 2011
1 parent 4e41d1a commit ac4728e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
15 changes: 10 additions & 5 deletions lib/helpers.js
Expand Up @@ -15,6 +15,11 @@ var jade = require('jade')
, helpers;

helpers = {
render: function(template, options) {
var fn = jade.compile(template, options);
return fn(options.locals);
},

/**
* Pagination links.
*
Expand Down Expand Up @@ -44,7 +49,7 @@ helpers = {
template += ' - if (paginator.nextPage <= paginator.pages)\n';
template += ' a.next(href="/page" + paginator.nextPage + "/") Next\n';
template += ' span &rarr;\n';
return jade.render(template, { locals: { paginator: paginator } });
return helpers.render(template, { locals: { paginator: paginator } });
},

/**
Expand All @@ -59,7 +64,7 @@ helpers = {
template = ''
+ '- for (var i = 0; i < paginator.items.length; i++)\n'
+ ' !{hNews(paginator.items[i], true)}\n';
return jade.render(template, { locals: site.applyHelpers({ paginator: site.paginator }) });
return helpers.render(template, { locals: site.applyHelpers({ paginator: site.paginator }) });
},

/**
Expand Down Expand Up @@ -105,7 +110,7 @@ helpers = {
else
template += ' content(type="html") !{h(post.content)}\n';

return jade.render(template, { locals: site.applyHelpers({
return helpers.render(template, { locals: site.applyHelpers({
paginator: site.paginator
, posts: posts
, title: title
Expand Down Expand Up @@ -163,7 +168,7 @@ helpers = {
else
template += ' description !{h(post.content)}\n';

return jade.render(template, { locals: site.applyHelpers({
return helpers.render(template, { locals: site.applyHelpers({
paginator: site.paginator
, posts: posts
, title: title
Expand Down Expand Up @@ -261,7 +266,7 @@ helpers = {
} else {
template += ' !{post.content}\n';
}
return jade.render(template, { locals: this.applyHelpers({ post: post }) });
return helpers.render(template, { locals: this.applyHelpers({ post: post }) });
},

/**
Expand Down
12 changes: 6 additions & 6 deletions lib/site_builder.js
Expand Up @@ -253,7 +253,7 @@ SiteBuilder.prototype.autoGenerateFile = function(file, fn) {
console.error('Error: Built-in feed generation requires config values for: url and title.');
} else {
var layoutData = "!{atom('" + this.config.url + '/' + file.feed + "')}"
, html = jade.render(layoutData, { locals: self.applyHelpers({ }) });
, html = helpers.render(layoutData, { locals: self.applyHelpers({ }) });
this.write(this.outFileName(file.feed), html);
fn();
}
Expand All @@ -264,7 +264,7 @@ SiteBuilder.prototype.autoGenerateFile = function(file, fn) {
console.error('Error: Built-in feed generation requires config values for: url and title.');
} else {
var layoutData = "!{rss('" + this.config.url + '/' + file.rss + "')}"
, html = jade.render(layoutData, { locals: self.applyHelpers({ }) });
, html = helpers.render(layoutData, { locals: self.applyHelpers({ }) });
this.write(this.outFileName(file.rss), html);
fn();
}
Expand Down Expand Up @@ -486,7 +486,7 @@ SiteBuilder.prototype.cacheIncludes = function() {
} else {
fs.readFile(path.join(self.root, '_includes', file), 'utf8', function(err, data) {
// TODO: This won't cope with _include/file/file, but people will expect this
var html = jade.render(data, { locals: self.applyHelpers({}) })
var html = helpers.render(data, { locals: self.applyHelpers({}) })
, name = path.basename(file).replace(path.extname(file), '');
self.includes[name] = html;

Expand Down Expand Up @@ -519,7 +519,7 @@ SiteBuilder.prototype.renderTemplate = function(templateFile, post, content) {
}

try {
var html = jade.render(data, { locals: self.applyHelpers({ post: post, content: content }) })
var html = helpers.render(data, { locals: self.applyHelpers({ post: post, content: content }) })
, fileName = self.outFileName(post.fileName, 'index.html')
, dirName = path.dirname(fileName);
} catch (e) {
Expand Down Expand Up @@ -577,14 +577,14 @@ SiteBuilder.prototype.renderFile = function(file, fn) {
path.basename(file.name).replace(path.extname(file.name), ext)
);

var fileContent = jade.render(fileData, {
var fileContent = helpers.render(fileData, {
locals: self.applyHelpers({ paginator: self.paginator, page: meta }),
});

if (!layoutData) {
self.write(outFileName, fileContent);
} else {
var html = jade.render(layoutData, { locals: self.applyHelpers({ content: fileContent }) });
var html = helpers.render(layoutData, { locals: self.applyHelpers({ content: fileContent }) });
self.write(outFileName, html);
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{ "name": "pop"
, "description": "A static website and blog generator"
, "version": "0.1.3"
, "version": "0.1.4"
, "url": "http://popjs.com"
, "author": "Alex R. Young <alex@helicoid.net>"
, "engines": ["node >= 0.4.7"]
Expand All @@ -12,8 +12,8 @@
, "underscore.date": "0.5.x"
, "stextile": "latest"
, "nodewatch": "latest"
, "jade": "0.13.0"
, "stylus": "0.13.7"
, "jade": "0.15.3"
, "stylus": "0.15.1"
}
, "devDependencies": {
"dox": "latest"
Expand Down

0 comments on commit ac4728e

Please sign in to comment.