Skip to content

Commit

Permalink
Implement build of showcase page custom node
Browse files Browse the repository at this point in the history
  • Loading branch information
tormozz48 committed Mar 23, 2015
1 parent 25d091a commit e3be38b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/model/nodes/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ BaseNode.prototype = {
AUTHOR: 'author',
AUTHORS: 'authors',
TAGS: 'tags',
BLOCK: 'block'
BLOCK: 'block',
SHOWCASE: 'showcase'
},
TYPE: {
SIMPLE: 'simple',
Expand Down
1 change: 1 addition & 0 deletions src/model/nodes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ exports.post = require('./post');
exports.level = require('./level');
exports.person = require('./person');
exports.version = require('./version');
exports.showcase = require('./showcase');
76 changes: 76 additions & 0 deletions src/model/nodes/showcase.js
Original file line number Diff line number Diff line change
@@ -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;

10 changes: 7 additions & 3 deletions src/model/nodes/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit e3be38b

Please sign in to comment.