diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-04-24 19:12:03 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-04-24 19:12:03 +0200 |
commit | 93b257314aa9a6ba240ff7d9534ddb1a6ded6bc0 (patch) | |
tree | fdb9103fe3d32c34326b7a13746668e2056a40de /lib/constants | |
parent | 19a1db8cb43431352d30dbc48aebb9cc8bf58eec (diff) | |
download | gitbook-93b257314aa9a6ba240ff7d9534ddb1a6ded6bc0.zip gitbook-93b257314aa9a6ba240ff7d9534ddb1a6ded6bc0.tar.gz gitbook-93b257314aa9a6ba240ff7d9534ddb1a6ded6bc0.tar.bz2 |
Add default filters and blocks
Diffstat (limited to 'lib/constants')
-rw-r--r-- | lib/constants/defaultBlocks.js | 51 | ||||
-rw-r--r-- | lib/constants/defaultFilters.js | 15 |
2 files changed, 66 insertions, 0 deletions
diff --git a/lib/constants/defaultBlocks.js b/lib/constants/defaultBlocks.js new file mode 100644 index 0000000..5d91359 --- /dev/null +++ b/lib/constants/defaultBlocks.js @@ -0,0 +1,51 @@ +var Immutable = require('immutable'); +var TemplateBlock = require('../models/templateBlock'); + +module.exports = Immutable.List([ + TemplateBlock({ + name: 'html', + process: function(blk) { + return blk; + } + }), + + TemplateBlock({ + name: 'code', + process: function(blk) { + return { + html: false, + body: blk.body + }; + } + }), + + TemplateBlock({ + name: 'markdown', + process: function(blk) { + return this.book.renderInline('markdown', blk.body) + .then(function(out) { + return { body: out }; + }); + } + }), + + TemplateBlock({ + name: 'asciidoc', + process: function(blk) { + return this.book.renderInline('asciidoc', blk.body) + .then(function(out) { + return { body: out }; + }); + } + }), + + TemplateBlock({ + name: 'markup', + process: function(blk) { + return this.book.renderInline(this.ctx.file.type, blk.body) + .then(function(out) { + return { body: out }; + }); + } + }), +]); diff --git a/lib/constants/defaultFilters.js b/lib/constants/defaultFilters.js new file mode 100644 index 0000000..35025cc --- /dev/null +++ b/lib/constants/defaultFilters.js @@ -0,0 +1,15 @@ +var Immutable = require('immutable'); +var moment = require('moment'); + +module.exports = Immutable.Map({ + // Format a date + // ex: 'MMMM Do YYYY, h:mm:ss a + date: function(time, format) { + return moment(time).format(format); + }, + + // Relative Time + dateFromNow: function(time) { + return moment(time).fromNow(); + } +}); |