helper-lib
Advanced tools
| <div class="navbar navbar-fixed-top"> | ||
| <div class="navbar-inner"> | ||
| <div class="container"> | ||
| <ul class="nav"> | ||
| <li><a href="embed.html">Embed Helper</a></li> | ||
| <li><a href="extname.html">Extension Helper</a></li> | ||
| <li><a href="gist.html">Gist Helper</a></li> | ||
| <li><a href="html.html">HTML Helpers</a></li> | ||
| <li><a href="icon.html">Icon Helper</a></li> | ||
| <li><a href="markdown.html">Markdown Helpers</a></li> | ||
| <li><a href="pages.html">Pages (Collection) Variables</a></li> | ||
| <li><a href="sections.html">Defining sections from inside a page.</a></li> | ||
| </ul> | ||
| <ul class="nav"><li><a href="http://github.com/assemble/">Visit Assemble</a></li></ul> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| # README | ||
| ## relative | ||
| _Derive the relative path from one absolute path to another._ | ||
| Parameters: `string` (the value to test against) | ||
| Default: `none` | ||
| Usage: | ||
| ``` html | ||
| [{{link.text}}]({{link.url}}) | ||
| ``` | ||
| Example: | ||
| ``` handlebars | ||
| <a href="{{relative "src" "dist"}}/assets/css/styles.css"></a> | ||
| ``` | ||
| Renders to: | ||
| ``` html | ||
| <a href="../../dist/assets/css/styles.css"></a> | ||
| ``` |
| # Include | ||
| #### relative | ||
| _Derive the relative path from one absolute path to another._ | ||
| Parameters: `string` (the value to test against) | ||
| Default: `none` | ||
| Usage: | ||
| ``` html | ||
| [{{link.text}}]({{link.url}}) | ||
| ``` | ||
| Example: | ||
| ``` handlebars | ||
| <a href="{{relative "src" "dist"}}/assets/css/styles.css"></a> | ||
| ``` | ||
| Renders to: | ||
| ``` html | ||
| <a href="../../dist/assets/css/styles.css"></a> | ||
| ``` |
| <html> | ||
| <head> | ||
| <title>Defining sections from inside a page.</title> | ||
| </head> | ||
| <body> | ||
| <h1>Top of the page</h1> | ||
| <h2>Section before body</h2> | ||
| <p>Default before section content</p> | ||
| <div class="navbar navbar-fixed-top"> | ||
| <div class="navbar-inner"> | ||
| <div class="container"> | ||
| <ul class="nav"> | ||
| <li><a href="sections.html">Defining sections from inside a page.</a></li> | ||
| </ul> | ||
| <ul class="nav"><li><a href="http://github.com/assemble/">Visit Assemble</a></li></ul> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
| # README | ||
| ## {{chapter './examples/src/content/test.md'}} |
| --- | ||
| title: Include | ||
| --- | ||
| # {{title}} | ||
| {{include './examples/src/content/test.md'}} |
| <html> | ||
| <head> | ||
| <title>{{title}}</title> | ||
| </head> | ||
| <body> | ||
| <h1>Top of the page</h1> | ||
| <h2>Section before body</h2> | ||
| {{#override 'before'}} | ||
| <p>Default before section content</p> | ||
| {{/override}} | ||
| {{>body}} | ||
| {{#override 'after'}} | ||
| <p>Default after section content</p> | ||
| {{/override}} | ||
| </body> | ||
| </html> |
| --- | ||
| title: Defining sections from inside a page. | ||
| url: | ||
| repo: http://github.com/assemble/ | ||
| --- | ||
| {{#section 'before'}} | ||
| <h1>{{title}}</h1> | ||
| {{/section}} | ||
| <div class="navbar navbar-fixed-top"> | ||
| <div class="navbar-inner"> | ||
| <div class="container"> | ||
| <ul class="nav"> | ||
| {{#pages}}<li><a href="{{lowercase basename}}{{ext}}">{{data.title}}</a></li> | ||
| {{/pages}} | ||
| </ul> | ||
| <ul class="nav"><li><a href="{{url.repo}}">Visit Assemble</a></li></ul> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {{#section 'after'}} | ||
| {{#comment}} | ||
| NOTE: "pages", "filename" and "ext" are build-in variables that require | ||
| assemble. Also, "title" does not require Assemble, but "data.title" does | ||
| since it accesses the Assemble "data" object | ||
| {{/comment}} | ||
| {{/section}} |
+8
-0
@@ -0,1 +1,9 @@ | ||
| v0.1.30: | ||
| date: "2013-04-20" | ||
| changes: | ||
| - Refactoring helpers-collection module to separate the functions from the Handlebars helper registration process. | ||
| v0.1.25: | ||
| date: "2013-04-16" | ||
| changes: | ||
| - Adding defineSection and renderSection helpers to try to get sections populated in a layout from the page. | ||
| v0.1.21: | ||
@@ -2,0 +10,0 @@ date: "2013-04-07" |
@@ -0,0 +0,0 @@ |
@@ -11,5 +11,5 @@ | ||
| <p>Usage:</p> | ||
| <pre><code class="lang-html">[{{link.text}}]({{link.url}})</code></pre> | ||
| <pre><code class="lang-html">[]()</code></pre> | ||
| <p>Example:</p> | ||
| <pre><code class="lang-handlebars"><a href="{{relative "src" "dist"}}/assets/css/styles.css"></a></code></pre> | ||
| <pre><code class="lang-handlebars"><a href="../dist/assets/css/styles.css"></a></code></pre> | ||
| <p>Renders to: </p> | ||
@@ -25,5 +25,5 @@ <pre><code class="lang-html"><a href="../../dist/assets/css/styles.css"></a></code></pre> | ||
| <p>Usage:</p> | ||
| <pre><code class="lang-html">[{{link.text}}]({{link.url}})</code></pre> | ||
| <pre><code class="lang-html">[]()</code></pre> | ||
| <p>Example:</p> | ||
| <pre><code class="lang-handlebars"><a href="{{relative "src" "dist"}}/assets/css/styles.css"></a></code></pre> | ||
| <pre><code class="lang-handlebars"><a href="../dist/assets/css/styles.css"></a></code></pre> | ||
| <p>Renders to: </p> | ||
@@ -30,0 +30,0 @@ <pre><code class="lang-html"><a href="../../dist/assets/css/styles.css"></a></code></pre> |
@@ -14,2 +14,3 @@ | ||
| <li><a href="pages.html">Pages (Collection) Variables</a></li> | ||
| <li><a href="sections.html">Defining sections from inside a page.</a></li> | ||
@@ -16,0 +17,0 @@ </ul> |
@@ -6,14 +6,14 @@ | ||
| { | ||
| html: './examples/src/content/test.html', | ||
| md: './examples/src/content/test.md', | ||
| none: './examples/src/content/TEST', | ||
| yml: './examples/src/content/test.yml', | ||
| less: './examples/src/content/test.less', | ||
| hbs: './examples/src/content/test.hbs', | ||
| json: './examples/src/content/test.json', | ||
| css: './examples/src/content/test.css', | ||
| hbs: './examples/src/content/test.hbs', | ||
| html: './examples/src/content/test.html', | ||
| js: './examples/src/content/test.js', | ||
| json: './examples/src/content/test.json', | ||
| less: './examples/src/content/test.less', | ||
| md: './examples/src/content/test.md', | ||
| text: './examples/src/content/test.txt', | ||
| yml: './examples/src/content/test.yml' | ||
| text: './examples/src/content/test.txt' | ||
| } | ||
| ``` | ||
@@ -12,3 +12,4 @@ | ||
| ## Highlight text | ||
| <span class="highlight">something</span> | ||
| <span class="highlight">This is content</span> | ||
| <span class="alert-info">This is content</span> | ||
@@ -37,3 +38,3 @@ ## JSON | ||
| "description": "Extensive collection of Handlebars helpers.", | ||
| "version": "0.1.24", | ||
| "version": "0.1.3", | ||
| "homepage": "https://github.com/assemble/helper-lib", | ||
@@ -75,3 +76,2 @@ "author": { | ||
| "dependencies": { | ||
| "assemble": "https://github.com/assemble/assemble/tarball/master", | ||
| "chai": "~1.5.0", | ||
@@ -90,6 +90,4 @@ "globule": "~0.1.0", | ||
| }, | ||
| "peerDependencies": { | ||
| "assemble": "*" | ||
| }, | ||
| "devDependencies": { | ||
| "assemble": "https://github.com/assemble/assemble/tarball/master", | ||
| "grunt": "~0.4.1", | ||
@@ -96,0 +94,0 @@ "grunt-contrib-jshint": "~0.2.0", |
@@ -30,5 +30,5 @@ | ||
| <a href="../lib/assets/css/styles.css"></a> | ||
| <a href="Dropbox/Development/generate/assemble/helpers/lib/assets/css/styles.css"></a> | ||
| <a href="Work/assemble/helpers/lib/assets/css/styles.css"></a> | ||
| <a href="../../assets/css/styles.css"></a> | ||
| <a href="../../../../../../../assets/css/styles.css"></a> | ||
| <a href="../../../../../assets/css/styles.css"></a> | ||
@@ -35,0 +35,0 @@ |
@@ -8,4 +8,4 @@ | ||
| Project Version: v0.1.24 | ||
| Project Version: v0.1.3 | ||
| Project Name: helper-lib | ||
| Project Description: Extensive collection of Handlebars helpers. |
@@ -0,0 +0,0 @@ --- |
@@ -15,3 +15,4 @@ --- | ||
| ## Highlight text | ||
| {{highlight 'something'}} | ||
| {{highlight 'This is content'}} | ||
| {{highlight 'This is content' 'alert-info'}} | ||
@@ -18,0 +19,0 @@ ## JSON |
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| var Utils; | ||
| var Utils, after, any, arrayify, before, eachIndex, eachProperty, empty, first, inArray, join, last, length, lengthEqual, sort, withAfter, withBefore, withFirst, withLast, withSort; | ||
| Utils = require('../utils/utils'); | ||
| Handlebars.registerHelper('first', function(array, count) { | ||
| if (Utils.isUndefined(count)) { | ||
| return array[0]; | ||
| } else { | ||
| return array.slice(0, count); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('withFirst', function(array, count, options) { | ||
| var item, result; | ||
| Utils = require('../utils/utils'); | ||
| if (Utils.isUndefined(count)) { | ||
| options = count; | ||
| return options.fn(array[0]); | ||
| } else { | ||
| array = array.slice(0, count); | ||
| result = ''; | ||
| for (item in array) { | ||
| result += options.fn(array[item]); | ||
| } | ||
| return result; | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('last', function(array, count) { | ||
| if (Utils.isUndefined(count)) { | ||
| return array[array.length - 1]; | ||
| } else { | ||
| return array.slice(-count); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('withLast', function(array, count, options) { | ||
| var item, result; | ||
| module.exports.first = first = function(array, count) { | ||
| if (Utils.isUndefined(count)) { | ||
| return array[0]; | ||
| } else { | ||
| return array.slice(0, count); | ||
| } | ||
| }; | ||
| if (Utils.isUndefined(count)) { | ||
| options = count; | ||
| return options.fn(array[array.length - 1]); | ||
| } else { | ||
| array = array.slice(-count); | ||
| result = ''; | ||
| for (item in array) { | ||
| result += options.fn(array[item]); | ||
| } | ||
| return result; | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('after', function(array, count) { | ||
| return array.slice(count); | ||
| }); | ||
| Handlebars.registerHelper('withAfter', function(array, count, options) { | ||
| var item, result; | ||
| module.exports.withFirst = withFirst = function(array, count, options) { | ||
| var item, result; | ||
| array = array.slice(count); | ||
| if (Utils.isUndefined(count)) { | ||
| options = count; | ||
| return options.fn(array[0]); | ||
| } else { | ||
| array = array.slice(0, count); | ||
| result = ''; | ||
@@ -62,10 +27,21 @@ for (item in array) { | ||
| return result; | ||
| }); | ||
| Handlebars.registerHelper('before', function(array, count) { | ||
| return array.slice(0, -count); | ||
| }); | ||
| Handlebars.registerHelper('withBefore', function(array, count, options) { | ||
| var item, result; | ||
| } | ||
| }; | ||
| array = array.slice(0, -count); | ||
| module.exports.last = last = function(array, count) { | ||
| if (Utils.isUndefined(count)) { | ||
| return array[array.length - 1]; | ||
| } else { | ||
| return array.slice(-count); | ||
| } | ||
| }; | ||
| module.exports.withLast = withLast = function(array, count, options) { | ||
| var item, result; | ||
| if (Utils.isUndefined(count)) { | ||
| options = count; | ||
| return options.fn(array[array.length - 1]); | ||
| } else { | ||
| array = array.slice(-count); | ||
| result = ''; | ||
@@ -76,117 +52,171 @@ for (item in array) { | ||
| return result; | ||
| }); | ||
| Handlebars.registerHelper('join', function(array, separator) { | ||
| return array.join(Utils.isUndefined(separator) ? ' ' : separator); | ||
| }); | ||
| Handlebars.registerHelper('sort', function(array, field) { | ||
| if (Utils.isUndefined(field)) { | ||
| return array.sort(); | ||
| } else { | ||
| return array.sort(function(a, b) { | ||
| return a[field] > b[field]; | ||
| }); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('withSort', function(array, field, options) { | ||
| var item, result, _i, _len; | ||
| } | ||
| }; | ||
| result = ''; | ||
| if (Utils.isUndefined(field)) { | ||
| options = field; | ||
| array = array.sort(); | ||
| for (_i = 0, _len = array.length; _i < _len; _i++) { | ||
| item = array[_i]; | ||
| result += options.fn(item); | ||
| } | ||
| } else { | ||
| array = array.sort(function(a, b) { | ||
| return a[field] > b[field]; | ||
| }); | ||
| for (item in array) { | ||
| result += options.fn(array[item]); | ||
| } | ||
| } | ||
| return result; | ||
| }); | ||
| Handlebars.registerHelper('length', function(array) { | ||
| return array.length; | ||
| }); | ||
| Handlebars.registerHelper('lengthEqual', function(array, length, options) { | ||
| if (array.length === length) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('empty', function(array, options) { | ||
| if (array.length <= 0) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('any', function(array, options) { | ||
| if (array.length > 0) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }); | ||
| Handlebars.registerHelper('inArray', function(array, value, options) { | ||
| if (array.indexOf(value) !== -1) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }); | ||
| /* | ||
| Similar to #each helper, but treats array-like objects as arrays | ||
| (i.e. objects with a `.length` property which is a number) | ||
| rather than objects. This lets us iterate over our Collection's. | ||
| */ | ||
| module.exports.after = after = function(array, count) { | ||
| return array.slice(count); | ||
| }; | ||
| Handlebars.registerHelper("eachIndex", function(context, options) { | ||
| var data, i, j, ret; | ||
| module.exports.withAfter = withAfter = function(array, count, options) { | ||
| var item, result; | ||
| ret = ""; | ||
| if (options.data != null) { | ||
| data = Handlebars.createFrame(options.data); | ||
| array = array.slice(count); | ||
| result = ''; | ||
| for (item in array) { | ||
| result += options.fn(array[item]); | ||
| } | ||
| return result; | ||
| }; | ||
| module.exports.before = before = function(array, count) { | ||
| return array.slice(0, -count); | ||
| }; | ||
| module.exports.withBefore = withBefore = function(array, count, options) { | ||
| var item, result; | ||
| array = array.slice(0, -count); | ||
| result = ''; | ||
| for (item in array) { | ||
| result += options.fn(array[item]); | ||
| } | ||
| return result; | ||
| }; | ||
| module.exports.join = join = function(array, separator) { | ||
| return array.join(Utils.isUndefined(separator) ? ' ' : separator); | ||
| }; | ||
| module.exports.sort = sort = function(array, field) { | ||
| if (Utils.isUndefined(field)) { | ||
| return array.sort(); | ||
| } else { | ||
| return array.sort(function(a, b) { | ||
| return a[field] > b[field]; | ||
| }); | ||
| } | ||
| }; | ||
| module.exports.withSort = withSort = function(array, field, options) { | ||
| var item, result, _i, _len; | ||
| result = ''; | ||
| if (Utils.isUndefined(field)) { | ||
| options = field; | ||
| array = array.sort(); | ||
| for (_i = 0, _len = array.length; _i < _len; _i++) { | ||
| item = array[_i]; | ||
| result += options.fn(item); | ||
| } | ||
| if (context && context.length > 0) { | ||
| i = 0; | ||
| j = context.length; | ||
| while (i < j) { | ||
| if (data) { | ||
| data.index = i; | ||
| } | ||
| context[i].index = i; | ||
| ret = ret + options.fn(context[i]); | ||
| i++; | ||
| } | ||
| } else { | ||
| ret = options.inverse(this); | ||
| } else { | ||
| array = array.sort(function(a, b) { | ||
| return a[field] > b[field]; | ||
| }); | ||
| for (item in array) { | ||
| result += options.fn(array[item]); | ||
| } | ||
| return ret; | ||
| }); | ||
| Handlebars.registerHelper("eachProperty", function(obj, options) { | ||
| var key, result, value; | ||
| } | ||
| return result; | ||
| }; | ||
| result = ""; | ||
| for (key in obj) { | ||
| value = obj[key]; | ||
| result += options.fn({ | ||
| key: key, | ||
| value: value | ||
| }); | ||
| } | ||
| return result; | ||
| }); | ||
| Handlebars.registerHelper("arrayify", function(data) { | ||
| var result; | ||
| module.exports.length = length = function(array) { | ||
| return array.length; | ||
| }; | ||
| result = data.split(",").map(function(tag) { | ||
| return "\"" + tag + "\""; | ||
| module.exports.lengthEqual = lengthEqual = function(array, length, options) { | ||
| if (array.length === length) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }; | ||
| module.exports.empty = empty = function(array, options) { | ||
| if (array.length <= 0) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }; | ||
| module.exports.any = any = function(array, options) { | ||
| if (array.length > 0) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }; | ||
| module.exports.inArray = inArray = function(array, value, options) { | ||
| if (array.indexOf(value) !== -1) { | ||
| return options.fn(this); | ||
| } else { | ||
| return options.inverse(this); | ||
| } | ||
| }; | ||
| /* | ||
| Similar to #each helper, but treats array-like objects as arrays | ||
| (i.e. objects with a `.length` property which is a number) | ||
| rather than objects. This lets us iterate over our Collection's. | ||
| */ | ||
| module.exports.eachIndex = eachIndex = function(array, options) { | ||
| var index, result, value, _i, _len; | ||
| result = ''; | ||
| for (index = _i = 0, _len = array.length; _i < _len; index = ++_i) { | ||
| value = array[index]; | ||
| result += options.fn({ | ||
| item: value, | ||
| index: index | ||
| }); | ||
| return result; | ||
| } | ||
| return result; | ||
| }; | ||
| module.exports.eachProperty = eachProperty = function(obj, options) { | ||
| var key, result, value; | ||
| result = ''; | ||
| for (key in obj) { | ||
| value = obj[key]; | ||
| result += options.fn({ | ||
| key: key, | ||
| value: value | ||
| }); | ||
| } | ||
| return result; | ||
| }; | ||
| module.exports.arrayify = arrayify = function(data) { | ||
| var result; | ||
| result = data.split(",").map(function(tag) { | ||
| return "\"" + tag + "\""; | ||
| }); | ||
| return result; | ||
| }; | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper('first', first); | ||
| Handlebars.registerHelper('withFirst', withFirst); | ||
| Handlebars.registerHelper('last', last); | ||
| Handlebars.registerHelper('withLast', withLast); | ||
| Handlebars.registerHelper('after', after); | ||
| Handlebars.registerHelper('withAfter', withAfter); | ||
| Handlebars.registerHelper('before', before); | ||
| Handlebars.registerHelper('withBefore', withBefore); | ||
| Handlebars.registerHelper('join', join); | ||
| Handlebars.registerHelper('sort', sort); | ||
| Handlebars.registerHelper('withSort', withSort); | ||
| Handlebars.registerHelper('length', length); | ||
| Handlebars.registerHelper('lengthEqual', lengthEqual); | ||
| Handlebars.registerHelper('empty', empty); | ||
| Handlebars.registerHelper('any', any); | ||
| Handlebars.registerHelper('inArray', inArray); | ||
| Handlebars.registerHelper('eachIndex', eachIndex); | ||
| Handlebars.registerHelper('eachProperty', eachProperty); | ||
| Handlebars.registerHelper("arrayify", arrayify); | ||
| return this; | ||
@@ -193,0 +223,0 @@ }; |
@@ -8,44 +8,17 @@ (function() { | ||
| /* | ||
| <!DOCTYPE> | ||
| Same as the `ul` helper but creates and ordered list. | ||
| 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'}} | ||
| */ | ||
| Handlebars.registerHelper("DOCTYPE", function(type) { | ||
| type = type.toLowerCase(); | ||
| switch (type) { | ||
| case "5": | ||
| case "html": | ||
| case "html5": | ||
| return Utils.safeString('<!DOCTYPE1 html>'); | ||
| case "xml": | ||
| return Utils.safeString('<?xml version="1.0" encoding="utf-8" ?>'); | ||
| case "strict": | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'); | ||
| case "transitional": | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'); | ||
| case "frameset": | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'); | ||
| case "1.1": | ||
| case "xhtml 1.1": | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'); | ||
| case "basic": | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">'); | ||
| case "mobile": | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'); | ||
| case "4.01 strict": | ||
| return Utils.safeString('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'); | ||
| case "4.01 trans": | ||
| return Utils.safeString('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'); | ||
| case "4.01 frameset": | ||
| return Utils.safeString('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'); | ||
| case "svg 1.1": | ||
| case "svg1.1": | ||
| return Utils.safeString('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'); | ||
| case "svg 1.0": | ||
| case "svg1.0": | ||
| case "svg1": | ||
| return Utils.safeString('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">'); | ||
| default: | ||
| return Utils.safeString('<!DOCTYPE html>'); | ||
| Handlebars.registerHelper("link", function(url, text, linkClass) { | ||
| var result; | ||
| 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); | ||
| }); | ||
@@ -71,2 +44,7 @@ /* | ||
| }); | ||
| /* | ||
| Break helper: Add the specified number of br tags | ||
| Usage: {{br 5}} | ||
| */ | ||
| Handlebars.registerHelper('br', function(count, options) { | ||
@@ -96,30 +74,49 @@ var br, i; | ||
| }); | ||
| Handlebars.registerHelper('newLineToBr', function(str) { | ||
| return str.replace(/\r?\n|\r/g, '<br>'); | ||
| }); | ||
| /* | ||
| link helper function. | ||
| 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'}} | ||
| <!DOCTYPE> | ||
| Same as the `ul` helper but creates and ordered list. | ||
| */ | ||
| Handlebars.registerHelper("link", function(url, text, linkClass) { | ||
| var result; | ||
| url = Handlebars.Utils.escapeExpression(url); | ||
| text = Handlebars.Utils.escapeExpression(text); | ||
| if (Utils.isUndefined(linkClass)) { | ||
| linkClass = ""; | ||
| Handlebars.registerHelper("DOCTYPE", function(type) { | ||
| type = type.toLowerCase(); | ||
| switch (type) { | ||
| case "5": | ||
| case "html": | ||
| case "html5": | ||
| return Utils.safeString('<!DOCTYPE1 html>'); | ||
| case "xml": | ||
| return Utils.safeString('<?xml version="1.0" encoding="utf-8" ?>'); | ||
| case "strict": | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'); | ||
| case "transitional": | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'); | ||
| case "frameset": | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'); | ||
| case "1.1": | ||
| case "xhtml 1.1": | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'); | ||
| case "basic": | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">'); | ||
| case "mobile": | ||
| return Utils.safeString('<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'); | ||
| case "4.01 strict": | ||
| return Utils.safeString('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'); | ||
| case "4.01 trans": | ||
| return Utils.safeString('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'); | ||
| case "4.01 frameset": | ||
| return Utils.safeString('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'); | ||
| case "svg 1.1": | ||
| case "svg1.1": | ||
| return Utils.safeString('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'); | ||
| case "svg 1.0": | ||
| case "svg1.0": | ||
| case "svg1": | ||
| return Utils.safeString('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">'); | ||
| default: | ||
| return Utils.safeString('<!DOCTYPE html>'); | ||
| } | ||
| result = '<a class="' + linkClass + '" href="' + url + '" title="' + text + '">' + text + '</a>'; | ||
| return Utils.safeString(result); | ||
| }); | ||
| Handlebars.registerHelper("highlight", function(value, options) { | ||
| var escaped; | ||
| escaped = Handlebars.Utils.escapeExpression(value); | ||
| return Utils.safeString("<span class=\"highlight\">" + escaped + "</span>"); | ||
| }); | ||
| Handlebars.registerHelper("icon", function(attachment) { | ||
@@ -126,0 +123,0 @@ var extension, value; |
@@ -57,3 +57,3 @@ (function() { | ||
| } | ||
| matches = authors.replace(/(.*?)\s*\((.*)\)/g, '[$1]' + '($2)') || []; | ||
| matches = authors.replace(/(.*?)\s*\((.*)\)/g, '* [$1]' + '($2) ') || []; | ||
| return Utils.safeString(matches); | ||
@@ -81,8 +81,27 @@ }); | ||
| /* | ||
| Section: 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: {{ section [file] }} | ||
| 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. | ||
| Syntax: {{roadmap [src]}} | ||
| */ | ||
| Handlebars.registerHelper('section', function(file) { | ||
| Handlebars.registerHelper("roadmap", function(roadmap) { | ||
| var source, template; | ||
| if (Utils.isUndefined(roadmap)) { | ||
| roadmap = Utils.readYAML('./ROADMAP'); | ||
| } else { | ||
| roadmap = Utils.readYAML(roadmap); | ||
| } | ||
| source = "{{#each .}}* {{eta}} {{{@key}}} {{#each goals}}{{{.}}}{{/each}}\n{{/each}}"; | ||
| template = Handlebars.compile(source); | ||
| return Utils.safeString(template(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; | ||
@@ -109,2 +128,20 @@ | ||
| /* | ||
| 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 result; | ||
| file = Utils.read(file); | ||
| if (Utils.isUndefined(language)) { | ||
| language = ""; | ||
| } | ||
| result = '``` ' + language + '\n' + file + '\n```'; | ||
| return Utils.safeString(result); | ||
| }); | ||
| /* | ||
| Markdown: Markdown helper used to write markdown inside and | ||
@@ -130,6 +167,9 @@ rendered the markdown inline with the HTML | ||
| Handlebars.registerHelper("md", function(path) { | ||
| var content; | ||
| var content, html, md, tmpl; | ||
| content = markdown.read(path); | ||
| return Utils.safeString(content); | ||
| content = Utils.read(path); | ||
| tmpl = Handlebars.compile(content); | ||
| md = tmpl(this); | ||
| html = markdown.convert(md); | ||
| return Utils.safeString(html); | ||
| }); | ||
@@ -136,0 +176,0 @@ } |
| (function() { | ||
| module.exports.register = function(Handlebars, options) { | ||
| Handlebars.registerHelper("safeString", function(value) { | ||
| return Utils.safeString(value); | ||
| }); | ||
| Handlebars.registerHelper('default', function(value, defaultValue) { | ||
@@ -7,0 +4,0 @@ return value != null ? value : defaultValue; |
@@ -9,4 +9,5 @@ (function() { | ||
| WARNING!!! WARNING!!! WARNING!!! | ||
| These are not stable, do not use them | ||
| in production yet!!! | ||
| These are not correct orstable, feel free to test | ||
| or submit pull requests for fixes, but do not | ||
| use them in projects yet!!! | ||
| */ | ||
@@ -13,0 +14,0 @@ |
@@ -9,2 +9,37 @@ (function() { | ||
| /* | ||
| Include: Include content from an external source. | ||
| Usage: {{ include [file] }} | ||
| */ | ||
| Handlebars.registerHelper('include', function(file) { | ||
| file = Utils.read(file); | ||
| return Utils.safeString(file); | ||
| }); | ||
| /* | ||
| "section": block helper. | ||
| Usage: {{#section [file] }} | ||
| */ | ||
| Handlebars.registerHelper('section', function(section, options) { | ||
| if (Handlebars.sections) { | ||
| Handlebars.sections[section] = options.fn(this); | ||
| } | ||
| return Utils.safeString(''); | ||
| }); | ||
| /* | ||
| "override" block helper. | ||
| Usage: {{#override [file] }} | ||
| */ | ||
| Handlebars.registerHelper('override', function(section, options) { | ||
| var content; | ||
| 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 | ||
@@ -40,17 +75,13 @@ Usage: {{ jsfiddle [id] [tabs] }} | ||
| /* | ||
| Embed: Embeds code from an external file as preformatted text. The first parameter | ||
| requires a path to the file you want to embed. There is a second optional | ||
| parameter to specify (force) syntax highlighting for a specific language. | ||
| Syntax: {{ embed [file] [lang] }} | ||
| Usage: {{ embed 'src/examples/Gruntfile.js' 'javascript' }} | ||
| Highlight: wraps the output in a span with the class "highlight". | ||
| Usage: {{highlight 'value' 'class'}} | ||
| */ | ||
| Handlebars.registerHelper('embed', function(file, language) { | ||
| Handlebars.registerHelper('highlight', function(text, modifier) { | ||
| var result; | ||
| file = Utils.read(file); | ||
| if (Utils.isUndefined(language)) { | ||
| language = ""; | ||
| if (Utils.isUndefined(modifier)) { | ||
| modifier = "highlight"; | ||
| } | ||
| result = '``` ' + language + '\n' + file + '\n```'; | ||
| result = '<span class="' + modifier + '">' + text + '</span>'; | ||
| return Utils.safeString(result); | ||
@@ -57,0 +88,0 @@ }); |
@@ -6,2 +6,5 @@ (function() { | ||
| Utils = require('../utils/utils'); | ||
| Handlebars.registerHelper("safeString", function(value) { | ||
| return Utils.safeString(value); | ||
| }); | ||
| Handlebars.registerHelper('lowercase', function(str) { | ||
@@ -69,5 +72,2 @@ return str.toLowerCase(); | ||
| }); | ||
| Handlebars.registerHelper('newLineToBr', function(str) { | ||
| return str.replace(/\r?\n|\r/g, '<br>'); | ||
| }); | ||
| Handlebars.registerHelper("hyphenate", function(tag) { | ||
@@ -74,0 +74,0 @@ return tag.split(" ").join("-"); |
+12
-12
| { | ||
| "name": "helper-lib", | ||
| "description": "Extensive collection of Handlebars helpers.", | ||
| "version": "0.1.24", | ||
| "version": "0.1.30", | ||
| "homepage": "https://github.com/assemble/helper-lib", | ||
@@ -41,5 +41,8 @@ "author": { | ||
| "dependencies": { | ||
| "assemble": "https://github.com/assemble/assemble/tarball/master", | ||
| "grunt": "~0.4.1", | ||
| "chai": "~1.5.0", | ||
| "globule": "~0.1.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", | ||
@@ -49,16 +52,13 @@ "js-yaml": "~2.0.4", | ||
| "marked": "~0.2.8", | ||
| "mime": "latest" | ||
| "mime": "latest", | ||
| "should": "~1.2.2" | ||
| }, | ||
| "devDependencies": { | ||
| "amdefine": "0.0.4", | ||
| "chai": "~1.5.0", | ||
| "grunt-contrib-clean": "~0.4.0", | ||
| "grunt-contrib-coffee": "~0.6.4", | ||
| "grunt-contrib-copy": "~0.4.2", | ||
| "assemble": "https://github.com/assemble/assemble/tarball/master", | ||
| "grunt": "~0.4.1", | ||
| "grunt-contrib-jshint": "~0.2.0", | ||
| "grunt-contrib-copy": "latest", | ||
| "grunt-contrib-nodeunit": "~0.1.2", | ||
| "grunt-contrib-uglify": "~0.2.0", | ||
| "grunt-mocha-test": "~0.2.0", | ||
| "handlebars": "~1.0.10", | ||
| "should": "~1.2.2" | ||
| "amdefine": "0.0.4" | ||
| }, | ||
@@ -65,0 +65,0 @@ "keywords": [ |
+2
-2
@@ -1,2 +0,2 @@ | ||
| # [Helper Library v0.1.24](http://github.com/assemble/helper-lib) [](https://travis-ci.org/assemble/helper-lib) | ||
| # [Helper Library v0.1.30](http://github.com/assemble/helper-lib) [](https://travis-ci.org/assemble/helper-lib) | ||
@@ -1598,3 +1598,3 @@ > Extensive collection of Handlebars helpers. | ||
| _This file was generated using Grunt and [assemble](http://github.com/assemble/assemble) on Tue Apr 16 2013 06:14:34._ | ||
| _This file was generated using Grunt and [assemble](http://github.com/assemble/assemble) on Sat Apr 20 2013 15:06:54._ | ||
@@ -1601,0 +1601,0 @@ |
| # README | ||
| ## relative | ||
| _Derive the relative path from one absolute path to another._ | ||
| Parameters: `string` (the value to test against) | ||
| Default: `none` | ||
| Usage: | ||
| ``` html | ||
| [{{link.text}}]({{link.url}}) | ||
| ``` | ||
| Example: | ||
| ``` handlebars | ||
| <a href="{{relative "src" "dist"}}/assets/css/styles.css"></a> | ||
| ``` | ||
| Renders to: | ||
| ``` html | ||
| <a href="../../dist/assets/css/styles.css"></a> | ||
| ``` |
| # README | ||
| ## {{section './examples/src/content/test.md'}} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
115595
5.22%7
-36.36%83
7.79%1536
4.77%0
-100%12
50%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed