helper-lib
Advanced tools
+9
-0
@@ -0,1 +1,10 @@ | ||
| v0.2.3: | ||
| date: "2013-05-11" | ||
| changes: | ||
| - File globbing added to some helpers. Including md and some file helpers. | ||
| v0.2.0: | ||
| date: "2013-05-07" | ||
| changes: | ||
| - A bunch of new tests for markdown and special helpers. | ||
| - Refactored most of the rest of the helpers to separate functions from Handlebars registration. | ||
| v0.1.32: | ||
@@ -2,0 +11,0 @@ date: "2013-05-02" |
| (function() { | ||
| var Utils, after, any, arrayify, before, eachIndex, eachProperty, empty, first, inArray, join, joinAny, last, length, lengthEqual, property, sort, stringify, value, withAfter, withBefore, withFirst, withLast, withSort, _; | ||
| var Handlebars, Utils, after, any, arrayify, before, eachIndex, eachProperty, each_with_classes, empty, first, foreach, inArray, iterate, join, joinAny, last, length, lengthEqual, sort, withAfter, withBefore, withFirst, withLast, withSort, _; | ||
| Handlebars = require('../helpers/helpers').Handlebars; | ||
| Utils = require('../utils/utils'); | ||
@@ -8,20 +10,2 @@ | ||
| module.exports.value = value = function(file, prop) { | ||
| file = Utils.readJSON(file); | ||
| prop = _.pick(file, prop); | ||
| prop = _.pluck(prop); | ||
| return Utils.safeString(prop); | ||
| }; | ||
| module.exports.property = property = function(file, prop) { | ||
| file = Utils.readJSON(file); | ||
| prop = _.pick(file, prop); | ||
| return Utils.safeString(JSON.stringify(prop, null, 2)); | ||
| }; | ||
| module.exports.stringify = stringify = function(file, props) { | ||
| file = Utils.readJSON(file); | ||
| return Utils.safeString(JSON.stringify(file, null, 2)); | ||
| }; | ||
| module.exports.first = first = function(array, count) { | ||
@@ -214,4 +198,99 @@ if (Utils.isUndefined(count)) { | ||
| module.exports.iterate = iterate = function(context, options) { | ||
| var data, fn, i, inverse, j, key, ret; | ||
| fn = options.fn; | ||
| inverse = options.inverse; | ||
| i = 0; | ||
| ret = ""; | ||
| data = void 0; | ||
| if (options.data) { | ||
| data = Handlebars.createFrame(options.data); | ||
| } | ||
| if (context && typeof context === "object") { | ||
| if (typeof context.length === "number") { | ||
| j = context.length; | ||
| while (i < j) { | ||
| if (data) { | ||
| data.index = i; | ||
| } | ||
| ret = ret + fn(context[i], { | ||
| data: data | ||
| }); | ||
| i++; | ||
| } | ||
| } else { | ||
| for (key in context) { | ||
| if (context.hasOwnProperty(key)) { | ||
| if (data) { | ||
| data.key = key; | ||
| } | ||
| ret = ret + fn(context[key], { | ||
| data: data | ||
| }); | ||
| i++; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (i === 0) { | ||
| ret = inverse(this); | ||
| } | ||
| return ret; | ||
| }; | ||
| module.exports.foreach = foreach = function(arr, options) { | ||
| if (options.inverse && !arr.length) { | ||
| return options.inverse(this); | ||
| } | ||
| return arr.map(function(item, index) { | ||
| item.$index = index; | ||
| item.$notlast = index !== arr.length - 1; | ||
| item.$first = index === 0; | ||
| item.$last = index === arr.length - 1; | ||
| return options.fn(item); | ||
| }).join(""); | ||
| }; | ||
| /* | ||
| adds an a bunch of item prefixed logic to the object | ||
| {{#each_with_classes records prefix="record"}} | ||
| <li class="record_{{item_index}}{{item_position}} {{item_alt}}">{{item_index}}</li> | ||
| {{/each_with_classes}} | ||
| results in the following html | ||
| <li class="record_0 record_first">0</li> | ||
| <li class="record_1 record_alt">1</li> | ||
| <li class="record_2">2</li> | ||
| <li class="record_3 record_last record_alt">3</li> | ||
| */ | ||
| module.exports.each_with_classes = each_with_classes = function(array, fn) { | ||
| var buffer, i, item, j; | ||
| buffer = ""; | ||
| i = 0; | ||
| j = array.length; | ||
| while (i < j) { | ||
| item = array[i]; | ||
| item.item_position = ""; | ||
| if (i === 0) { | ||
| item.item_position = " " + fn.hash.prefix + "-first"; | ||
| } | ||
| if (i === (array.length - 1)) { | ||
| item.item_position += " " + fn.hash.prefix + "-last"; | ||
| } | ||
| item.item_alt = (i % 2 ? fn.hash.prefix + "-alt" : ""); | ||
| item.item_index = i; | ||
| buffer += fn(item); | ||
| i++; | ||
| } | ||
| return buffer; | ||
| }; | ||
| module.exports.eachIndex = eachIndex = function(array, options) { | ||
| var index, result, _i, _len; | ||
| var index, result, value, _i, _len; | ||
@@ -230,3 +309,3 @@ result = ''; | ||
| module.exports.eachProperty = eachProperty = function(obj, options) { | ||
| var key, result; | ||
| var key, result, value; | ||
@@ -254,6 +333,7 @@ result = ''; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("arrayify", arrayify); | ||
| Handlebars.registerHelper('after', after); | ||
| Handlebars.registerHelper('any', any); | ||
| Handlebars.registerHelper('arrayify', arrayify); | ||
| Handlebars.registerHelper('before', before); | ||
| Handlebars.registerHelper('each_with_classes', each_with_classes); | ||
| Handlebars.registerHelper('eachIndex', eachIndex); | ||
@@ -263,3 +343,5 @@ Handlebars.registerHelper('eachProperty', eachProperty); | ||
| Handlebars.registerHelper('first', first); | ||
| Handlebars.registerHelper('foreach', foreach); | ||
| Handlebars.registerHelper('inArray', inArray); | ||
| Handlebars.registerHelper('iterate', iterate); | ||
| Handlebars.registerHelper('join', join); | ||
@@ -270,6 +352,3 @@ Handlebars.registerHelper('joinAny', join); | ||
| Handlebars.registerHelper('lengthEqual', lengthEqual); | ||
| Handlebars.registerHelper('property', property); | ||
| Handlebars.registerHelper('sort', sort); | ||
| Handlebars.registerHelper('stringify', stringify); | ||
| Handlebars.registerHelper('value', value); | ||
| Handlebars.registerHelper('withAfter', withAfter); | ||
@@ -276,0 +355,0 @@ Handlebars.registerHelper('withBefore', withBefore); |
| (function() { | ||
| var Utils, copy; | ||
| var Handlebars, Utils, chapter, copy, defineSection, dir, dirJSON, expMappingJSON, expMappingYAML, extract, glob, grunt, include, path, renderSection, to, toc, _; | ||
| Handlebars = require('../helpers/helpers').Handlebars; | ||
| Utils = require('../utils/utils'); | ||
| grunt = require('grunt'); | ||
| path = require('path'); | ||
| to = require('to'); | ||
| _ = require('lodash'); | ||
| module.exports.copy = copy = function(a, b) { | ||
@@ -10,4 +20,105 @@ return Utils.copyFile(a, b); | ||
| module.exports.section = defineSection = function(section, options) { | ||
| if (Handlebars.sections) { | ||
| Handlebars.sections[section] = options.fn(this); | ||
| } | ||
| return Utils.safeString(''); | ||
| }; | ||
| module.exports.section = renderSection = function(section, options) { | ||
| var content; | ||
| if (Handlebars.sections && Handlebars.sections[section]) { | ||
| content = Handlebars.sections[section]; | ||
| } else { | ||
| content = options.fn(this); | ||
| } | ||
| return Utils.safeString(content); | ||
| }; | ||
| module.exports.include = include = function(src) { | ||
| return Utils.safeString(Utils.read(src)); | ||
| }; | ||
| /* | ||
| Concat: reads in data from a markdown file, and uses the first heading | ||
| as a section heading, and then copies the rest of the content inline. | ||
| Usage: {{{ glob [file] }} | ||
| */ | ||
| module.exports.glob = glob = function(src) { | ||
| var content; | ||
| content = Utils.globFiles(src); | ||
| return Utils.safeString(content); | ||
| }; | ||
| module.exports.chapter = chapter = function(src) { | ||
| var content; | ||
| content = Utils.globFiles(src); | ||
| return Utils.safeString(content); | ||
| }; | ||
| module.exports.extract = extract = function(str) { | ||
| var content; | ||
| content = Utils.globFiles(src); | ||
| return Utils.safeString(content); | ||
| }; | ||
| module.exports.dir = dir = function(src) { | ||
| var list, yml; | ||
| list = grunt.file.expandMapping(src); | ||
| yml = to.format.yaml.stringify(list); | ||
| return Utils.safeString(yml); | ||
| }; | ||
| module.exports.expMappingYAML = expMappingYAML = function(src) { | ||
| var list, yml; | ||
| list = grunt.file.expandMapping(src); | ||
| yml = to.format.yaml.stringify(list); | ||
| return Utils.safeString(yml); | ||
| }; | ||
| module.exports.expMappingJSON = expMappingJSON = function(src) { | ||
| var json, list; | ||
| list = grunt.file.expandMapping(src); | ||
| json = JSON.stringify(list, null, 2); | ||
| return Utils.safeString(json); | ||
| }; | ||
| module.exports.dir = dirJSON = function(src) { | ||
| var json, list; | ||
| list = grunt.file.expand(src); | ||
| json = JSON.stringify(list, null, 2); | ||
| return Utils.safeString(json); | ||
| }; | ||
| module.exports.toc = toc = function(src) { | ||
| var content, headings, output; | ||
| content = grunt.file.expand(src).map(grunt.file.read).join(grunt.util.normalizelf(grunt.util.linefeed)); | ||
| headings = content.match(Utils.findHeadings).join(''); | ||
| output = headings.replace(Utils.findHeadings, '$1 [$2](#' + '$2' + ')\n'); | ||
| return output = Utils.safeString(output); | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("copy", copy); | ||
| Handlebars.registerHelper("dir", dir); | ||
| Handlebars.registerHelper("include", include); | ||
| Handlebars.registerHelper("expMappingYAML", expMappingYAML); | ||
| Handlebars.registerHelper("expMappingJSON", expMappingJSON); | ||
| Handlebars.registerHelper("glob", glob); | ||
| Handlebars.registerHelper("extract", extract); | ||
| Handlebars.registerHelper("chapter", chapter); | ||
| Handlebars.registerHelper("toc", toc); | ||
| Handlebars.registerHelper("defineSection", defineSection); | ||
| Handlebars.registerHelper("renderSection", renderSection); | ||
| return this; | ||
@@ -14,0 +125,0 @@ }; |
@@ -23,30 +23,40 @@ (function() { | ||
| Handlebars.registerHelper("css", function(context) { | ||
| var css, ext, less; | ||
| if (!Array.isArray(context)) { | ||
| context = [context]; | ||
| } | ||
| return Utils.safeString(context.map(function(item) { | ||
| var css, ext, less; | ||
| ext = Utils.getExt(context); | ||
| css = Utils.safeString('<link rel="stylesheet" href="' + options.assets + '/css/' + context + '">'); | ||
| less = Utils.safeString('<link rel="stylesheet/less" href="' + options.assets + '/less/' + context + '">\n' + '<script src="' + options.assets + 'js/less.js" type="text/javascript"></script>\n'); | ||
| switch (ext) { | ||
| case "less": | ||
| return less; | ||
| case "css": | ||
| return css; | ||
| default: | ||
| return css; | ||
| } | ||
| ext = Utils.getExt(item); | ||
| css = '<link rel="stylesheet" href="' + options.assets + '/css/' + item + '">'; | ||
| less = '<link rel="stylesheet/less" href="' + options.assets + '/less/' + item + '">'; | ||
| switch (ext) { | ||
| case "less": | ||
| return less; | ||
| case "css": | ||
| return css; | ||
| default: | ||
| return css; | ||
| } | ||
| }).join("\n")); | ||
| }); | ||
| Handlebars.registerHelper("js", function(context) { | ||
| var coffee, ext, js; | ||
| if (!Array.isArray(context)) { | ||
| context = [context]; | ||
| } | ||
| return Utils.safeString(context.map(function(item) { | ||
| var coffee, ext, js; | ||
| ext = Utils.getExt(context); | ||
| js = Utils.safeString('<script src="' + options.assets + '/js/' + context + '"></script>'); | ||
| coffee = Utils.safeString('<script type="text/coffeescript" src="' + options.assets + '/js/' + context + '"></script>'); | ||
| switch (ext) { | ||
| case "js": | ||
| return js; | ||
| case "coffee": | ||
| return coffee; | ||
| default: | ||
| return js; | ||
| } | ||
| ext = Utils.getExt(item); | ||
| js = '<script src="' + options.assets + '/js/' + item + '"></script>'; | ||
| coffee = '<script type="text/coffeescript" src="' + options.assets + '/js/' + item + '"></script>'; | ||
| switch (ext) { | ||
| case "js": | ||
| return js; | ||
| case "coffee": | ||
| return coffee; | ||
| default: | ||
| return js; | ||
| } | ||
| }).join("\n")); | ||
| }); | ||
@@ -53,0 +63,0 @@ /* |
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| var Utils, file, fs, grunt, isServer, markdown, opts, path, yaml, _; | ||
| var Markdown, Utils, file, fs, grunt, isServer, opts, path, yaml, _; | ||
| fs = require('fs'); | ||
| path = require('path'); | ||
| yaml = require('js-yaml'); | ||
| grunt = require('grunt'); | ||
| file = grunt.file; | ||
| _ = require('lodash'); | ||
| yaml = require('js-yaml'); | ||
| Utils = require('../utils/utils'); | ||
| Markdown = require('../utils/markdown').Markdown(opts); | ||
| opts = { | ||
@@ -41,3 +42,2 @@ gfm: true, | ||
| opts = _.extend(opts, options); | ||
| markdown = require('../utils/markdown').Markdown(opts); | ||
| isServer = typeof process !== 'undefined'; | ||
@@ -116,3 +116,3 @@ /* | ||
| } | ||
| source = title + '[](' + travisUrl + ')'; | ||
| source = title + ' [](' + travisUrl + ')'; | ||
| template = Handlebars.compile(source); | ||
@@ -193,16 +193,2 @@ return Utils.safeString(template(pkg)); | ||
| /* | ||
| Glob: reads in data from a markdown file, and uses the first heading | ||
| as a section heading, and then copies the rest of the content inline. | ||
| Usage: {{{ glob [file] }} | ||
| */ | ||
| Handlebars.registerHelper('glob', function(file) { | ||
| var content; | ||
| file = file.match(file); | ||
| content = grunt.file.read(file); | ||
| content = content.replace(/(^[^ ]*\s)(.+)([^#]+(?=.*)$)/gim, '$2\n' + '$3') || []; | ||
| return Utils.safeString(content); | ||
| }); | ||
| /* | ||
| Embed: Embeds code from an external file as preformatted text. The first parameter | ||
@@ -236,3 +222,3 @@ requires a path to the file you want to embed. There second second optional | ||
| content = options.fn(this); | ||
| return markdown.convert(content); | ||
| return Markdown.convert(content); | ||
| }); | ||
@@ -249,6 +235,6 @@ if (isServer) { | ||
| content = Utils.read(path); | ||
| content = Utils.globFiles(path); | ||
| tmpl = Handlebars.compile(content); | ||
| md = tmpl(this); | ||
| html = markdown.convert(md); | ||
| html = Markdown.convert(md); | ||
| return Utils.safeString(html); | ||
@@ -255,0 +241,0 @@ }); |
| (function() { | ||
| var add, ceil, divide, floor, multiply, round, subtract; | ||
| var add, ceil, divide, floor, multiply, round, subtract, sum, _; | ||
| _ = require('lodash'); | ||
| module.exports.add = add = function(value, addition) { | ||
@@ -32,2 +34,16 @@ return value + addition; | ||
| module.exports.sum = sum = function() { | ||
| var args, i; | ||
| args = _.flatten(arguments); | ||
| sum = 0; | ||
| i = args.length - 1; | ||
| while (i--) { | ||
| if ("number" === typeof args[i]) { | ||
| sum += args[i]; | ||
| } | ||
| } | ||
| return sum; | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
@@ -41,2 +57,3 @@ Handlebars.registerHelper("add", add); | ||
| Handlebars.registerHelper("round", round); | ||
| Handlebars.registerHelper("sum", sum); | ||
| return this; | ||
@@ -43,0 +60,0 @@ }; |
@@ -12,11 +12,2 @@ (function() { | ||
| /* | ||
| 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) { | ||
@@ -23,0 +14,0 @@ Handlebars.registerHelper("default", _default); |
| (function() { | ||
| var Handlebars, Utils, defineSection, disqus, formatPhoneNumber, fs, gist, highlight, include, jsfiddle, renderSection, _; | ||
| var Handlebars, Utils, fs, gist, highlight, jsfiddle, property, stringify, value, _; | ||
@@ -8,34 +8,22 @@ Handlebars = require('../helpers/helpers').Handlebars; | ||
| _ = require('lodash'); | ||
| Utils = require('../utils/utils'); | ||
| module.exports.include = include = function(file) { | ||
| return Utils.safeString(Utils.read(file)); | ||
| }; | ||
| _ = require('lodash'); | ||
| module.exports.section = defineSection = function(section, options) { | ||
| if (Handlebars.sections) { | ||
| Handlebars.sections[section] = options.fn(this); | ||
| } | ||
| return Utils.safeString(''); | ||
| module.exports.value = value = function(file, prop) { | ||
| file = Utils.readJSON(file); | ||
| prop = _.pick(file, prop); | ||
| prop = _.pluck(prop); | ||
| return Utils.safeString(prop); | ||
| }; | ||
| module.exports.section = renderSection = function(section, options) { | ||
| var content; | ||
| if (Handlebars.sections && Handlebars.sections[section]) { | ||
| content = Handlebars.sections[section]; | ||
| } else { | ||
| content = options.fn(this); | ||
| } | ||
| return Utils.safeString(content); | ||
| module.exports.property = property = function(file, prop) { | ||
| file = Utils.readJSON(file); | ||
| prop = _.pick(file, prop); | ||
| return Utils.safeString(JSON.stringify(prop, null, 2)); | ||
| }; | ||
| module.exports.disqus = disqus = function(slug, options) { | ||
| var result; | ||
| return ""; | ||
| result = "<a href=\"http://" + window.location.host + "/blog/" + slug + "#disqus_thread\" data-disqus-identifier=\"/blog/" + slug + "\" ></a>"; | ||
| return Utils.safeString(result); | ||
| module.exports.stringify = stringify = function(file, props) { | ||
| file = Utils.readJSON(file); | ||
| return Utils.safeString(JSON.stringify(file, null, 2)); | ||
| }; | ||
@@ -74,16 +62,9 @@ | ||
| 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('property', property); | ||
| Handlebars.registerHelper('value', value); | ||
| Handlebars.registerHelper('stringify', stringify); | ||
| 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; | ||
@@ -90,0 +71,0 @@ }; |
| (function() { | ||
| var Utils, capitalizeEach, capitalizeFirst, center, dashify, hyphenate, lowercase, replace, reverse, safeString, sentence, titleize, truncate, uppercase; | ||
| var Utils, capitalizeEach, capitalizeFirst, center, dashify, formatPhoneNumber, hyphenate, lowercase, replace, reverse, safeString, sentence, titleize, truncate, uppercase; | ||
@@ -81,2 +81,7 @@ Utils = require('../utils/utils'); | ||
| module.exports.formatPhoneNumber = formatPhoneNumber = function(phoneNumber) { | ||
| phoneNumber = phoneNumber.toString(); | ||
| return "(" + phoneNumber.substr(0, 3) + ") " + phoneNumber.substr(3, 3) + "-" + phoneNumber.substr(6, 4); | ||
| }; | ||
| module.exports.hyphenate = hyphenate = function(str) { | ||
@@ -108,2 +113,3 @@ return str.split(" ").join("-"); | ||
| Handlebars.registerHelper("replace", replace); | ||
| Handlebars.registerHelper("formatPhoneNumber", formatPhoneNumber); | ||
| return this; | ||
@@ -110,0 +116,0 @@ }; |
+78
-12
@@ -25,2 +25,11 @@ (function() { | ||
| Utils.escapeString = function(str, except) { | ||
| return str.replace(/([\.$?*|{}\(\)\[\]\\\/\+\^])/g, function(ch) { | ||
| if (except && except.indexOf(ch) !== -1) { | ||
| return ch; | ||
| } | ||
| return "\\" + ch; | ||
| }); | ||
| }; | ||
| Utils.escapeExpression = function(str) { | ||
@@ -49,2 +58,35 @@ return Handlebars.Utils.escapeExpression; | ||
| Utils.isFunction = function(obj) { | ||
| return typeof obj === "function"; | ||
| }; | ||
| Utils.isBoolean = function(obj) { | ||
| var type, undef; | ||
| undef = void 0; | ||
| type = typeof obj; | ||
| return obj !== undef && type === "boolean" || type === "Boolean"; | ||
| }; | ||
| Utils.isNumber = function(obj) { | ||
| var undef; | ||
| undef = void 0; | ||
| return obj !== undef && obj !== null && (typeof obj === "number" || obj instanceof Number); | ||
| }; | ||
| Utils.isObject = function(obj) { | ||
| var undef; | ||
| undef = void 0; | ||
| return obj !== null && obj !== undef && typeof obj === "object"; | ||
| }; | ||
| Utils.isRegExp = function(obj) { | ||
| var undef; | ||
| undef = void 0; | ||
| return obj !== undef && obj !== null && (obj instanceof RegExp); | ||
| }; | ||
| Utils.repoUrl = function(str) { | ||
@@ -200,2 +242,8 @@ var pkg, url; | ||
| Utils.globFiles = function(src) { | ||
| var content; | ||
| return content = grunt.file.expand(src).map(grunt.file.read).join(grunt.util.normalizelf(grunt.util.linefeed)); | ||
| }; | ||
| Utils.exists = function(file) { | ||
@@ -213,14 +261,2 @@ var src; | ||
| Utils.expand = function(filepath, options) { | ||
| var src; | ||
| return src = grunt.file.expand(filepath, options); | ||
| }; | ||
| Utils.expandMapping = function(patterns, destBase, options) { | ||
| var src; | ||
| return src = grunt.file.expandMapping(patterns, destBase, options); | ||
| }; | ||
| Utils.readJSON = function(filepath, options) { | ||
@@ -263,2 +299,32 @@ var src; | ||
| /* | ||
| Markdown Utils | ||
| */ | ||
| Utils.lowerCase = function(str) { | ||
| str = toString(str); | ||
| return str.toLowerCase(); | ||
| }; | ||
| Utils.linkify = function(str) { | ||
| str = Utils.lowerCase(str); | ||
| return str.split(" ").join("-"); | ||
| }; | ||
| Utils.getHeadings = function(str) { | ||
| var headings; | ||
| headings = str.match(/^(#{1,6})\s*(.*?)\s*#*\s*(?:\n|$)/gm).join(''); | ||
| return headings; | ||
| }; | ||
| Utils.findHeadings = /^(#{1,6})\s*(.*?)\s*#*\s*(?:\n|$)/gm; | ||
| Utils.findh1 = /^(#{1} )\s*(.*?)\s*#*\s*(?:\n|$)/gm; | ||
| Utils.findh2 = /^(#{2} )\s*(.*?)\s*#*\s*(?:\n|$)/gm; | ||
| Utils.findParens = /\(([^)]+)\)/g; | ||
| Utils.urlNormalize = function(filepath) { | ||
@@ -265,0 +331,0 @@ return filepath.replace(/\\/g, "/"); |
+8
-8
| { | ||
| "name": "helper-lib", | ||
| "description": "Extensive collection of Handlebars helpers.", | ||
| "version": "0.2.0", | ||
| "version": "0.2.2", | ||
| "homepage": "https://github.com/assemble/helper-lib", | ||
@@ -41,7 +41,2 @@ "author": { | ||
| "dependencies": { | ||
| "chai": "~1.5.0", | ||
| "grunt-contrib-clean": "~0.4.0", | ||
| "grunt-contrib-coffee": "~0.6.4", | ||
| "grunt-contrib-uglify": "~0.2.0", | ||
| "grunt-mocha-test": "~0.2.0", | ||
| "highlight.js": "~7.3.0", | ||
@@ -51,3 +46,2 @@ "js-yaml": "~2.0.4", | ||
| "marked": "~0.2.8", | ||
| "coffee-script": "~1.6.2", | ||
| "mime": "~1.2.9", | ||
@@ -58,8 +52,14 @@ "should": "~1.2.2" | ||
| "assemble": "https://github.com/assemble/assemble/tarball/master", | ||
| "chai": "~1.5.0", | ||
| "grunt": "~0.4.1", | ||
| "grunt-contrib-jshint": "~0.2.0", | ||
| "grunt-contrib-uglify": "~0.2.0", | ||
| "grunt-contrib-copy": "~0.4.1", | ||
| "grunt-contrib-coffee": "~0.6.4", | ||
| "grunt-mocha-test": "~0.2.0", | ||
| "grunt-contrib-clean": "~0.4.0", | ||
| "grunt-contrib-nodeunit": "~0.1.2", | ||
| "handlebars": "~1.0.10", | ||
| "amdefine": "0.0.4" | ||
| "amdefine": "0.0.4", | ||
| "to": "~0.2.9" | ||
| }, | ||
@@ -66,0 +66,0 @@ "keywords": [ |
+174
-130
@@ -1,11 +0,5 @@ | ||
| # [Helper Library v0.2.0](http://github.com/assemble/helper-lib) [](https://travis-ci.org/assemble/helper-lib) | ||
| # [Helper Library v0.2.2](http://github.com/assemble/helper-lib) [](https://travis-ci.org/assemble/helper-lib) | ||
| > Extensive collection of Handlebars helpers. | ||
| ## Quick start | ||
@@ -15,124 +9,125 @@ For linting and testing this project uses Grunt `~0.4.1`, but Grunt is **not required** to use the helpers. Check out the [Getting Started](http://gruntjs.com/getting-started) guide to learn more about Grunt. | ||
| ```shell | ||
| npm install helper-lib --save-dev | ||
| npm install helper-lib --save | ||
| ``` | ||
| Once helper-lib has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: | ||
| Once helper-lib has been installed, it may be used within your application with the following JavaScript: | ||
| ```js | ||
| grunt.loadNpmTasks('helper-lib'); | ||
| var handlebars = require('handlebars'); | ||
| var helpers = require('helper-lib'); | ||
| helpers.register(handlebars); | ||
| ``` | ||
| This plugin was designed to work with _Grunt 0.4.x_. If you're still using grunt _v0.3.x_ it's strongly recommended that you upgrade, but in case you can't please use _v0.3.1_. | ||
| Now your handlebars instance will have access to the helpers. | ||
| ### | ||
| When completed, you'll be able to run the various `grunt` commands provided: | ||
| **Table of Contents** | ||
| #### build - `grunt` | ||
| Runs the Less.js compiler to rebuild the specified `/test/fixtures/**` files. . | ||
| ## [The Helpers](#the-helpers) | ||
| #### test - `grunt test` | ||
| Runs jshint on JavaScripts and nodeunit tests on . | ||
| ### [Special](#special) | ||
| * [{{changelog}}](#changelog) | ||
| * [{{formatPhoneNumber}}](#formatphonenumber) | ||
| #### watch - `grunt watch` | ||
| This is a convenience method for watching and automatically re-building them whenever you save. Requires the [grunt-contrib-watch](http://github.com/gruntjs/grunt-contrib-watch) Grunt plugin. | ||
| ### [Strings](#strings) | ||
| * [{{hyphenate}}](#hyphenate) | ||
| * [{{dashify}}](#dashify) | ||
| * [{{lowercase}}](#lowercase) | ||
| * [{{uppercase}}](#uppercase) | ||
| * [{{capitalizeFirst}}](#capitalizefirst) | ||
| * [{{capitalizeEach}}](#capitalizeeach) | ||
| * [{{titleize}}](#titleize) | ||
| * [{{sentence}}](#sentence) | ||
| * [{{reverse}}](#reverse) | ||
| * [{{truncate}}](#truncate) | ||
| * [{{center}}](#center) | ||
| * [{{nl2br}}](#nl2br) | ||
| Should you encounter problems with installing dependencies or running the `grunt` commands, be sure to first uninstall any previous versions (global and local) you may have installed, and then rerun `npm install`. | ||
| ### [Collections](#collections) | ||
| * [{{first}}](#first) | ||
| * [{{withFirst}}](#withfirst) | ||
| * [{{last}}](#last) | ||
| * [{{withLast}}](#withlast) | ||
| * [{{after}}](#after) | ||
| * [{{withAfter}}](#withafter) | ||
| * [{{before}}](#before) | ||
| * [{{withBefore}}](#withbefore) | ||
| * [{{join}}](#join) | ||
| * [{{sort}}](#sort) | ||
| * [{{withSort}}](#withsort) | ||
| * [{{length}}](#length) | ||
| * [{{lengthEqual}}](#lengthequal) | ||
| * [{{empty}}](#empty) | ||
| * [{{any}}](#any) | ||
| * [{{inArray}}](#inarray) | ||
| * [{{eachIndex}}](#eachindex) | ||
| * [{{eachProperty}}](#eachproperty) | ||
| **Table of Contents** | ||
| ### [Math](#math) | ||
| * [{{add}}](#add) | ||
| * [{{subtract}}](#subtract) | ||
| * [{{divide}}](#divide) | ||
| * [{{multiply}}](#multiply) | ||
| * [{{floor}}](#floor) | ||
| * [{{ceil}}](#ceil) | ||
| * [{{round}}](#round) | ||
| * [{{sum}}](#sum) | ||
| - [The Helpers](#the-helpers) | ||
| - [Path](#path) | ||
| - [Strings](#strings) | ||
| - [hyphenate](#hyphenate) | ||
| - [dashify](#dashify) | ||
| - [lowercase](#lowercase) | ||
| - [uppercase](#uppercase) | ||
| - [capitalizeFirst](#capitalizefirst) | ||
| - [capitalizeEach](#capitalizeeach) | ||
| - [titleize](#titleize) | ||
| - [sentence](#sentence) | ||
| - [reverse](#reverse) | ||
| - [truncate](#truncate) | ||
| - [center](#center) | ||
| - [nl2br](#nl2br) | ||
| - [Collections](#collections) | ||
| - [first](#first) | ||
| - [withFirst](#withfirst) | ||
| - [last](#last) | ||
| - [withLast](#withlast) | ||
| - [after](#after) | ||
| - [withAfter](#withafter) | ||
| - [before](#before) | ||
| - [withBefore](#withbefore) | ||
| - [join](#join) | ||
| - [sort](#sort) | ||
| - [withSort](#withsort) | ||
| - [length](#length) | ||
| - [lengthEqual](#lengthequal) | ||
| - [empty](#empty) | ||
| - [any](#any) | ||
| - [inArray](#inarray) | ||
| - [eachIndex](#eachindex) | ||
| - [eachProperty](#eachproperty) | ||
| - [Math](#math) | ||
| - [add](#add) | ||
| - [subtract](#subtract) | ||
| - [divide](#divide) | ||
| - [multiply](#multiply) | ||
| - [floor](#floor) | ||
| - [ceil](#ceil) | ||
| - [round](#round) | ||
| - [Numbers](#numbers) | ||
| - [toFixed](#tofixed) | ||
| - [toPrecision](#toprecision) | ||
| - [toExponential](#toexponential) | ||
| - [toInt](#toint) | ||
| - [toFloat](#tofloat) | ||
| - [toAbbr](#toabbr) | ||
| - [addCommas](#addcommas) | ||
| - [Comparisons](#comparisons) | ||
| - [Equal](#equal) | ||
| - [is](#is) | ||
| - [if_eq](#if_eq) | ||
| - [isnt](#isnt) | ||
| - [or](#or) | ||
| - [and](#and) | ||
| - [unless_eq](#unless_eq) | ||
| - [Greater Than](#greater-than) | ||
| - [if_gt](#if_gt) | ||
| - [gt](#gt) | ||
| - [unless_gt](#unless_gt) | ||
| - [if_gteq](#if_gteq) | ||
| - [gte](#gte) | ||
| - [unless_gteq](#unless_gteq) | ||
| - [Less Than](#less-than) | ||
| - [lt](#lt) | ||
| - [lte](#lte) | ||
| - [unless_lt](#unless_lt) | ||
| - [unless_lteq](#unless_lteq) | ||
| - [Special](#special) | ||
| - [formatPhoneNumber](#formatphonenumber) | ||
| - [Dates](#dates) | ||
| - [formatDate](#formatdate) | ||
| - [now](#now) | ||
| - [timeago](#timeago) | ||
| - [Inflections](#inflections) | ||
| - [inflect](#inflect) | ||
| - [ordinalize](#ordinalize) | ||
| - [HTML](#html) | ||
| - [ul](#ul) | ||
| - [ol](#ol) | ||
| - [br](#br) | ||
| - [Logging](#logging) | ||
| - [log](#log) | ||
| - [debug](#debug) | ||
| - [Miscellaneous](#miscellaneous) | ||
| - [default](#default) | ||
| - [partial (**NOT USED IN ASSEMBLE**)](#partial-not-used-in-assemble) | ||
| - [Contributing](#contributing) | ||
| - [Adding Custom Helpers](#adding-custom-helpers) | ||
| - [Release History](#release-history) | ||
| - [Roadmap](#roadmap) | ||
| - [Authors](#authors) | ||
| - [Credit](#credit) | ||
| ### [Numbers](#numbers) | ||
| * [{{toFixed}}](#tofixed) | ||
| * [{{toPrecision}}](#toprecision) | ||
| * [{{toExponential}}](#toexponential) | ||
| * [{{toInt}}](#toint) | ||
| * [{{toFloat}}](#tofloat) | ||
| * [{{toAbbr}}](#toabbr) | ||
| * [{{addCommas}}](#addcommas) | ||
| ### [Comparisons: Equal](#comparisons-equal) | ||
| * [{{is}}](#is) | ||
| * [{{if_eq}}](#if_eq) | ||
| * [{{isnt}}](#isnt) | ||
| * [{{or}}](#or) | ||
| * [{{and}}](#and) | ||
| * [{{unless_eq}}](#unless_eq) | ||
| ### [Comparisons: Greater Than](#comparisons-greater-than) | ||
| * [{{if_gt}}](#if_gt) | ||
| * [{{gt}}](#gt) | ||
| * [{{unless_gt}}](#unless_gt) | ||
| * [{{if_gteq}}](#if_gteq) | ||
| * [{{gte}}](#gte) | ||
| * [{{unless_gteq}}](#unless_gteq) | ||
| ### [Comparisons: Less Than](#comparisons-less-than) | ||
| * [{{lt}}](#lt) | ||
| * [{{lte}}](#lte) | ||
| * [{{unless_lt}}](#unless_lt) | ||
| * [{{unless_lteq}}](#unless_lteq) | ||
| ### [Dates](#dates) | ||
| * [{{formatDate}}](#formatdate) | ||
| * [{{now}}](#now) | ||
| * [{{timeago}}](#timeago) | ||
| ### [Inflections](#inflections) | ||
| * [{{inflect}}](#inflect) | ||
| * [{{ordinalize}}](#ordinalize) | ||
| ### [HTML](#html) | ||
| * [{{gist}}](#gist) | ||
| * [{{embed}}](#embed) | ||
| * [{{blockquote}}](#blockquote) | ||
| * [{{stripes}}](#stripes) | ||
| * [{{timeline}}](#timeline) | ||
| * [{{ul}}](#ul) | ||
| * [{{ol}}](#ol) | ||
| * [{{br}}](#br) | ||
| ### [Logging](#logging) | ||
| * [{{log}}](#log) | ||
| * [{{debug}}](#debug) | ||
| ### [Miscellaneous](#miscellaneous) | ||
| * [{{default}}](#default) | ||
| * [{{include}}](#include) | ||
| ## Overview | ||
@@ -165,4 +160,39 @@ Handlebars.js ships with some built-in helpers, such as `{{#each}}`, `{{#if}}` and `{{#unless}}`. Here is how helpers work: | ||
| ### YAML Helpers | ||
| ### README Helpers | ||
| #### authors | ||
| TODO... | ||
| ### Travis CI | ||
| #### travis | ||
| Creates a "full" Travis CI link in markdown format. | ||
| Params: `branch` | ||
| Type: `String` | ||
| Usage: `{{travis [branch]}}` | ||
| Example using default: `{{travis}}` | ||
| ``` md | ||
| # [helper-lib v2.0.0](https://github.com/assemble/helper-lib)[](https://travis-ci.org/assemble/helper-lib) | ||
| ``` | ||
| Example with branch: `{{travis 'master'}}` | ||
| ``` md | ||
| # [helper-lib v2.0.0](https://github.com/assemble/helper-lib)[](https://travis-ci.org/assemble/helper-lib) | ||
| ``` | ||
| #### travis-badge | ||
| Creates a Travis CI link in markdown format. | ||
| Params: `none` | ||
| Usage: `{{travis-badge}}` | ||
| Example: | ||
| ``` md | ||
| [](https://travis-ci.org/assemble/helper-lib) | ||
| ``` | ||
| #### changelog | ||
| A few convenience helpers that read data in YAML format, and do interesting things with the data. Well... they "do things" with the data. Anyway I guess only nerds like me find it interesting. | ||
@@ -177,8 +207,4 @@ | ||
| More info here: [js-yaml](https://github.com/nodeca/js-yaml) | ||
| Here is an example of the format to follow in your `CHANGELOG` file: | ||
| #### changelog | ||
| Here is the format to follow in your `CHANGELOG` file: | ||
| ``` yaml | ||
@@ -202,3 +228,3 @@ v0.1.2 | ||
| And the output will look like this: | ||
| The output will look like this: | ||
@@ -210,11 +236,9 @@ ``` md | ||
| * More info here: [js-yaml](https://github.com/nodeca/js-yaml) | ||
| * See the tests here: [test/helpers/special_test.js](test/helpers/special_test.js) | ||
| ### Other | ||
| #### formatPhoneNumber | ||
@@ -892,4 +916,22 @@ _Output a formatted phone number_ | ||
| #### sum | ||
| _Returns the sum of multiple numbers. Similar to `{{#add}}` block helper but accepts multiple arguments._ | ||
| <br>Parameters: `none` | ||
| ``` js | ||
| // Data | ||
| value = { | ||
| a: 1, | ||
| b: 2, | ||
| c: 3 | ||
| } | ||
| ``` | ||
| ``` html | ||
| // Template | ||
| {{sum value.a value.b value.c}} | ||
| // Result: | ||
| 6 | ||
| ``` | ||
| ### Numbers | ||
@@ -1641,3 +1683,3 @@ #### toFixed | ||
| ## Copyright and license | ||
| Copyright NaN Assemble | ||
| Copyright 2013 Assemble | ||
@@ -1647,2 +1689,4 @@ [MIT License](LICENSE-MIT) | ||
| ## Release History | ||
| * 2013-05-11 v0.2.3 File globbing added to some helpers. Including md and some file helpers. | ||
| * 2013-05-07 v0.2.0 A bunch of new tests for markdown and special helpers.Refactored most of the rest of the helpers to separate functions from Handlebars registration. | ||
| * 2013-05-02 v0.1.32 Updated utils and a number of helpers, including value, property, and stringify. | ||
@@ -1669,3 +1713,3 @@ * 2013-04-21 v0.1.31 Fixing relative helper | ||
| _This file was generated using Grunt and [assemble](http://github.com/assemble/assemble) on Tue May 07 2013 22:23:19._ | ||
| _This file was generated using Grunt and [assemble](http://github.com/assemble/assemble) on Sat May 11 2013 18:57:26._ | ||
@@ -1672,0 +1716,0 @@ |
| (function() { | ||
| }).call(this); |
| (function() { | ||
| }).call(this); |
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
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
110516
6.75%6
-50%1960
10.99%1777
2.54%13
85.71%31
-6.06%8
14.29%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed