Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow pages to contain examples #8

Merged
merged 2 commits into from

2 participants

@davglass

This patch modifies the default view so that it searches pages for example data that is can't find at the top level.

davglass added some commits
@davglass davglass 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.
6065c15
@davglass davglass Expanded variable names f0bd26c
@rgrove rgrove merged commit f0bd26c into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 19, 2012
  1. @davglass

    Added support for pages containing an example array.

    davglass authored
        This patch modifies the default view so that it
        searchs pages for example data that is can't
        find at the top level.
  2. @davglass

    Expanded variable names

    davglass authored
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 9 deletions.
  1. +29 −9 lib/view/index.js
View
38 lib/view/index.js
@@ -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(page) {
+ if (page.examples) {
+ util.each(page.examples, function(example) {
+ if (example.name === self.templateName) {
+ util.mix(self, example);
+ self.examples = page.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 = {
Something went wrong with that request. Please try again.