Skip to content

Commit

Permalink
Added support for pages containing an example array.
Browse files Browse the repository at this point in the history
    This patch modifies the default view so that it
    searchs pages for example data that is can't
    find at the top level.
  • Loading branch information
davglass committed Jan 19, 2012
1 parent b649901 commit 6065c15
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions lib/view/index.js
Expand Up @@ -7,9 +7,38 @@ Licensed under the BSD License.
var util = require('../util'); // Selleck's util, not Node's util.

function View(data, templateName) {
var self = this;

this.templateName = templateName;

util.mix(this, data);

if (this.pages) {
// If the name of the current template matches the name of a page
// with custom metadata, mix the page's metadata into the view.
if (this.pages[this.templateName]) {
this.page = true;
util.mix(this, this.pages[this.templateName]);
} else {
/*
Template name was not found in this pages list, so walk all the pages and
see if any of them contain this example. If it does, then
mix the data in and reset the `self.examples` before the
below code mixes them.
*/
util.each(self.pages, function(n) {
if (n.examples) {
util.each(n.examples, function(e, k) {
if (e.name === self.templateName) {
util.mix(self, e);
self.examples = n.examples;
}
});
}
});
}
}

if (this.examples) {
this.examples.forEach(function (example) {
// If the name of the current template matches the name of an
Expand All @@ -20,15 +49,6 @@ function View(data, templateName) {
}
}, this);
}

if (this.pages) {
// If the name of the current template matches the name of a page
// with custom metadata, mix the page's metadata into the view.
if (this.pages[this.templateName]) {
this.page = true;
util.mix(this, this.pages[this.templateName]);
}
}
}

View.prototype = {
Expand Down

0 comments on commit 6065c15

Please sign in to comment.