Permalink
Browse files

Add partials-referencing partials support.

  • Loading branch information...
1 parent d54c36c commit 08b42f5d4d8d3c85ea95276fbc882d5c52f83b7b @cliffano committed Dec 10, 2011
Showing with 22 additions and 18 deletions.
  1. +0 −1 examples/layouts/alternative.html
  2. +0 −1 examples/layouts/default.html
  3. +2 −1 examples/partials/header.html
  4. +19 −14 lib/engine.js
  5. +1 −1 test/engine.js
@@ -6,7 +6,6 @@
</head>
<body>
{include('header.html')}
-{include('common/nav.html')}
{content}
{include('footer.html')}
</body>
@@ -6,7 +6,6 @@
</head>
<body>
{include('header.html')}
-{include('common/nav.html')}
{content}
{include('footer.html')}
</body>
@@ -1,3 +1,4 @@
<div id="header">
<h1>{site.name}</h1>
-</div>
+</div>
+{include('common/nav.html')}
View
@@ -59,25 +59,30 @@ function process(dir, pages, layouts, partials, params, cb) {
// evaluate all partials with params for current context
_process(partials, partialsParams, function (result) {
context.partials = result;
- var pageParams = _.extend(params, prms.params(context));
- // evaluate page with partials-populated
- _process({ 'currpage': pages[page] }, pageParams, function (result) {
- var layoutParams = _.clone(pageParams);
- layoutParams.content = result.currpage;
+ // evaluate all partials the second time for partials referencing other partials
+ _process(partials, partialsParams, function (result) {
+ context.partials = result;
+ var pageParams = _.extend(params, prms.params(context));
- // evaluate layout with current page as its content
- var layout = (params.sitemap && params.sitemap[page] && params.sitemap[page].layout) ?
- params.sitemap[page].layout : 'default.html';
- f.mkdirs(p.join(dir, page).replace(/\/[^\/]+$/, ''), '0755', function (err) {
- _process({ 'currlayout': layouts[layout] }, layoutParams, function (result) {
- fs.writeFile(p.join(dir, page), result.currlayout, 'utf8', function (err) {
- console.log('+ creating ' + p.join(dir, page));
- cb(null);
+ // evaluate page with partials-populated
+ _process({ 'currpage': pages[page] }, pageParams, function (result) {
+ var layoutParams = _.clone(pageParams);
+ layoutParams.content = result.currpage;
+
+ // evaluate layout with current page as its content
+ var layout = (params.sitemap && params.sitemap[page] && params.sitemap[page].layout) ?
+ params.sitemap[page].layout : 'default.html';
+ f.mkdirs(p.join(dir, page).replace(/\/[^\/]+$/, ''), '0755', function (err) {
+ _process({ 'currlayout': layouts[layout] }, layoutParams, function (result) {
+ fs.writeFile(p.join(dir, page), result.currlayout, 'utf8', function (err) {
+ console.log('+ creating ' + p.join(dir, page));
+ cb(null);
+ });
});
});
});
- });
+ });
});
};
});
View
@@ -110,7 +110,7 @@ vows.describe('engine').addBatch({
_results = results;
});
// each partial and layout is processed once per page
- assert.equal(processCount, 6);
+ assert.equal(processCount, 8);
assert.equal(mkdirsPaths.length, 2);
assert.equal(mkdirsPaths[0], 'out');
assert.equal(mkdirsPaths[1], 'out/product');

0 comments on commit 08b42f5

Please sign in to comment.