Skip to content

Instantly share code, notes, and snippets.

View sylvaindethier's full-sized avatar

Sylvain Dethier sylvaindethier

View GitHub Profile
/**
* MomentJS - fromNow
*/
Handlebars.registerHelper('moment_unix_fromNow', function (timestamp) {
return moment.unix(timestamp).fromNow();
});
@sylvaindethier
sylvaindethier / Handlebars.helpers-momentJS.fromNow.js
Created May 6, 2014 18:28
Handlebars helper that handle MomentJS `fromNow` method
/**
* Moment - fromNow
*/
Handlebars.registerHelper('moment_unix_fromNow', function (timestamp) {
return moment.unix(timestamp).fromNow();
});
@sylvaindethier
sylvaindethier / Handlebars.helpers-nl2br.js
Created May 6, 2014 18:26
Handlebars helper new line to br
/**
* Replace \n by <br />, such as the `nl2br` in PHP
* @see http://stackoverflow.com/questions/2919337/jquery-convert-line-breaks-to-br-nl2br-equivalent
*/
Handlebars.registerHelper('nl2br', function (text, isXhtml) {
var breakTag = (isXhtml || typeof isXhtml === 'undefined') ? '<br />' : '<br>';
return (text + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
});
@sylvaindethier
sylvaindethier / Handlebars.helpers-pluralize.js
Created May 6, 2014 18:24
Handlebars helper for pluralization
/**
* Pluralization outputs singular or plural given a value
*/
Handlebars.registerHelper('pluralize', function (value, singular, plural) {
return value > 1 ? plural : singular;
});