helper-lib
Advanced tools
| (function() { | ||
| }).call(this); |
| (function() { | ||
| }).call(this); |
@@ -0,193 +1,184 @@ | ||
| /* | ||
| Comparison Helpers | ||
| */ | ||
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper('is', function(value, test, options) { | ||
| if (value === test) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('isnt', function(value, test, options) { | ||
| if (value !== test) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('gt', function(value, test, options) { | ||
| if (value > test) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('gte', function(value, test, options) { | ||
| if (value >= test) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('lt', function(value, test, options) { | ||
| if (value < test) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('lte', function(value, test, options) { | ||
| if (value <= test) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('or', function(testA, testB, options) { | ||
| if (testA || testB) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('and', function(testA, testB, options) { | ||
| if (testA && testB) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }); | ||
| /* | ||
| Similar to {{#if}} block helper but accepts multiple arguments. | ||
| */ | ||
| var gt, gte, ifAny, if_eq, if_gt, if_gteq, if_lt, if_lteq, lt, lte, unless_eq, unless_gt, unless_gteq, unless_lt, unless_lteq, _and, _is, _isnt, _or; | ||
| Handlebars.registerHelper("ifAny", function() { | ||
| var argLength, content, i, success; | ||
| module.exports.and = _and = function(testA, testB, options) { | ||
| if (testA && testB) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }; | ||
| argLength = arguments_.length - 2; | ||
| content = arguments_[argLength + 1]; | ||
| success = true; | ||
| i = 0; | ||
| while (i < argLength) { | ||
| if (!arguments_[i]) { | ||
| success = false; | ||
| break; | ||
| } | ||
| i += 1; | ||
| } | ||
| if (success) { | ||
| return content(this); | ||
| } else { | ||
| return content.inverse(this); | ||
| } | ||
| }); | ||
| /* | ||
| If Equals | ||
| if_eq this compare=that | ||
| */ | ||
| module.exports.gt = gt = function(value, test, options) { | ||
| if (value > test) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }; | ||
| Handlebars.registerHelper("if_eq", function(context, options) { | ||
| if (context === options.hash.compare) { | ||
| return options.fn(this); | ||
| } | ||
| module.exports.gte = gte = function(value, test, options) { | ||
| if (value >= test) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| }); | ||
| /* | ||
| Unless Equals | ||
| unless_eq this compare=that | ||
| */ | ||
| } | ||
| }; | ||
| Handlebars.registerHelper("unless_eq", function(context, options) { | ||
| if (context === options.hash.compare) { | ||
| return options.inverse(this); | ||
| } | ||
| module.exports.is = _is = function(value, test, options) { | ||
| if (value === test) { | ||
| return options.fn(this); | ||
| }); | ||
| /* | ||
| If Greater Than | ||
| if_gt this compare=that | ||
| */ | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }; | ||
| Handlebars.registerHelper("if_gt", function(context, options) { | ||
| if (context > options.hash.compare) { | ||
| return options.fn(this); | ||
| } | ||
| module.exports.isnt = _isnt = function(value, test, options) { | ||
| if (value !== test) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| }); | ||
| /* | ||
| Unless Greater Than | ||
| unless_gt this compare=that | ||
| */ | ||
| } | ||
| }; | ||
| Handlebars.registerHelper("unless_gt", function(context, options) { | ||
| if (context > options.hash.compare) { | ||
| return options.inverse(this); | ||
| } | ||
| module.exports.lt = lt = function(value, test, options) { | ||
| if (value < test) { | ||
| return options.fn(this); | ||
| }); | ||
| /* | ||
| If Less Than | ||
| if_lt this compare=that | ||
| */ | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }; | ||
| Handlebars.registerHelper("if_lt", function(context, options) { | ||
| if (context < options.hash.compare) { | ||
| return options.fn(this); | ||
| } | ||
| module.exports.lte = lte = function(value, test, options) { | ||
| if (value <= test) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| }); | ||
| /* | ||
| Unless Less Than | ||
| unless_lt this compare=that | ||
| */ | ||
| } | ||
| }; | ||
| Handlebars.registerHelper("unless_lt", function(context, options) { | ||
| if (context < options.hash.compare) { | ||
| return options.inverse(this); | ||
| } | ||
| module.exports.or = _or = function(testA, testB, options) { | ||
| if (testA || testB) { | ||
| return options.fn(this); | ||
| }); | ||
| /* | ||
| If Greater Than or Equal To | ||
| if_gteq this compare=that | ||
| */ | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }; | ||
| Handlebars.registerHelper("if_gteq", function(context, options) { | ||
| if (context >= options.hash.compare) { | ||
| return options.fn(this); | ||
| } | ||
| module.exports.if_eq = if_eq = function(context, options) { | ||
| if (context === options.hash.compare) { | ||
| return options.fn(this); | ||
| } | ||
| return options.inverse(this); | ||
| }; | ||
| module.exports.unless_eq = unless_eq = function(context, options) { | ||
| if (context === options.hash.compare) { | ||
| return options.inverse(this); | ||
| }); | ||
| /* | ||
| Unless Greater Than or Equal To | ||
| unless_gteq this compare=that | ||
| */ | ||
| } | ||
| return options.fn(this); | ||
| }; | ||
| Handlebars.registerHelper("unless_gteq", function(context, options) { | ||
| if (context >= options.hash.compare) { | ||
| return options.inverse(this); | ||
| } | ||
| module.exports.if_gt = if_gt = function(context, options) { | ||
| if (context > options.hash.compare) { | ||
| return options.fn(this); | ||
| }); | ||
| /* | ||
| If Less Than or Equal To | ||
| if_lteq this compare=that | ||
| */ | ||
| } | ||
| return options.inverse(this); | ||
| }; | ||
| Handlebars.registerHelper("if_lteq", function(context, options) { | ||
| if (context <= options.hash.compare) { | ||
| return options.fn(this); | ||
| } | ||
| module.exports.unless_gt = unless_gt = function(context, options) { | ||
| if (context > options.hash.compare) { | ||
| return options.inverse(this); | ||
| }); | ||
| /* | ||
| Unless Less Than or Equal To | ||
| unless_lteq this compare=that | ||
| */ | ||
| } | ||
| return options.fn(this); | ||
| }; | ||
| Handlebars.registerHelper("unless_lteq", function(context, options) { | ||
| if (context <= options.hash.compare) { | ||
| return options.inverse(this); | ||
| module.exports.if_lt = if_lt = function(context, options) { | ||
| if (context < options.hash.compare) { | ||
| return options.fn(this); | ||
| } | ||
| return options.inverse(this); | ||
| }; | ||
| module.exports.unless_lt = unless_lt = function(context, options) { | ||
| if (context < options.hash.compare) { | ||
| return options.inverse(this); | ||
| } | ||
| return options.fn(this); | ||
| }; | ||
| module.exports.if_gteq = if_gteq = function(context, options) { | ||
| if (context >= options.hash.compare) { | ||
| return options.fn(this); | ||
| } | ||
| return options.inverse(this); | ||
| }; | ||
| module.exports.unless_gteq = unless_gteq = function(context, options) { | ||
| if (context >= options.hash.compare) { | ||
| return options.inverse(this); | ||
| } | ||
| return options.fn(this); | ||
| }; | ||
| module.exports.if_lteq = if_lteq = function(context, options) { | ||
| if (context <= options.hash.compare) { | ||
| return options.fn(this); | ||
| } | ||
| return options.inverse(this); | ||
| }; | ||
| module.exports.unless_lteq = unless_lteq = function(context, options) { | ||
| if (context <= options.hash.compare) { | ||
| return options.inverse(this); | ||
| } | ||
| return options.fn(this); | ||
| }; | ||
| module.exports.ifAny = ifAny = function() { | ||
| var argLength, content, i, success; | ||
| argLength = arguments_.length - 2; | ||
| content = arguments_[argLength + 1]; | ||
| success = true; | ||
| i = 0; | ||
| while (i < argLength) { | ||
| if (!arguments_[i]) { | ||
| success = false; | ||
| break; | ||
| } | ||
| return options.fn(this); | ||
| }); | ||
| i += 1; | ||
| } | ||
| if (success) { | ||
| return content(this); | ||
| } else { | ||
| return content.inverse(this); | ||
| } | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("and", _and); | ||
| Handlebars.registerHelper("gt", gt); | ||
| Handlebars.registerHelper("gte", gte); | ||
| Handlebars.registerHelper("if_eq", if_eq); | ||
| Handlebars.registerHelper("if_gt", if_gt); | ||
| Handlebars.registerHelper("if_gteq", if_gteq); | ||
| Handlebars.registerHelper("if_lt", if_lt); | ||
| Handlebars.registerHelper("if_lteq", if_lteq); | ||
| Handlebars.registerHelper("ifAny", ifAny); | ||
| Handlebars.registerHelper("is", _is); | ||
| Handlebars.registerHelper("isnt", _isnt); | ||
| Handlebars.registerHelper("lt", lt); | ||
| Handlebars.registerHelper("lte", lte); | ||
| Handlebars.registerHelper("or", _or); | ||
| Handlebars.registerHelper("unless_eq", unless_eq); | ||
| Handlebars.registerHelper("unless_gt", unless_gt); | ||
| Handlebars.registerHelper("unless_gteq", unless_gteq); | ||
| Handlebars.registerHelper("unless_lt", unless_lt); | ||
| Handlebars.registerHelper("unless_lteq", unless_lteq); | ||
| return this; | ||
@@ -194,0 +185,0 @@ }; |
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| var Dates, Utils; | ||
| var Dates, Utils, formatDate, now, timeago; | ||
| Utils = require('../utils/utils'); | ||
| Dates = require('../utils/dates'); | ||
| Handlebars.registerHelper('formatDate', function(date, format) { | ||
| date = new Date(date); | ||
| Utils = require('../utils/utils'); | ||
| Dates = require('../utils/dates'); | ||
| module.exports.formatDate = formatDate = function(date, format) { | ||
| date = new Date(date); | ||
| return Dates.format(date, format); | ||
| }; | ||
| module.exports.now = now = function(format) { | ||
| var date; | ||
| date = new Date(); | ||
| if (Utils.isUndefined(format)) { | ||
| return date; | ||
| } else { | ||
| return Dates.format(date, format); | ||
| }); | ||
| Handlebars.registerHelper('now', function(format) { | ||
| var date; | ||
| } | ||
| }; | ||
| date = new Date(); | ||
| if (Utils.isUndefined(format)) { | ||
| return date; | ||
| } else { | ||
| return Dates.format(date, format); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('timeago', function(date) { | ||
| var interval, seconds; | ||
| module.exports.timeago = timeago = function(date) { | ||
| var interval, seconds; | ||
| date = new Date(date); | ||
| seconds = Math.floor((new Date() - date) / 1000); | ||
| interval = Math.floor(seconds / 31536000); | ||
| if (interval > 1) { | ||
| return "" + interval + " years ago"; | ||
| } | ||
| interval = Math.floor(seconds / 2592000); | ||
| if (interval > 1) { | ||
| return "" + interval + " months ago"; | ||
| } | ||
| interval = Math.floor(seconds / 86400); | ||
| if (interval > 1) { | ||
| return "" + interval + " days ago"; | ||
| } | ||
| interval = Math.floor(seconds / 3600); | ||
| if (interval > 1) { | ||
| return "" + interval + " hours ago"; | ||
| } | ||
| interval = Math.floor(seconds / 60); | ||
| if (interval > 1) { | ||
| return "" + interval + " minutes ago"; | ||
| } | ||
| if (Math.floor(seconds) === 0) { | ||
| return 'Just now'; | ||
| } else { | ||
| return Math.floor(seconds) + ' seconds ago'; | ||
| } | ||
| }); | ||
| date = new Date(date); | ||
| seconds = Math.floor((new Date() - date) / 1000); | ||
| interval = Math.floor(seconds / 31536000); | ||
| if (interval > 1) { | ||
| return "" + interval + " years ago"; | ||
| } | ||
| interval = Math.floor(seconds / 2592000); | ||
| if (interval > 1) { | ||
| return "" + interval + " months ago"; | ||
| } | ||
| interval = Math.floor(seconds / 86400); | ||
| if (interval > 1) { | ||
| return "" + interval + " days ago"; | ||
| } | ||
| interval = Math.floor(seconds / 3600); | ||
| if (interval > 1) { | ||
| return "" + interval + " hours ago"; | ||
| } | ||
| interval = Math.floor(seconds / 60); | ||
| if (interval > 1) { | ||
| return "" + interval + " minutes ago"; | ||
| } | ||
| if (Math.floor(seconds) === 0) { | ||
| return 'Just now'; | ||
| } else { | ||
| return Math.floor(seconds) + ' seconds ago'; | ||
| } | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("formatDate", formatDate); | ||
| Handlebars.registerHelper("now", now); | ||
| Handlebars.registerHelper("timeago", timeago); | ||
| return this; | ||
@@ -53,0 +61,0 @@ }; |
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| var Utils; | ||
| var Utils, copy; | ||
| Utils = require('../utils/utils'); | ||
| /* | ||
| Copy: copies src file from A to B. USE WITH CAUTION!!! | ||
| Usage: {{copy [a] [b]}} | ||
| */ | ||
| Utils = require('../utils/utils'); | ||
| return Handlebars.registerHelper('copy', function(a, b) { | ||
| return Utils.copyFile(a, b); | ||
| }); | ||
| module.exports.copy = copy = function(a, b) { | ||
| return Utils.copyFile(a, b); | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("copy", copy); | ||
| return this; | ||
| }; | ||
| }).call(this); |
@@ -8,17 +8,15 @@ (function() { | ||
| /* | ||
| Link helper: This will escape the passed in parameters, but mark the response as safe, | ||
| so Handlebars will not try to escape it even if the "triple-stash" is not used. | ||
| Usage: {{link 'href' 'title' 'class'}} | ||
| Switch (proof of concept), not intended for use in production code. | ||
| This helper demonstrates a simple example of how to switch the output | ||
| format based on the extension of the destination file(s) in the | ||
| 'assemble' grunt task. | ||
| */ | ||
| Handlebars.registerHelper("href", function(url, text, linkClass) { | ||
| var result; | ||
| Handlebars.registerHelper("switch", function(src) { | ||
| var html, md, output; | ||
| url = Handlebars.Utils.escapeExpression(url); | ||
| text = Handlebars.Utils.escapeExpression(text); | ||
| if (Utils.isUndefined(linkClass)) { | ||
| linkClass = ""; | ||
| } | ||
| result = '<a class="' + linkClass + '" href="' + url + '" title="' + text + '">' + text + '</a>'; | ||
| return Utils.safeString(result); | ||
| md = '# ' + src; | ||
| html = '<h1>' + src + '</h1>'; | ||
| output = Utils.switchOutput(options.ext, md, html); | ||
| return Utils.safeString(output); | ||
| }); | ||
@@ -56,25 +54,30 @@ Handlebars.registerHelper("css", function(context) { | ||
| /* | ||
| List: <ul> | ||
| href: This will escape the passed in parameters, but mark the response as safe, | ||
| so Handlebars will not try to escape it even if the "triple-stash" is not used. | ||
| Usage: {{href 'url' 'title/text' 'class'}} | ||
| */ | ||
| Handlebars.registerHelper("href", function(url, text, linkClass) { | ||
| var html, md, result; | ||
| url = Handlebars.Utils.escapeExpression(url); | ||
| text = Handlebars.Utils.escapeExpression(text); | ||
| if (Utils.isUndefined(linkClass)) { | ||
| linkClass = ""; | ||
| } | ||
| md = '[' + text + '](' + url + ')'; | ||
| html = '<a class="' + linkClass + '" href="' + url + '" title="' + text + '">' + text + '</a>'; | ||
| result = Utils.switchOutput(options.ext, md, html); | ||
| return Utils.safeString(result); | ||
| }); | ||
| Handlebars.registerHelper("ul", function(context, options) { | ||
| return ("<ul " + (HTML.parseAttributes(options.hash)) + ">" + "\n") + context.map(function(item) { | ||
| return " <li>" + (options.fn(item)) + " </li>"; | ||
| }).join("\n") + "\n" + "</ul>"; | ||
| return ("<ul " + (HTML.parseAttributes(options.hash)) + ">") + context.map(function(item) { | ||
| return "<li>" + (options.fn(item)) + "</li>"; | ||
| }).join("\n") + "</ul>"; | ||
| }); | ||
| /* | ||
| List: <ol> | ||
| Same as the `ul` helper but creates ordered lists. | ||
| */ | ||
| Handlebars.registerHelper("ol", function(context, options) { | ||
| return ("<ol " + (HTML.parseAttributes(options.hash)) + ">" + "\n") + context.map(function(item) { | ||
| return " <li>" + (options.fn(item)) + " </li>"; | ||
| }).join("\n") + "\n" + "</ol>"; | ||
| return ("<ol " + (HTML.parseAttributes(options.hash)) + ">") + context.map(function(item) { | ||
| return "<li>" + (options.fn(item)) + "</li>"; | ||
| }).join("\n") + "</ol>"; | ||
| }); | ||
| /* | ||
| Break helper: Add the specified number of br tags | ||
| Usage: {{br 5}} | ||
| */ | ||
| Handlebars.registerHelper('br', function(count, options) { | ||
@@ -93,7 +96,2 @@ var br, i; | ||
| }); | ||
| /* | ||
| Convert new line (\n) to <br> | ||
| from http://phpjs.org/functions/nl2br:480 | ||
| */ | ||
| Handlebars.registerHelper('nl2br', function(text) { | ||
@@ -108,7 +106,2 @@ var nl2br; | ||
| }); | ||
| /* | ||
| <!DOCTYPE> | ||
| Same as the `ul` helper but creates and ordered list. | ||
| */ | ||
| Handlebars.registerHelper("DOCTYPE", function(type) { | ||
@@ -136,2 +129,4 @@ type = type.toLowerCase(); | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'); | ||
| case "4": | ||
| case "4.01": | ||
| case "4.01 strict": | ||
@@ -143,2 +138,3 @@ return Utils.safeString('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'); | ||
| return Utils.safeString('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'); | ||
| case "svg": | ||
| case "svg 1.1": | ||
@@ -152,3 +148,3 @@ case "svg1.1": | ||
| default: | ||
| return Utils.safeString('<!DOCTYPE html>'); | ||
| return Utils.safeString('<!DOCTYPE1 html>'); | ||
| } | ||
@@ -155,0 +151,0 @@ }); |
| (function() { | ||
| var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
| var Utils, inflect, ordinalize, | ||
| __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| var Utils; | ||
| Utils = require('../utils/utils'); | ||
| Utils = require('../utils/utils'); | ||
| Handlebars.registerHelper('inflect', function(count, singular, plural, include) { | ||
| var word; | ||
| module.exports.inflect = inflect = function(count, singular, plural, include) { | ||
| var word; | ||
| word = count > 1 || count === 0 ? plural : singular; | ||
| if (Utils.isUndefined(include) || include === false) { | ||
| return word; | ||
| } else { | ||
| return "" + count + " " + word; | ||
| word = count > 1 || count === 0 ? plural : singular; | ||
| if (Utils.isUndefined(include) || include === false) { | ||
| return word; | ||
| } else { | ||
| return "" + count + " " + word; | ||
| } | ||
| }; | ||
| module.exports.ordinalize = ordinalize = function(value) { | ||
| var normal, _ref; | ||
| normal = Math.abs(Math.round(value)); | ||
| if (_ref = normal % 100, __indexOf.call([11, 12, 13], _ref) >= 0) { | ||
| return "" + value + "th"; | ||
| } else { | ||
| switch (normal % 10) { | ||
| case 1: | ||
| return "" + value + "st"; | ||
| case 2: | ||
| return "" + value + "nd"; | ||
| case 3: | ||
| return "" + value + "rd"; | ||
| default: | ||
| return "" + value + "th"; | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('ordinalize', function(value) { | ||
| var normal, _ref; | ||
| } | ||
| }; | ||
| normal = Math.abs(Math.round(value)); | ||
| if (_ref = normal % 100, __indexOf.call([11, 12, 13], _ref) >= 0) { | ||
| return "" + value + "th"; | ||
| } else { | ||
| switch (normal % 10) { | ||
| case 1: | ||
| return "" + value + "st"; | ||
| case 2: | ||
| return "" + value + "nd"; | ||
| case 3: | ||
| return "" + value + "rd"; | ||
| default: | ||
| return "" + value + "th"; | ||
| } | ||
| } | ||
| }); | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("inflect", inflect); | ||
| Handlebars.registerHelper("ordinalize", ordinalize); | ||
| return this; | ||
@@ -38,0 +42,0 @@ }; |
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| var Utils; | ||
| var Utils, debug, inspect, log; | ||
| Utils = require('../utils/utils'); | ||
| Handlebars.registerHelper('inspect', function(obj, language) { | ||
| var result; | ||
| Utils = require('../utils/utils'); | ||
| if (Utils.isUndefined(language)) { | ||
| language = ""; | ||
| } | ||
| result = '``` ' + language + '\n' + require('util').inspect(obj, 10, null).replace('{', '{\n ').replace('}', '\n}') + '\n```'; | ||
| return Utils.safeString(result); | ||
| }); | ||
| Handlebars.registerHelper('log', function(value) { | ||
| return console.log(value); | ||
| }); | ||
| Handlebars.registerHelper('debug', function(value) { | ||
| console.log('Context: ', this); | ||
| if (!Utils.isUndefined(value)) { | ||
| console.log('Value: ', value); | ||
| } | ||
| return console.log('-----------------------------------------------'); | ||
| }); | ||
| module.exports.inspect = inspect = function(obj, language) { | ||
| var result; | ||
| if (Utils.isUndefined(language)) { | ||
| language = ""; | ||
| } | ||
| result = '``` ' + language + '\n' + require('util').inspect(obj, 10, null).replace('{', '{\n ').replace('}', '\n}') + '\n```'; | ||
| return Utils.safeString(result); | ||
| }; | ||
| module.exports.log = log = function(value) { | ||
| return console.log(value); | ||
| }; | ||
| module.exports.debug = debug = function(value) { | ||
| console.log('Context: ', this); | ||
| if (!Utils.isUndefined(value)) { | ||
| console.log('Value: ', value); | ||
| } | ||
| return console.log('-----------------------------------------------'); | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("inspect", inspect); | ||
| Handlebars.registerHelper("log", log); | ||
| Handlebars.registerHelper("debug", debug); | ||
| return this; | ||
@@ -26,0 +33,0 @@ }; |
@@ -44,18 +44,42 @@ (function() { | ||
| /* | ||
| Travis CI: | ||
| readme-title: Generates a title and Travis CI badge for a README.md. | ||
| Syntax: {{travis [src]}} | ||
| */ | ||
| Handlebars.registerHelper("travis", function(pkg) { | ||
| var source, template, travis; | ||
| Handlebars.registerHelper("readme-title", function(branch) { | ||
| var name, pkg, repo, source, template, version; | ||
| travis = "./.travis.yml"; | ||
| source = void 0; | ||
| template = void 0; | ||
| if (grunt.file.exists(travis)) { | ||
| pkg = Utils.readJSON("./package.json"); | ||
| } else if (pkg) { | ||
| pkg = Utils.readJSON(pkg); | ||
| pkg = Utils.readJSON("./package.json"); | ||
| repo = Utils.repoUrl('https://github.com/$1'); | ||
| name = pkg.name; | ||
| version = pkg.version; | ||
| source = '[' + name + ' v' + version + '](' + repo + ')'; | ||
| template = Handlebars.compile(source); | ||
| return Utils.safeString(template(pkg)); | ||
| }); | ||
| /* | ||
| Travis CI: Generates a title and Travis CI badge for a README.md. | ||
| Syntax: {{travis [src]}} | ||
| */ | ||
| Handlebars.registerHelper("travis-badge", function(branch) { | ||
| var curBranch, pkg, source, template, travis, travisUrl; | ||
| pkg = Utils.readJSON("./package.json"); | ||
| travisUrl = Utils.repoUrl('https://travis-ci.org/$1'); | ||
| travis = options.travis || {}; | ||
| curBranch = ''; | ||
| if (Utils.isUndefined(branch)) { | ||
| curBranch = ''; | ||
| } else if (travis.branch) { | ||
| curBranch = '?branch=' + travis.branch; | ||
| } else { | ||
| curBranch = '?branch=' + branch; | ||
| } | ||
| source = "# [{{ name }} v{{ version }}]({{ homepage }})[](https://travis-ci.org/{{ author.name }}/{{ name }})"; | ||
| if (travis.name) { | ||
| pkg.name = travis.name; | ||
| } else { | ||
| pkg.name; | ||
| } | ||
| source = '[](' + travisUrl + ')'; | ||
| template = Handlebars.compile(source); | ||
@@ -65,2 +89,34 @@ return Utils.safeString(template(pkg)); | ||
| /* | ||
| Travis CI: Generates a title and Travis CI badge for a README.md. | ||
| Syntax: {{travis [src]}} | ||
| */ | ||
| Handlebars.registerHelper("travis", function(branch) { | ||
| var curBranch, pkg, repo, source, template, title, travis, travisUrl; | ||
| pkg = Utils.readJSON("./package.json"); | ||
| repo = Utils.repoUrl('https://github.com/$1'); | ||
| travisUrl = Utils.repoUrl('https://travis-ci.org/$1'); | ||
| travis = options.travis || {}; | ||
| curBranch = ''; | ||
| if (Utils.isUndefined(branch)) { | ||
| curBranch = ''; | ||
| } else if (travis.branch) { | ||
| curBranch = '?branch=' + travis.branch; | ||
| } else { | ||
| curBranch = '?branch=' + branch; | ||
| } | ||
| if (travis.name) { | ||
| pkg.name = travis.name; | ||
| } else { | ||
| pkg.name; | ||
| } | ||
| if (travis.title !== false) { | ||
| title = '# [' + pkg.name + ' v' + pkg.version + '](' + repo + ')'; | ||
| } | ||
| source = title + '[](' + travisUrl + ')'; | ||
| template = Handlebars.compile(source); | ||
| return Utils.safeString(template(pkg)); | ||
| }); | ||
| /* | ||
| Authors: reads in data from an "AUTHORS" file to generate markdown formtted | ||
@@ -73,6 +129,4 @@ author or list of authors for a README.md. Accepts a second optional | ||
| Handlebars.registerHelper('authors', function(authors) { | ||
| var matches, source, template; | ||
| var matches; | ||
| source = void 0; | ||
| template = void 0; | ||
| if (Utils.isUndefined(authors)) { | ||
@@ -91,6 +145,4 @@ authors = Utils.read("./AUTHORS"); | ||
| Handlebars.registerHelper('AUTHORS', function(authors) { | ||
| var matches, source, template; | ||
| var matches; | ||
| source = void 0; | ||
| template = void 0; | ||
| if (Utils.isUndefined(authors)) { | ||
@@ -114,4 +166,2 @@ authors = Utils.read("./AUTHORS"); | ||
| source = void 0; | ||
| template = void 0; | ||
| if (Utils.isUndefined(changelog)) { | ||
@@ -136,4 +186,2 @@ changelog = Utils.readYAML('./CHANGELOG'); | ||
| source = void 0; | ||
| template = void 0; | ||
| if (Utils.isUndefined(roadmap)) { | ||
@@ -149,15 +197,2 @@ roadmap = Utils.readYAML('./ROADMAP'); | ||
| /* | ||
| chapter: reads in data from a markdown file, and uses the first heading | ||
| as a chapter heading, and then copies the rest of the content inline. | ||
| Usage: {{ chapter [file] }} | ||
| */ | ||
| Handlebars.registerHelper('chapter', function(file) { | ||
| var content; | ||
| file = grunt.file.read(file); | ||
| content = file.replace(/(^[^ ]*\s)(.+)([^#]+(?=.*)$)/gim, '$2\n' + '$3') || []; | ||
| return Utils.safeString(content); | ||
| }); | ||
| /* | ||
| Glob: reads in data from a markdown file, and uses the first heading | ||
@@ -185,3 +220,3 @@ as a section heading, and then copies the rest of the content inline. | ||
| Handlebars.registerHelper('embed', function(file, language) { | ||
| var result; | ||
| var content; | ||
@@ -192,4 +227,4 @@ file = grunt.file.read(file); | ||
| } | ||
| result = '``` ' + language + '\n' + file + '\n```'; | ||
| return Utils.safeString(result); | ||
| content = '``` ' + language + '\n' + file + '\n```'; | ||
| return Utils.safeString(content); | ||
| }); | ||
@@ -196,0 +231,0 @@ /* |
| (function() { | ||
| var add, ceil, divide, floor, multiply, round, subtract; | ||
| module.exports.add = add = function(value, addition) { | ||
| return value + addition; | ||
| }; | ||
| module.exports.subtract = subtract = function(value, substraction) { | ||
| return value - substraction; | ||
| }; | ||
| module.exports.divide = divide = function(value, divisor) { | ||
| return value / divisor; | ||
| }; | ||
| module.exports.multiply = multiply = function(value, multiplier) { | ||
| return value * multiplier; | ||
| }; | ||
| module.exports.floor = floor = function(value) { | ||
| return Math.floor(value); | ||
| }; | ||
| module.exports.ceil = ceil = function(value) { | ||
| return Math.ceil(value); | ||
| }; | ||
| module.exports.round = round = function(value) { | ||
| return Math.round(value); | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper('add', function(value, addition) { | ||
| return value + addition; | ||
| }); | ||
| Handlebars.registerHelper('subtract', function(value, substraction) { | ||
| return value - substraction; | ||
| }); | ||
| Handlebars.registerHelper('divide', function(value, divisor) { | ||
| return value / divisor; | ||
| }); | ||
| Handlebars.registerHelper('multiply', function(value, multiplier) { | ||
| return value * multiplier; | ||
| }); | ||
| Handlebars.registerHelper('floor', function(value) { | ||
| return Math.floor(value); | ||
| }); | ||
| Handlebars.registerHelper('ceil', function(value) { | ||
| return Math.ceil(value); | ||
| }); | ||
| Handlebars.registerHelper('round', function(value) { | ||
| return Math.round(value); | ||
| }); | ||
| Handlebars.registerHelper("add", add); | ||
| Handlebars.registerHelper("subtract", subtract); | ||
| Handlebars.registerHelper("divide", divide); | ||
| Handlebars.registerHelper("multiply", multiply); | ||
| Handlebars.registerHelper("floor", floor); | ||
| Handlebars.registerHelper("ceil", ceil); | ||
| Handlebars.registerHelper("round", round); | ||
| return this; | ||
@@ -25,0 +41,0 @@ }; |
| (function() { | ||
| var noop, _default; | ||
| module.exports["default"] = _default = function(value, defaultValue) { | ||
| return value != null ? value : defaultValue; | ||
| }; | ||
| module.exports.noop = noop = function(options) { | ||
| return options.fn(this); | ||
| }; | ||
| /* | ||
| Handlebars.registerHelper 'partial', (name, data) -> | ||
| partial = Assemble.Config.partialsPath + name | ||
| data = if Utils.isUndefined(data) then {} else data | ||
| Handlebars.registerPartial(name, require partial) unless Handlebars.partials[name]? | ||
| Utils.safeString Handlebars.partials[name](data) | ||
| */ | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper('default', function(value, defaultValue) { | ||
| return value != null ? value : defaultValue; | ||
| }); | ||
| Handlebars.registerHelper("noop", function(options) { | ||
| return options.fn(this); | ||
| }); | ||
| /* | ||
| Handlebars.registerHelper 'partial', (name, data) -> | ||
| partial = Assemble.Config.partialsPath + name | ||
| data = if Utils.isUndefined(data) then {} else data | ||
| Handlebars.registerPartial(name, require partial) unless Handlebars.partials[name]? | ||
| Utils.safeString Handlebars.partials[name](data) | ||
| */ | ||
| Handlebars.registerHelper("default", _default); | ||
| Handlebars.registerHelper("noop", noop); | ||
| return this; | ||
@@ -18,0 +25,0 @@ }; |
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| var Utils; | ||
| var Utils, addCommas, toAbbr, toExponential, toFixed, toFloat, toInt, toPrecision; | ||
| Utils = require('../utils/utils'); | ||
| Handlebars.registerHelper('toFixed', function(number, digits) { | ||
| if (Utils.isUndefined(digits)) { | ||
| digits = 0; | ||
| Utils = require('../utils/utils'); | ||
| module.exports.toFixed = toFixed = function(number, digits) { | ||
| if (Utils.isUndefined(digits)) { | ||
| digits = 0; | ||
| } | ||
| return number.toFixed(digits); | ||
| }; | ||
| module.exports.toPrecision = toPrecision = function(number, precision) { | ||
| if (Utils.isUndefined(precision)) { | ||
| precision = 1; | ||
| } | ||
| return number.toPrecision(precision); | ||
| }; | ||
| module.exports.toExponential = toExponential = function(number, fractions) { | ||
| if (Utils.isUndefined(fractions)) { | ||
| fractions = 0; | ||
| } | ||
| return number.toExponential(fractions); | ||
| }; | ||
| module.exports.toInt = toInt = function(number) { | ||
| return parseInt(number, 10); | ||
| }; | ||
| module.exports.toFloat = toFloat = function(number) { | ||
| return parseFloat(number); | ||
| }; | ||
| module.exports.toAbbr = toAbbr = function(number, digits) { | ||
| var abbr, i, size; | ||
| if (Utils.isUndefined(digits)) { | ||
| digits = 2; | ||
| } | ||
| digits = Math.pow(10, digits); | ||
| abbr = ["k", "m", "b", "t"]; | ||
| i = abbr.length - 1; | ||
| while (i >= 0) { | ||
| size = Math.pow(10, (i + 1) * 3); | ||
| if (size <= number) { | ||
| number = Math.round(number * digits / size) / digits; | ||
| if ((number === 1000) && (i < abbr.length - 1)) { | ||
| number = 1; | ||
| i++; | ||
| } | ||
| number += abbr[i]; | ||
| break; | ||
| } | ||
| return number.toFixed(digits); | ||
| }); | ||
| Handlebars.registerHelper('toPrecision', function(number, precision) { | ||
| if (Utils.isUndefined(precision)) { | ||
| precision = 1; | ||
| } | ||
| return number.toPrecision(precision); | ||
| }); | ||
| Handlebars.registerHelper('toExponential', function(number, fractions) { | ||
| if (Utils.isUndefined(fractions)) { | ||
| fractions = 0; | ||
| } | ||
| return number.toExponential(fractions); | ||
| }); | ||
| Handlebars.registerHelper('toInt', function(number) { | ||
| return parseInt(number, 10); | ||
| }); | ||
| Handlebars.registerHelper('toFloat', function(number) { | ||
| return parseFloat(number); | ||
| }); | ||
| Handlebars.registerHelper('addCommas', function(number) { | ||
| return number.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); | ||
| }); | ||
| i--; | ||
| } | ||
| return number; | ||
| }; | ||
| module.exports.addCommas = addCommas = function(number) { | ||
| return number.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("toFixed", toFixed); | ||
| Handlebars.registerHelper("toPrecision", toPrecision); | ||
| Handlebars.registerHelper("toExponential", toExponential); | ||
| Handlebars.registerHelper("toInt", toInt); | ||
| Handlebars.registerHelper("toFloat", toFloat); | ||
| Handlebars.registerHelper("toAbbr", toAbbr); | ||
| Handlebars.registerHelper("addCommas", addCommas); | ||
| return this; | ||
@@ -34,0 +73,0 @@ }; |
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| var Utils, path; | ||
| var Utils, absolute, basename, directory, extname, filename, path, relative; | ||
| path = require('path'); | ||
| Utils = require('../utils/utils'); | ||
| /* | ||
| directory: Returns the absolute path to the current directory. | ||
| Usage: {{directory [path]}} | ||
| Returns: C:\path\to\the\current\current\directory | ||
| */ | ||
| path = require('path'); | ||
| Handlebars.registerHelper("directory", function(dir) { | ||
| return path.dirname(); | ||
| }); | ||
| /* | ||
| absolute: Returns the absolute path to the current directory. | ||
| Usage: {{absolute [to]}} | ||
| Returns: C:\path\to\the\current\current\directory | ||
| */ | ||
| Utils = require('../utils/utils'); | ||
| Handlebars.registerHelper("absolute", function(to) { | ||
| var absolutePath; | ||
| module.exports.directory = directory = function(dir) { | ||
| return path.dirname(); | ||
| }; | ||
| return absolutePath = Utils.urlNormalize(path.normalize(to, path.dirname())); | ||
| }); | ||
| /* | ||
| Relative: {{relative [from] [to]}} | ||
| Returns the derived relative path from one to the other. | ||
| */ | ||
| module.exports.absolute = absolute = function(to) { | ||
| var absolutePath; | ||
| Handlebars.registerHelper("relative", function(from, to) { | ||
| return Utils.getRelativePath(from, to); | ||
| }); | ||
| /* | ||
| filename: Returns the full-name of a given file. | ||
| Usage: {{filename "docs/toc.md"}} | ||
| Returns: toc.md | ||
| */ | ||
| return absolutePath = Utils.urlNormalize(path.normalize(to, path.dirname())); | ||
| }; | ||
| Handlebars.registerHelper('filename', function(base, ext) { | ||
| return Utils.getBasename(base, ext); | ||
| }); | ||
| /* | ||
| Basename: Returns the basename of a given file. | ||
| Usage: {{base "docs/toc.md"}} | ||
| Returns: toc | ||
| */ | ||
| module.exports.relative = relative = function(a, b) { | ||
| return Utils.getRelativePath(a, b); | ||
| }; | ||
| Handlebars.registerHelper('basename', function(base, ext) { | ||
| return Utils.getBasename(base, ext); | ||
| }); | ||
| /* | ||
| Extension: Returns the extension of a given file. | ||
| Usage: {{ext "docs/toc.md"}} | ||
| Returns: .md | ||
| */ | ||
| module.exports.basename = basename = function(file) { | ||
| return Utils.getBasename(file); | ||
| }; | ||
| Handlebars.registerHelper("extname", function(ext) { | ||
| return Utils.getExt(ext); | ||
| }); | ||
| module.exports.filename = filename = function(file) { | ||
| return path.basename(file); | ||
| }; | ||
| module.exports.extname = extname = function(ext) { | ||
| return Utils.getExt(ext); | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("directory", directory); | ||
| Handlebars.registerHelper("absolute", absolute); | ||
| Handlebars.registerHelper("relative", relative); | ||
| Handlebars.registerHelper("basename", basename); | ||
| Handlebars.registerHelper("filename", filename); | ||
| Handlebars.registerHelper("extname", extname); | ||
| return this; | ||
@@ -63,0 +42,0 @@ }; |
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| var Utils, fs, _; | ||
| var Handlebars, Utils, defineSection, disqus, formatPhoneNumber, fs, gist, highlight, include, jsfiddle, renderSection, _; | ||
| fs = require('fs'); | ||
| _ = require('lodash'); | ||
| Utils = require('../utils/utils'); | ||
| /* | ||
| Include: Include content from an external source. | ||
| Usage: {{ include [file] }} | ||
| */ | ||
| Handlebars = require('../helpers/helpers').Handlebars; | ||
| Handlebars.registerHelper('include', function(file) { | ||
| file = Utils.read(file); | ||
| return Utils.safeString(file); | ||
| }); | ||
| /* | ||
| "section": block helper. | ||
| Usage: {{#section [file] }} | ||
| */ | ||
| fs = require('fs'); | ||
| Handlebars.registerHelper('section', function(section, options) { | ||
| if (Handlebars.sections) { | ||
| Handlebars.sections[section] = options.fn(this); | ||
| } | ||
| return Utils.safeString(''); | ||
| }); | ||
| /* | ||
| "override" block helper. | ||
| Usage: {{#override [file] }} | ||
| */ | ||
| _ = require('lodash'); | ||
| Handlebars.registerHelper('override', function(section, options) { | ||
| var content; | ||
| Utils = require('../utils/utils'); | ||
| if (Handlebars.sections && Handlebars.sections[section]) { | ||
| content = Handlebars.sections[section]; | ||
| } else { | ||
| content = options.fn(this); | ||
| } | ||
| return Utils.safeString(content); | ||
| }); | ||
| /* | ||
| jsFiddle: Embed a jsFiddle, second parameter sets tabs | ||
| Usage: {{ jsfiddle [id] [tabs] }} | ||
| */ | ||
| module.exports.include = include = function(file) { | ||
| return Utils.safeString(Utils.read(file)); | ||
| }; | ||
| Handlebars.registerHelper('jsfiddle', function(id, tabs) { | ||
| var result; | ||
| module.exports.section = defineSection = function(section, options) { | ||
| if (Handlebars.sections) { | ||
| Handlebars.sections[section] = options.fn(this); | ||
| } | ||
| return Utils.safeString(''); | ||
| }; | ||
| if (Utils.isUndefined(tabs)) { | ||
| tabs = "result,js,html,css"; | ||
| } | ||
| result = '<iframe width="100%" height="300" src="http://jsfiddle.net/' + id + '/embedded/' + tabs + '/presentation/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>'; | ||
| return Utils.safeString(result); | ||
| }); | ||
| /* | ||
| Gist: Downloads and embeds public GitHub Gists by | ||
| adding only the Id of the Gist. | ||
| Usage: {{ gist [id] [file] }} | ||
| */ | ||
| module.exports.section = renderSection = function(section, options) { | ||
| var content; | ||
| Handlebars.registerHelper('gist', function(id, file) { | ||
| var result; | ||
| if (Handlebars.sections && Handlebars.sections[section]) { | ||
| content = Handlebars.sections[section]; | ||
| } else { | ||
| content = options.fn(this); | ||
| } | ||
| return Utils.safeString(content); | ||
| }; | ||
| id = Handlebars.Utils.escapeExpression(id); | ||
| if (Utils.isUndefined(file)) { | ||
| file = ""; | ||
| } | ||
| result = '<script src="https://gist.github.com/' + id + '.js"></script>'; | ||
| return Utils.safeString(result); | ||
| }); | ||
| /* | ||
| Highlight: wraps the output in a span with the class "highlight". | ||
| Usage: {{highlight 'value' 'class'}} | ||
| */ | ||
| module.exports.disqus = disqus = function(slug, options) { | ||
| var result; | ||
| Handlebars.registerHelper('highlight', function(text, modifier) { | ||
| var result; | ||
| return ""; | ||
| result = "<a href=\"http://" + window.location.host + "/blog/" + slug + "#disqus_thread\" data-disqus-identifier=\"/blog/" + slug + "\" ></a>"; | ||
| return Utils.safeString(result); | ||
| }; | ||
| if (Utils.isUndefined(modifier)) { | ||
| modifier = "highlight"; | ||
| } | ||
| result = '<span class="' + modifier + '">' + text + '</span>'; | ||
| return Utils.safeString(result); | ||
| }); | ||
| /* | ||
| Format Phone Number | ||
| from: http://blog.teamtreehouse.com/handlebars-js-part-2-partials-and-helpers | ||
| Helper function to output a formatted phone number | ||
| Usage: {{formatPhoneNumber phoneNumber}} | ||
| */ | ||
| module.exports.jsfiddle = jsfiddle = function(id, tabs) { | ||
| var result; | ||
| Handlebars.registerHelper("formatPhoneNumber", function(phoneNumber) { | ||
| phoneNumber = phoneNumber.toString(); | ||
| return "(" + phoneNumber.substr(0, 3) + ") " + phoneNumber.substr(3, 3) + "-" + phoneNumber.substr(6, 4); | ||
| }); | ||
| if (Utils.isUndefined(tabs)) { | ||
| tabs = "result,js,html,css"; | ||
| } | ||
| result = '<iframe width="100%" height="300" src="http://jsfiddle.net/' + id + '/embedded/' + tabs + '/presentation/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>'; | ||
| return Utils.safeString(result); | ||
| }; | ||
| module.exports.gist = gist = function(id, file) { | ||
| var result; | ||
| id = Handlebars.Utils.escapeExpression(id); | ||
| if (Utils.isUndefined(file)) { | ||
| file = ""; | ||
| } | ||
| result = '<script src="https://gist.github.com/' + id + '.js"></script>'; | ||
| return Utils.safeString(result); | ||
| }; | ||
| module.exports.highlight = highlight = function(text, modifier) { | ||
| var result; | ||
| if (Utils.isUndefined(modifier)) { | ||
| modifier = "highlight"; | ||
| } | ||
| result = '<span class="' + modifier + '">' + text + '</span>'; | ||
| return Utils.safeString(result); | ||
| }; | ||
| module.exports.formatPhoneNumber = formatPhoneNumber = function(phoneNumber) { | ||
| phoneNumber = phoneNumber.toString(); | ||
| return "(" + phoneNumber.substr(0, 3) + ") " + phoneNumber.substr(3, 3) + "-" + phoneNumber.substr(6, 4); | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("disqus", disqus); | ||
| Handlebars.registerHelper("gist", gist); | ||
| Handlebars.registerHelper("highlight", highlight); | ||
| Handlebars.registerHelper("include", include); | ||
| Handlebars.registerHelper("jsfiddle", jsfiddle); | ||
| Handlebars.registerHelper("defineSection", defineSection); | ||
| Handlebars.registerHelper("renderSection", renderSection); | ||
| Handlebars.registerHelper("formatPhoneNumber", formatPhoneNumber); | ||
| return this; | ||
@@ -99,0 +88,0 @@ }; |
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| var Utils; | ||
| var Utils, capitalizeEach, capitalizeFirst, center, dashify, hyphenate, lowercase, replace, reverse, safeString, sentence, titleize, truncate, uppercase; | ||
| Utils = require('../utils/utils'); | ||
| Handlebars.registerHelper("safeString", function(value) { | ||
| return Utils.safeString(value); | ||
| Utils = require('../utils/utils'); | ||
| module.exports.safeString = safeString = function(value) { | ||
| return Utils.safeString(value); | ||
| }; | ||
| module.exports.lowercase = lowercase = function(str) { | ||
| return str.toLowerCase(); | ||
| }; | ||
| module.exports.uppercase = uppercase = function(str) { | ||
| return str.toUpperCase(); | ||
| }; | ||
| module.exports.capitalizeFirst = capitalizeFirst = function(str) { | ||
| return str.charAt(0).toUpperCase() + str.slice(1); | ||
| }; | ||
| module.exports.capitalizeEach = capitalizeEach = function(str) { | ||
| return str.replace(/\w\S*/g, function(txt) { | ||
| return txt.charAt(0).toUpperCase() + txt.substr(1); | ||
| }); | ||
| Handlebars.registerHelper('lowercase', function(str) { | ||
| return str.toLowerCase(); | ||
| }); | ||
| Handlebars.registerHelper('uppercase', function(str) { | ||
| return str.toUpperCase(); | ||
| }); | ||
| Handlebars.registerHelper('capitalizeFirst', function(str) { | ||
| return str.charAt(0).toUpperCase() + str.slice(1); | ||
| }); | ||
| Handlebars.registerHelper('capitalizeEach', function(str) { | ||
| return str.replace(/\w\S*/g, function(txt) { | ||
| return txt.charAt(0).toUpperCase() + txt.substr(1); | ||
| }); | ||
| }); | ||
| Handlebars.registerHelper('titleize', function(str) { | ||
| var capitalize, title, word, words; | ||
| }; | ||
| title = str.replace(/[ \-_]+/g, ' '); | ||
| words = title.match(/\w+/g); | ||
| capitalize = function(word) { | ||
| return word.charAt(0).toUpperCase() + word.slice(1); | ||
| }; | ||
| return ((function() { | ||
| var _i, _len, _results; | ||
| module.exports.titleize = titleize = function(str) { | ||
| var capitalize, title, word, words; | ||
| _results = []; | ||
| for (_i = 0, _len = words.length; _i < _len; _i++) { | ||
| word = words[_i]; | ||
| _results.push(capitalize(word)); | ||
| } | ||
| return _results; | ||
| })()).join(' '); | ||
| }); | ||
| Handlebars.registerHelper('sentence', function(str) { | ||
| return str.replace(/((?:\S[^\.\?\!]*)[\.\?\!]*)/g, function(txt) { | ||
| return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); | ||
| }); | ||
| }); | ||
| Handlebars.registerHelper('reverse', function(str) { | ||
| return str.split('').reverse().join(''); | ||
| }); | ||
| Handlebars.registerHelper('truncate', function(str, length, omission) { | ||
| if (Utils.isUndefined(omission)) { | ||
| omission = ''; | ||
| title = str.replace(/[ \-_]+/g, ' '); | ||
| words = title.match(/\w+/g); | ||
| capitalize = function(word) { | ||
| return word.charAt(0).toUpperCase() + word.slice(1); | ||
| }; | ||
| return ((function() { | ||
| var _i, _len, _results; | ||
| _results = []; | ||
| for (_i = 0, _len = words.length; _i < _len; _i++) { | ||
| word = words[_i]; | ||
| _results.push(capitalize(word)); | ||
| } | ||
| if (str.length > length) { | ||
| return str.substring(0, length - omission.length) + omission; | ||
| } else { | ||
| return str; | ||
| } | ||
| return _results; | ||
| })()).join(' '); | ||
| }; | ||
| module.exports.sentence = sentence = function(str) { | ||
| return str.replace(/((?:\S[^\.\?\!]*)[\.\?\!]*)/g, function(txt) { | ||
| return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); | ||
| }); | ||
| Handlebars.registerHelper('center', function(str, spaces) { | ||
| var i, space; | ||
| }; | ||
| space = ''; | ||
| i = 0; | ||
| while (i < spaces) { | ||
| space += ' '; | ||
| i++; | ||
| } | ||
| return "" + space + str + space; | ||
| }); | ||
| Handlebars.registerHelper("hyphenate", function(tag) { | ||
| return tag.split(" ").join("-"); | ||
| }); | ||
| Handlebars.registerHelper("dashify", function(tag) { | ||
| return tag.split(".").join("-"); | ||
| }); | ||
| module.exports.reverse = reverse = function(str) { | ||
| return str.split('').reverse().join(''); | ||
| }; | ||
| module.exports.truncate = truncate = function(str, length, omission) { | ||
| if (Utils.isUndefined(omission)) { | ||
| omission = ''; | ||
| } | ||
| if (str.length > length) { | ||
| return str.substring(0, length - omission.length) + omission; | ||
| } else { | ||
| return str; | ||
| } | ||
| }; | ||
| module.exports.center = center = function(str, spaces) { | ||
| var i, space; | ||
| space = ''; | ||
| i = 0; | ||
| while (i < spaces) { | ||
| space += ' '; | ||
| i++; | ||
| } | ||
| return "" + space + str + space; | ||
| }; | ||
| module.exports.hyphenate = hyphenate = function(str) { | ||
| return str.split(" ").join("-"); | ||
| }; | ||
| module.exports.dashify = dashify = function(str) { | ||
| return str.split(".").join("-"); | ||
| }; | ||
| module.exports.dashify = replace = function(str, a, b) { | ||
| return str.split(a).join(b); | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("safeString", safeString); | ||
| Handlebars.registerHelper("lowercase", lowercase); | ||
| Handlebars.registerHelper("uppercase", uppercase); | ||
| Handlebars.registerHelper("capitalizeFirst", capitalizeFirst); | ||
| Handlebars.registerHelper("capitalizeEach", capitalizeEach); | ||
| Handlebars.registerHelper("titleize", titleize); | ||
| Handlebars.registerHelper("sentence", sentence); | ||
| Handlebars.registerHelper("reverse", reverse); | ||
| Handlebars.registerHelper("truncate", truncate); | ||
| Handlebars.registerHelper("center", center); | ||
| Handlebars.registerHelper("hyphenate", hyphenate); | ||
| Handlebars.registerHelper("dashify", dashify); | ||
| Handlebars.registerHelper("replace", replace); | ||
| return this; | ||
@@ -78,0 +108,0 @@ }; |
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("stripQuerystring", function(url) { | ||
| return url.split("?")[0]; | ||
| }); | ||
| /* | ||
| encode URI | ||
| Encodes a Uniform Resource Identifier (URI) component by replacing each instance of | ||
| certain characters by one, two, three, or four escape sequences representing the | ||
| UTF-8 encoding of the character | ||
| */ | ||
| var Utils, stripQuerystring, _decodeURI, _encodeURI; | ||
| Handlebars.registerHelper("encodeURI", function(uri) { | ||
| return encodeURIComponent(uri); | ||
| }); | ||
| /* | ||
| Decode URI | ||
| Decodes a Uniform Resource Identifier (URI) component previously created | ||
| by encodeURIComponent or by a similar routine. | ||
| */ | ||
| Utils = require('../utils/utils'); | ||
| return Handlebars.registerHelper("decodeURI", function(encodedURI) { | ||
| return decodeURIComponent(encodedURI); | ||
| }); | ||
| module.exports.stripQuerystring = stripQuerystring = function(url) { | ||
| return url.split("?")[0]; | ||
| }; | ||
| /* | ||
| encode URI | ||
| Encodes a Uniform Resource Identifier (URI) component by replacing each instance of | ||
| certain characters by one, two, three, or four escape sequences representing the | ||
| UTF-8 encoding of the character | ||
| */ | ||
| module.exports.encodeURI = _encodeURI = function(uri) { | ||
| return encodeURIComponent(uri); | ||
| }; | ||
| /* | ||
| Decode URI | ||
| Decodes a Uniform Resource Identifier (URI) component previously created | ||
| by encodeURIComponent or by a similar routine. | ||
| */ | ||
| module.exports.decodeURI = _decodeURI = function(encodedURI) { | ||
| return decodeURIComponent(encodedURI); | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("stripQuerystring", stripQuerystring); | ||
| Handlebars.registerHelper("encodeURI", _encodeURI); | ||
| Handlebars.registerHelper("decodeURI", _decodeURI); | ||
| return this; | ||
| }; | ||
| }).call(this); |
+40
-6
@@ -25,2 +25,6 @@ (function() { | ||
| Utils.escapeExpression = function(str) { | ||
| return Handlebars.Utils.escapeExpression; | ||
| }; | ||
| Utils.trim = function(str) { | ||
@@ -45,8 +49,14 @@ var trim; | ||
| Utils.repoUrl = function(str) { | ||
| var pkg, url; | ||
| pkg = grunt.file.readJSON("./package.json"); | ||
| url = pkg.repository.url; | ||
| return str = url.replace(/.*:\/\/github.com\/(.*?)(?:\.git|$)/, str); | ||
| }; | ||
| /* | ||
| # Detect and return the indentation. | ||
| # | ||
| # @param {String} string | ||
| # | ||
| # @return {Mixed} Indentation used, or undefined. | ||
| # param {String} string | ||
| # return {Mixed} Indentation used, or undefined. | ||
| */ | ||
@@ -120,6 +130,30 @@ | ||
| Utils.readBasedOnType = function(ext) { | ||
| Utils.toggleOutput = function(ext, md, html) { | ||
| var output; | ||
| if (ext === '') { | ||
| return output = md; | ||
| } else { | ||
| return output = html; | ||
| } | ||
| }; | ||
| Utils.switchOutput = function(ext, md, html) { | ||
| var output; | ||
| switch (ext) { | ||
| case "": | ||
| case ".md": | ||
| output = md; | ||
| break; | ||
| case ".html": | ||
| case ".htm": | ||
| output = html; | ||
| } | ||
| return output; | ||
| }; | ||
| Utils.switchType = function(ext) { | ||
| var reader; | ||
| ext = options.ext; | ||
| reader = grunt.file.readJSON; | ||
@@ -126,0 +160,0 @@ switch (ext) { |
+2
-2
| { | ||
| "name": "helper-lib", | ||
| "description": "Extensive collection of Handlebars helpers.", | ||
| "version": "0.1.32", | ||
| "version": "0.2.0", | ||
| "homepage": "https://github.com/assemble/helper-lib", | ||
@@ -22,3 +22,3 @@ "author": { | ||
| "type": "git", | ||
| "url": "git://github.com/assemble/helper-lib" | ||
| "url": "git://github.com/assemble/helper-lib.git" | ||
| }, | ||
@@ -25,0 +25,0 @@ "bugs": { |
+40
-22
@@ -1,2 +0,2 @@ | ||
| # [Helper Library v0.1.32](http://github.com/assemble/helper-lib) [](https://travis-ci.org/assemble/helper-lib) | ||
| # [Helper Library v0.2.0](http://github.com/assemble/helper-lib) [](https://travis-ci.org/assemble/helper-lib) | ||
@@ -89,2 +89,3 @@ > Extensive collection of Handlebars helpers. | ||
| - [toFloat](#tofloat) | ||
| - [toAbbr](#toabbr) | ||
| - [addCommas](#addcommas) | ||
@@ -966,2 +967,19 @@ - [Comparisons](#comparisons) | ||
| #### toAbbr | ||
| _Returns the number in abbreviation formats based on a value. The number is rounded to a particular decimal place._ | ||
| <br>Parameters: digits `int` - The number of digits to appear after the decimal point. (Optional) | ||
| <br>Default: `2` | ||
| ``` js | ||
| // Data | ||
| value = 123456789 | ||
| ``` | ||
| ``` html | ||
| // Template | ||
| {{toAbbr value}} | ||
| // Result: | ||
| 123.457m | ||
| ``` | ||
| #### addCommas | ||
@@ -1334,3 +1352,3 @@ _Adds commas to a number._ | ||
| ``` | ||
| Result: | ||
| Output: | ||
| ``` html | ||
@@ -1361,3 +1379,3 @@ <script src="https://gist.github.com/5193239.js"></script> | ||
| #### blockquote | ||
| #### blockquote (planned...) | ||
| _Create a blockquote_ | ||
@@ -1372,3 +1390,3 @@ | ||
| ``` | ||
| results in: | ||
| Output: | ||
@@ -1409,3 +1427,3 @@ ``` html | ||
| #### timeline | ||
| #### timeline (planned...) | ||
| _Iterates through an array, letting the contents know whether a timeline entry belongs in the left or right column._ | ||
@@ -1458,3 +1476,3 @@ | ||
| ``` html | ||
| // Result: | ||
| // Output: | ||
| <ul class="deliveries-list"> | ||
@@ -1491,3 +1509,3 @@ <li> Leela - 8021 deliveries </li> | ||
| ``` html | ||
| // Result: | ||
| // Output: | ||
| <ol class="deliveries-list"> | ||
@@ -1562,3 +1580,3 @@ <li> Leela - 8021 deliveries </li> | ||
| // Template | ||
| {{default title "Not title available."}} | ||
| {{default title "No title available."}} | ||
@@ -1631,15 +1649,15 @@ // Result: | ||
| ## Release History | ||
| * 2013-05-02 v0.1.32 Updated utils and a number of helpers, including value, property, and stringify. | ||
| * 2013-04-21 v0.1.31 Fixing relative helper | ||
| * 2013-04-20 v0.1.30 Refactoring helpers-collection module to separate the functions from the Handlebars helper registration process. | ||
| * 2013-04-16 v0.1.25 Adding defineSection and renderSection helpers to try to get sections populated in a layout from the page. | ||
| * 2013-04-07 v0.1.21 Add markdown helpers back, add more tests. | ||
| * 2013-04-06 v0.1.20 Generalized helpers structure, externalized utilities. | ||
| * 2013-04-05 v0.1.11 New authors and gist helpers, general cleanup and new tests. | ||
| * 2013-04-04 v0.1.10 Externalized utility javascript from helpers.js | ||
| * 2013-03-28 v0.1.8 Gruntfile updated with mocha tests for 71 helpers, bug fixes. | ||
| * 2013-03-18 v0.1.7 New path helper "relative", for resolving relative path from one absolute path to another. | ||
| * 2013-03-16 v0.1.3 New helpers, "formatPhoneNumber" and "eachProperty" | ||
| * 2013-03-15 v0.1.2 Update README.md with documentation, examples. | ||
| * 2013-03-06 v0.1.0 First commit. | ||
| * 2013-05-02 v0.1.32 Updated utils and a number of helpers, including value, property, and stringify. | ||
| * 2013-04-21 v0.1.31 Fixing relative helper | ||
| * 2013-04-20 v0.1.30 Refactoring helpers-collection module to separate the functions from the Handlebars helper registration process. | ||
| * 2013-04-16 v0.1.25 Adding defineSection and renderSection helpers to try to get sections populated in a layout from the page. | ||
| * 2013-04-07 v0.1.21 Add markdown helpers back, add more tests. | ||
| * 2013-04-06 v0.1.20 Generalized helpers structure, externalized utilities. | ||
| * 2013-04-05 v0.1.11 New authors and gist helpers, general cleanup and new tests. | ||
| * 2013-04-04 v0.1.10 Externalized utility javascript from helpers.js | ||
| * 2013-03-28 v0.1.8 Gruntfile updated with mocha tests for 71 helpers, bug fixes. | ||
| * 2013-03-18 v0.1.7 New path helper "relative", for resolving relative path from one absolute path to another. | ||
| * 2013-03-16 v0.1.3 New helpers, "formatPhoneNumber" and "eachProperty" | ||
| * 2013-03-15 v0.1.2 Update README.md with documentation, examples. | ||
| * 2013-03-06 v0.1.0 First commit. | ||
@@ -1653,3 +1671,3 @@ | ||
| _This file was generated using Grunt and [assemble](http://github.com/assemble/assemble) on Thu May 02 2013 02:28:18._ | ||
| _This file was generated using Grunt and [assemble](http://github.com/assemble/assemble) on Tue May 07 2013 22:23:19._ | ||
@@ -1656,0 +1674,0 @@ |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
103526
4.62%33
6.45%1766
4.25%1733
1.05%