helper-lib
Advanced tools
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| var HTML, Markdown, Utils, fs, grunt, isServer, opts, path, _; | ||
| Utils = require('../utils/utils'); | ||
| HTML = require('../utils/html'); | ||
| fs = require('fs'); | ||
| path = require('path'); | ||
| grunt = require('grunt'); | ||
| _ = require('lodash'); | ||
| Markdown = require('../utils/markdown').Markdown(opts); | ||
| opts = { | ||
| gfm: true, | ||
| tables: true, | ||
| breaks: false, | ||
| highlight: null, | ||
| pedantic: false, | ||
| sanitize: true, | ||
| silent: false, | ||
| smartLists: true, | ||
| langPrefix: "lang-", | ||
| highlight: function(code, lang) { | ||
| var res; | ||
| res = void 0; | ||
| if (!lang) { | ||
| return code; | ||
| } | ||
| switch (lang) { | ||
| case "js": | ||
| lang = "javascript"; | ||
| } | ||
| try { | ||
| return res = hljs.highlight(lang, code).value; | ||
| } finally { | ||
| return res || code; | ||
| } | ||
| } | ||
| }; | ||
| opts = _.extend(opts, options); | ||
| isServer = typeof process !== 'undefined'; | ||
| /* | ||
| 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("switch", function(src) { | ||
| var html, md, output; | ||
| md = '# ' + src; | ||
| html = '<h1>' + src + '</h1>'; | ||
| output = Utils.switchOutput(options.ext, md, html); | ||
| return Utils.safeString(output); | ||
| }); | ||
| 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("link", 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("css", function(context) { | ||
| if (!Array.isArray(context)) { | ||
| context = [context]; | ||
| } | ||
| return Utils.safeString(context.map(function(item) { | ||
| var css, ext, less; | ||
| 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) { | ||
| if (!Array.isArray(context)) { | ||
| context = [context]; | ||
| } | ||
| return Utils.safeString(context.map(function(item) { | ||
| var coffee, ext, 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")); | ||
| }); | ||
| /* | ||
| readme-title: Generates a title and Travis CI badge for a README.md. | ||
| Syntax: {{travis [src]}} | ||
| */ | ||
| Handlebars.registerHelper("readme-title", function(branch) { | ||
| var name, pkg, repo, source, template, version; | ||
| 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; | ||
| } | ||
| if (travis.name) { | ||
| pkg.name = travis.name; | ||
| } else { | ||
| pkg.name; | ||
| } | ||
| source = '[](' + travisUrl + ')'; | ||
| 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", 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)); | ||
| }); | ||
| /* | ||
| Markdown: markdown helper enables writing markdown inside HTML | ||
| and then renders the markdown as HTML inline with the rest of the page. | ||
| Usage: {{#markdown}} # This is a title. {{/markdown}} | ||
| Renders to: <h1>This is a title </h1> | ||
| */ | ||
| Handlebars.registerHelper("markdown", function(options) { | ||
| var content; | ||
| content = options.fn(this); | ||
| return Markdown.convert(content); | ||
| }); | ||
| if (isServer) { | ||
| /* | ||
| Markdown helper used to read in a file and inject | ||
| the rendered markdown into the HTML. | ||
| Usage: {{md ../path/to/file.md}} | ||
| */ | ||
| Handlebars.registerHelper("md", function(path) { | ||
| var content, html, md, tmpl; | ||
| content = Utils.globFiles(path); | ||
| tmpl = Handlebars.compile(content); | ||
| md = tmpl(this); | ||
| html = Markdown.convert(md); | ||
| return Utils.safeString(html); | ||
| }); | ||
| } | ||
| return this; | ||
| }; | ||
| /* | ||
| Markdown: markdown helper enables writing markdown inside HTML | ||
| and then renders the markdown as HTML inline with the rest of the page. | ||
| Usage: {{#markdown}} # This is a title. {{/markdown}} | ||
| Renders to: <h1>This is a title </h1> | ||
| */ | ||
| }).call(this); |
@@ -43,3 +43,3 @@ (function() { | ||
| /* | ||
| Concat: reads in data from a markdown file, and uses the first heading | ||
| 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. | ||
@@ -46,0 +46,0 @@ Usage: {{{ glob [file] }} |
+118
-13
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| var HTML, Utils; | ||
| var HTML, Utils, grunt; | ||
| grunt = require('grunt'); | ||
| Utils = require('../utils/utils'); | ||
| HTML = require('../utils/html'); | ||
| /* | ||
| 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("switch", function(src) { | ||
@@ -62,8 +56,119 @@ var html, md, output; | ||
| }); | ||
| /* | ||
| 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("readme-title", function(branch) { | ||
| var name, pkg, repo, source, template, version; | ||
| 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)); | ||
| }); | ||
| 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; | ||
| } | ||
| if (travis.name) { | ||
| pkg.name = travis.name; | ||
| } else { | ||
| pkg.name; | ||
| } | ||
| source = '[](' + travisUrl + ')'; | ||
| template = Handlebars.compile(source); | ||
| return Utils.safeString(template(pkg)); | ||
| }); | ||
| 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)); | ||
| }); | ||
| Handlebars.registerHelper('authors', function(authors) { | ||
| var matches; | ||
| if (Utils.isUndefined(authors)) { | ||
| authors = Utils.read("./AUTHORS"); | ||
| } else { | ||
| authors = Utils.read(authors); | ||
| } | ||
| matches = authors.replace(/(.*?)\s*\((.*)\)/g, '* [$1]($2) ') || []; | ||
| return Utils.safeString(matches); | ||
| }); | ||
| Handlebars.registerHelper('AUTHORS', function(authors) { | ||
| var matches; | ||
| if (Utils.isUndefined(authors)) { | ||
| authors = Utils.read("./AUTHORS"); | ||
| } else { | ||
| authors = Utils.read(authors); | ||
| } | ||
| matches = authors.replace(/(.*?)\s*\((.*)\)/g, '\n**[$1]**\n \n+ [$2]($2) ') || []; | ||
| return Utils.safeString(matches); | ||
| }); | ||
| Handlebars.registerHelper("changelog", function(changelog) { | ||
| var source, template; | ||
| if (Utils.isUndefined(changelog)) { | ||
| changelog = Utils.readYAML('./CHANGELOG'); | ||
| } else { | ||
| changelog = Utils.readYAML(changelog); | ||
| } | ||
| source = "{{#each .}}* {{date}}\t\t\t{{{@key}}}\t\t\t{{#each changes}}{{{.}}}{{/each}}\n{{/each}}"; | ||
| template = Handlebars.compile(source); | ||
| return Utils.safeString(template(changelog)); | ||
| }); | ||
| Handlebars.registerHelper("roadmap", function(roadmap) { | ||
| var source, template; | ||
| if (Utils.isUndefined(roadmap)) { | ||
| roadmap = Utils.readYAML('./ROADMAP'); | ||
| } else { | ||
| roadmap = Utils.readYAML(roadmap); | ||
| } | ||
| source = "{{#each .}}* {{eta}}\t\t\t{{{@key}}}\t\t\t{{#each goals}}{{{.}}}{{/each}}\n{{else}}_(Big plans in the works)_{{/each}}"; | ||
| template = Handlebars.compile(source); | ||
| return Utils.safeString(template(roadmap)); | ||
| }); | ||
| Handlebars.registerHelper('embed', function(file, language) { | ||
| var content; | ||
| file = grunt.file.read(file); | ||
| if (Utils.isUndefined(language)) { | ||
| language = ""; | ||
| } | ||
| content = '``` ' + language + '\n' + file + '\n```'; | ||
| return Utils.safeString(content); | ||
| }); | ||
| Handlebars.registerHelper("href", function(url, text, linkClass) { | ||
@@ -70,0 +175,0 @@ var html, md, result; |
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| var Markdown, Utils, file, fs, grunt, isServer, opts, path, yaml, _; | ||
| var Markdown, Utils, fs, isServer, opts, path, _; | ||
| fs = require('fs'); | ||
| path = require('path'); | ||
| grunt = require('grunt'); | ||
| file = grunt.file; | ||
| _ = require('lodash'); | ||
| yaml = require('js-yaml'); | ||
| Utils = require('../utils/utils'); | ||
@@ -44,167 +41,2 @@ Markdown = require('../utils/markdown').Markdown(opts); | ||
| /* | ||
| readme-title: Generates a title and Travis CI badge for a README.md. | ||
| Syntax: {{travis [src]}} | ||
| */ | ||
| Handlebars.registerHelper("readme-title", function(branch) { | ||
| var name, pkg, repo, source, template, version; | ||
| 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; | ||
| } | ||
| if (travis.name) { | ||
| pkg.name = travis.name; | ||
| } else { | ||
| pkg.name; | ||
| } | ||
| source = '[](' + travisUrl + ')'; | ||
| 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", 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 | ||
| author or list of authors for a README.md. Accepts a second optional | ||
| parameter to a different file than the default. | ||
| Usage: {{authors}} or {{ authors [file] }} | ||
| */ | ||
| Handlebars.registerHelper('authors', function(authors) { | ||
| var matches; | ||
| if (Utils.isUndefined(authors)) { | ||
| authors = Utils.read("./AUTHORS"); | ||
| } else { | ||
| authors = Utils.read(authors); | ||
| } | ||
| matches = authors.replace(/(.*?)\s*\((.*)\)/g, '* [$1]($2) ') || []; | ||
| return Utils.safeString(matches); | ||
| }); | ||
| /* | ||
| AUTHORS: (case senstitive) Same as `{{authors}}`, but outputs a different format. | ||
| */ | ||
| Handlebars.registerHelper('AUTHORS', function(authors) { | ||
| var matches; | ||
| if (Utils.isUndefined(authors)) { | ||
| authors = Utils.read("./AUTHORS"); | ||
| } else { | ||
| authors = Utils.read(authors); | ||
| } | ||
| matches = authors.replace(/(.*?)\s*\((.*)\)/g, '\n**[$1]**\n \n+ [$2]($2) ') || []; | ||
| return Utils.safeString(matches); | ||
| }); | ||
| /* | ||
| Changelog: Reads in data from an "CHANGELOG" file to generate markdown formatted | ||
| changelog or list of changelog entries for a README.md. Accepts a | ||
| second optional parameter to change to a different file than the default. | ||
| Usage: {{changelog}} or {{changelog [src]}} | ||
| */ | ||
| Handlebars.registerHelper("changelog", function(changelog) { | ||
| var source, template; | ||
| if (Utils.isUndefined(changelog)) { | ||
| changelog = Utils.readYAML('./CHANGELOG'); | ||
| } else { | ||
| changelog = Utils.readYAML(changelog); | ||
| } | ||
| source = "{{#each .}}* {{date}}\t\t\t{{{@key}}}\t\t\t{{#each changes}}{{{.}}}{{/each}}\n{{/each}}"; | ||
| template = Handlebars.compile(source); | ||
| return Utils.safeString(template(changelog)); | ||
| }); | ||
| /* | ||
| Roadmap: Reads in data from an "ROADMAP" file to generate markdown formatted | ||
| roadmap or list of roadmap entries for a README.md. Accepts a | ||
| second optional parameter to change to a different file than the default. | ||
| Usage: {{roadmap}} or {{roadmap [src]}} | ||
| */ | ||
| Handlebars.registerHelper("roadmap", function(roadmap) { | ||
| var source, template; | ||
| if (Utils.isUndefined(roadmap)) { | ||
| roadmap = Utils.readYAML('./ROADMAP'); | ||
| } else { | ||
| roadmap = Utils.readYAML(roadmap); | ||
| } | ||
| source = "{{#each .}}* {{eta}}\t\t\t{{{@key}}}\t\t\t{{#each goals}}{{{.}}}{{/each}}\n{{else}}_(Big plans in the works)_{{/each}}"; | ||
| template = Handlebars.compile(source); | ||
| return Utils.safeString(template(roadmap)); | ||
| }); | ||
| /* | ||
| Embed: Embeds code from an external file as preformatted text. The first parameter | ||
| requires a path to the file you want to embed. There second second optional | ||
| parameter is for specifying (forcing) syntax highlighting for language of choice. | ||
| Syntax: {{ embed [file] [lang] }} | ||
| Usage: {{embed 'path/to/file.js'}} or {{embed 'path/to/file.hbs' 'html'}} | ||
| */ | ||
| Handlebars.registerHelper('embed', function(file, language) { | ||
| var content; | ||
| file = grunt.file.read(file); | ||
| if (Utils.isUndefined(language)) { | ||
| language = ""; | ||
| } | ||
| content = '``` ' + language + '\n' + file + '\n```'; | ||
| return Utils.safeString(content); | ||
| }); | ||
| /* | ||
| Markdown: markdown helper enables writing markdown inside HTML | ||
@@ -211,0 +43,0 @@ and then renders the markdown as HTML inline with the rest of the page. |
+99
-23
| (function() { | ||
| var Handlebars, Utils, fs, grunt, path, | ||
| var Handlebars, Utils, fs, grunt, minimatch, path, toString, _, | ||
| __slice = [].slice; | ||
@@ -13,2 +13,6 @@ | ||
| _ = require("lodash"); | ||
| minimatch = require("minimatch"); | ||
| Utils = module.exports = {}; | ||
@@ -18,2 +22,20 @@ | ||
| /* | ||
| # String Utils | ||
| */ | ||
| toString = function(val) { | ||
| if (val == null) { | ||
| return ""; | ||
| } else { | ||
| return val.toString(); | ||
| } | ||
| }; | ||
| Utils.lowerCase = function(str) { | ||
| str = toString(str); | ||
| return str.toLowerCase(); | ||
| }; | ||
| Utils.isUndefined = function(value) { | ||
@@ -242,8 +264,2 @@ return value === 'undefined' || Utils.toString.call(value) === '[object Function]' || (value.hash != null); | ||
| 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) { | ||
@@ -299,31 +315,91 @@ var src; | ||
| /* | ||
| Markdown Utils | ||
| # Markdown Utils | ||
| */ | ||
| Utils.lowerCase = function(str) { | ||
| str = toString(str); | ||
| return str.toLowerCase(); | ||
| }; | ||
| Utils.findHeadings = /^(#{1,6})\s*(.*?)\s*#*\s*(?:\n|$)/gm; | ||
| Utils.linkify = function(str) { | ||
| str = Utils.lowerCase(str); | ||
| return str.split(" ").join("-"); | ||
| Utils.findh1 = /^(#{1} )\s*(.*?)\s*#*\s*(?:\n|$)/gm; | ||
| Utils.findh2 = /^(#{2} )\s*(.*?)\s*#*\s*(?:\n|$)/gm; | ||
| Utils.findParens = /\(([^)]+)\)/g; | ||
| /* | ||
| # Globbing Utils | ||
| */ | ||
| Utils.globFiles = function(src) { | ||
| var content; | ||
| return content = grunt.file.expand(src).map(grunt.file.read).join(grunt.util.normalizelf(grunt.util.linefeed)); | ||
| }; | ||
| Utils.getHeadings = function(str) { | ||
| var headings; | ||
| Utils.buildObjectPaths = function(obj) { | ||
| var files; | ||
| headings = str.match(/^(#{1,6})\s*(.*?)\s*#*\s*(?:\n|$)/gm).join(''); | ||
| return headings; | ||
| files = []; | ||
| _.forOwn(obj, function(value, key) { | ||
| var file, recurse; | ||
| file = key; | ||
| recurse = function(obj) { | ||
| return _.forOwn(obj, function(value, key) { | ||
| if (file.length !== 0) { | ||
| file += '/'; | ||
| } | ||
| file += key; | ||
| if (_.isObject(value)) { | ||
| return recurse(value); | ||
| } | ||
| }); | ||
| }; | ||
| if (_.isObject(value)) { | ||
| recurse(value); | ||
| } | ||
| return files.push(file); | ||
| }); | ||
| return files; | ||
| }; | ||
| Utils.findHeadings = /^(#{1,6})\s*(.*?)\s*#*\s*(?:\n|$)/gm; | ||
| Utils.globObject = function(obj, pattern) { | ||
| var files, getValue, matches, rtn, setValue; | ||
| Utils.findh1 = /^(#{1} )\s*(.*?)\s*#*\s*(?:\n|$)/gm; | ||
| files = Utils.buildObjectPaths(obj); | ||
| matches = files.filter(minimatch.filter(pattern)); | ||
| rtn = {}; | ||
| getValue = function(obj, path) { | ||
| var keys, value; | ||
| Utils.findh2 = /^(#{2} )\s*(.*?)\s*#*\s*(?:\n|$)/gm; | ||
| keys = path.split('/'); | ||
| value = _.cloneDeep(obj); | ||
| _.forEach(keys, function(key) { | ||
| if (_.has(value, key)) { | ||
| return value = _.cloneDeep(value[key]); | ||
| } | ||
| }); | ||
| return value; | ||
| }; | ||
| setValue = function(obj, path, value) { | ||
| var key, keys; | ||
| Utils.findParens = /\(([^)]+)\)/g; | ||
| keys = path.split('/'); | ||
| key = keys.shift(); | ||
| if (keys.length) { | ||
| obj[key] = setValue({}, keys.join('/'), value); | ||
| } else { | ||
| obj[key] = value; | ||
| } | ||
| return obj; | ||
| }; | ||
| _.forEach(matches, function(match) { | ||
| var value; | ||
| value = getValue(obj, match); | ||
| return rtn = setValue(rtn, match, value); | ||
| }); | ||
| return rtn; | ||
| }; | ||
| Utils.urlNormalize = function(filepath) { | ||
@@ -330,0 +406,0 @@ return filepath.replace(/\\/g, "/"); |
+11
-7
| { | ||
| "name": "helper-lib", | ||
| "description": "Extensive collection of Handlebars helpers.", | ||
| "version": "0.2.2", | ||
| "version": "0.2.3", | ||
| "homepage": "https://github.com/assemble/helper-lib", | ||
@@ -46,17 +46,21 @@ "author": { | ||
| "mime": "~1.2.9", | ||
| "should": "~1.2.2" | ||
| "minimatch": "~0.2.12", | ||
| "to": "~0.2.9" | ||
| }, | ||
| "devDependencies": { | ||
| "amdefine": "0.0.4", | ||
| "assemble": "https://github.com/assemble/assemble/tarball/master", | ||
| "chai": "~1.5.0", | ||
| "coffee-script": "~1.6.2", | ||
| "grunt": "~0.4.1", | ||
| "grunt-contrib-clean": "~0.4.0", | ||
| "grunt-contrib-coffee": "~0.6.4", | ||
| "grunt-contrib-copy": "~0.4.1", | ||
| "grunt-contrib-jshint": "~0.2.0", | ||
| "grunt-contrib-nodeunit": "~0.1.2", | ||
| "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", | ||
| "minimatch": "~0.2.12", | ||
| "should": "~1.2.2", | ||
| "to": "~0.2.9" | ||
@@ -63,0 +67,0 @@ }, |
+2
-2
@@ -1,2 +0,2 @@ | ||
| # [Helper Library v0.2.2](http://github.com/assemble/helper-lib) [](https://travis-ci.org/assemble/helper-lib) | ||
| # [Helper Library v0.2.3](http://github.com/assemble/helper-lib) [](https://travis-ci.org/assemble/helper-lib) | ||
@@ -1705,3 +1705,3 @@ > Extensive collection of Handlebars helpers. | ||
| _This file was generated using Grunt and [assemble](http://github.com/assemble/assemble) on Sat May 11 2013 18:57:26._ | ||
| _This file was generated using Grunt and [assemble](http://github.com/assemble/assemble) on Sat May 11 2013 18:37:01._ | ||
@@ -1708,0 +1708,0 @@ |
Sorry, the diff of this file is not supported yet
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
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
117499
6.32%32
3.23%2190
11.73%7
16.67%16
23.08%9
12.5%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed