summaryrefslogtreecommitdiffstats
path: root/lib/models/templateOutput.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-05-05 11:00:05 +0200
committerSamy Pesse <samypesse@gmail.com>2016-05-05 11:00:05 +0200
commit34947b5e207e84ef43a8194c0ec7bac19dccf709 (patch)
tree06e687700d95590cae678f8bef381e8a62dc0129 /lib/models/templateOutput.js
parentc621380b664bcbef087df571b662e7a34e098168 (diff)
downloadgitbook-34947b5e207e84ef43a8194c0ec7bac19dccf709.zip
gitbook-34947b5e207e84ef43a8194c0ec7bac19dccf709.tar.gz
gitbook-34947b5e207e84ef43a8194c0ec7bac19dccf709.tar.bz2
Add mode TemplateOutput to represent {content + blocks} from template
Diffstat (limited to 'lib/models/templateOutput.js')
-rw-r--r--lib/models/templateOutput.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/models/templateOutput.js b/lib/models/templateOutput.js
new file mode 100644
index 0000000..cd65a05
--- /dev/null
+++ b/lib/models/templateOutput.js
@@ -0,0 +1,44 @@
+var Immutable = require('immutable');
+
+var TemplateOutput = Immutable.Record({
+ // Text content of the template
+ content: String(),
+
+ // Map of blocks to replace / post process
+ blocks: Immutable.Map()
+}, 'TemplateOutput');
+
+TemplateOutput.prototype.getContent = function() {
+ return this.get('content');
+};
+
+TemplateOutput.prototype.getBlocks = function() {
+ return this.get('blocks');
+};
+
+/**
+ Update content of this output
+
+ @param {String} content
+ @return {TemplateContent}
+*/
+TemplateOutput.prototype.setContent = function(content) {
+ return this.set('content', content);
+};
+
+/**
+ Create a TemplateOutput from a text content
+ and an object containing block definition
+
+ @param {String} content
+ @param {Object} blocks
+ @return {TemplateOutput}
+*/
+TemplateOutput.create = function(content, blocks) {
+ return new TemplateOutput({
+ content: content,
+ blocks: Immutable.fromJS(blocks)
+ });
+};
+
+module.exports = TemplateOutput;