diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-21 00:42:11 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-21 00:42:11 +0100 |
commit | b4cdbc6534b12d4547898077b7d5b2fd2b2163d0 (patch) | |
tree | 25f8b6c194760523fa979a31cf6b076dd6c5905d /lib | |
parent | 0a93ffd76ba574de5afaad73954c287ae40143d5 (diff) | |
download | gitbook-b4cdbc6534b12d4547898077b7d5b2fd2b2163d0.zip gitbook-b4cdbc6534b12d4547898077b7d5b2fd2b2163d0.tar.gz gitbook-b4cdbc6534b12d4547898077b7d5b2fd2b2163d0.tar.bz2 |
Add custom filters for dates to templating engine
Diffstat (limited to 'lib')
-rw-r--r-- | lib/output/folder.js | 2 | ||||
-rw-r--r-- | lib/template/filters.js | 15 | ||||
-rw-r--r-- | lib/template/index.js | 4 |
3 files changed, 20 insertions, 1 deletions
diff --git a/lib/output/folder.js b/lib/output/folder.js index 9e139c0..4d8584e 100644 --- a/lib/output/folder.js +++ b/lib/output/folder.js @@ -39,6 +39,7 @@ module.exports = function folderOutput(Base) { // Cleanup output folder .then(function() { + that.log.debug.ln('removing previous output directory'); return fs.rmDir(that.root()) .fail(function() { return Promise(); @@ -47,6 +48,7 @@ module.exports = function folderOutput(Base) { // Create output folder .then(function() { + that.log.debug.ln('creating output directory'); return fs.mkdirp(that.root()); }) diff --git a/lib/template/filters.js b/lib/template/filters.js new file mode 100644 index 0000000..ac68b82 --- /dev/null +++ b/lib/template/filters.js @@ -0,0 +1,15 @@ +var moment = require('moment'); + + +module.exports = { + // 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(); + } +}; diff --git a/lib/template/index.js b/lib/template/index.js index a2d00b5..a130088 100644 --- a/lib/template/index.js +++ b/lib/template/index.js @@ -7,6 +7,7 @@ var Promise = require('../utils/promise'); var error = require('../utils/error'); var parsers = require('../parsers'); var defaultBlocks = require('./blocks'); +var defaultFilters = require('./filters'); var Loader = require('./loader'); // Return extension name for a specific block @@ -59,8 +60,9 @@ function TemplateEngine(output) { // Bind methods _.bindAll(this); - // Add default blocks + // Add default blocks and filters this.addBlocks(defaultBlocks); + this.addFilters(defaultFilters); } // Bind a function to a context |