diff --git a/src/model/nodes/base.js b/src/model/nodes/base.js index adfbd6c..2c2ac3a 100644 --- a/src/model/nodes/base.js +++ b/src/model/nodes/base.js @@ -35,7 +35,8 @@ BaseNode.prototype = { AUTHOR: 'author', AUTHORS: 'authors', TAGS: 'tags', - BLOCK: 'block' + BLOCK: 'block', + SHOWCASE: 'showcase' }, TYPE: { SIMPLE: 'simple', diff --git a/src/model/nodes/index.js b/src/model/nodes/index.js index b9dba8f..5e84a8a 100644 --- a/src/model/nodes/index.js +++ b/src/model/nodes/index.js @@ -6,3 +6,4 @@ exports.post = require('./post'); exports.level = require('./level'); exports.person = require('./person'); exports.version = require('./version'); +exports.showcase = require('./showcase'); diff --git a/src/model/nodes/showcase.js b/src/model/nodes/showcase.js new file mode 100644 index 0000000..8f2143d --- /dev/null +++ b/src/model/nodes/showcase.js @@ -0,0 +1,76 @@ +var util = require('util'), + utility = require('../../util'), + nodes = require('./index'), + + /** + * Subclass of dynamic nodes which describe showcase pagr + * @param {VersionNode} parent node object + * @param {Object} version - library version object + * @param {Object} showcase object + * @constructor + */ + ShowcaseNode = function (parent, version, showcase) { + this.setTitle(showcase) + .setSource(showcase) + .processRoute(parent, { + conditions: { + lib: version.repo, + version: version.ref, + id: showcase.title + } + }) + .init(parent) + .setView() + .createBreadcrumbs(); + }; + +ShowcaseNode.prototype = Object.create(nodes.dynamic.DynamicNode.prototype); + +/** + * Sets title for node + * @param {Object} showcase object + * @returns {ShowcaseNode} + */ +ShowcaseNode.prototype.setTitle = function (showcase) { + this.title = utility.getLanguages().reduce(function (prev, lang) { + prev[lang] = showcase.title; + return prev; + }, {}); + return this; +}; + +/** + * Sets source for node + * @param {Object} showcase object + * @returns {ShowcaseNode} + */ +ShowcaseNode.prototype.setSource = function (showcase) { + this.content = showcase.content; + return this; +}; + +/** + * Sets class for node + * @returns {ShowcaseNode} + */ +ShowcaseNode.prototype.setClass = function () { + this.class = 'showcase'; + return this; +}; + +/** + * Sets view for node + * @returns {ShowcaseNode} + */ +ShowcaseNode.prototype.setView = function () { + this.view = this.VIEW.SHOWCASE; + return this; +}; + +ShowcaseNode.prototype.saveToDb = function () { + this.parent = this.parent.id; + return { type: 'put', key: this.generateKey(), value: this }; +}; + +exports.ShowcaseNode = ShowcaseNode; + diff --git a/src/model/nodes/version.js b/src/model/nodes/version.js index b0813ed..7e6a791 100644 --- a/src/model/nodes/version.js +++ b/src/model/nodes/version.js @@ -170,10 +170,14 @@ VersionNode.prototype.addItems = function (version) { this.items.push(new nodes.post.PostNode(this, version, docs[item], item)); }, this); - // TODO implement it + if (version['showcase']) { + var showcaseItem = new nodes.showcase.ShowcaseNode(this, version, version['showcase']); + this.items.push(showcaseItem); + } + // add custom nodes to library version - if (version.custom) { - version.custom.forEach(function (item) { + if (version['custom']) { + version['custom'].forEach(function (item) { item.url += '#'; var cItem = new nodes.base.BaseNode(item, this); cItem.saveToDb = function () {