Permalink
Browse files

Added support for pages containing an example array.

    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...
1 parent b649901 commit 6065c15e01e253b8d7c9f28d76d28c5665671710 @davglass davglass committed Jan 19, 2012
Showing with 29 additions and 9 deletions.
  1. +29 −9 lib/view/index.js
View
@@ -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
@@ -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 = {

0 comments on commit 6065c15

Please sign in to comment.