Permalink
Browse files

add more comments to helpers file

  • Loading branch information...
1 parent 53a3747 commit b66c4b290043ac156b1708ca8ca1cc7164fabcf3 @jonschlinkert jonschlinkert committed Mar 21, 2013
Showing with 91 additions and 21 deletions.
  1. +83 −19 lib/engines/handlebars/helpers/defaultHelpers.js
  2. +8 −2 lib/utils/index.js
@@ -1,3 +1,11 @@
+/*
+ * helper-lib
+ * https://github.com/assemble/helper-lib
+ *
+ * Copyright (c) 2013 Assemble, Brian Woodward, contributors.
+ * Licensed under the MIT license.
+ */
+
if(!define || typeof define !== 'function') {
var define = require('amdefine')(module);
@@ -754,6 +762,24 @@ define([], function() {
});
/**
+ * Relative path
+ * Returns the derived relative path from one to the other.
+ */
+ Handlebars.registerHelper('relativeFrom', function(from, to) {
+
+ var relativePath = path.relative(from, to);
+
+ if(relativePath === "." || relativePath.length === 0) {
+ relativePath = dest;
+ }
+ relativePath = Utils.urlNormalize(path.relative(
+ path.resolve(path.join(dest, relative)),
+ path.resolve(relativePath)
+ ));
+ return relativePath;
+ });
+
+ /**
* Add
* Returns the sum of two numbers.
*/
@@ -1137,31 +1163,27 @@ define([], function() {
*
* Usage:
*
+ * // Data
* collection = [
- * name: 'Leela'
- * deliveries: 8021
- * ,
- * name: 'Bender'
- * deliveries: 239
- * ,
- * name: 'Fry'
- * deliveries: 1
- * * ]
+ * name: 'Leela'
+ * deliveries: 8021,
+ * name: 'Bender'
+ * deliveries: 239,
+ * name: 'Fry'
+ * deliveries: 1
+ * ]
*
+ * // Template
* {{#ul collection class="deliveries-list"}}
* {{name}} - {{inflect deliveries "delivery" "deliveries" true}}
* {{/ul}}
*
+ *
+ * // Result:
* <ul class="deliveries-list">
- * <li>
- * Leela - 8021 deliveries
- * </li>
- * <li>
- * Bender - 239 deliveries
- * </li>
- * <li>
- * Fry - 1 delivery
- * </li>
+ * <li> Leela - 8021 deliveries </li>
+ * <li> Bender - 239 deliveries </li>
+ * <li> Fry - 1 delivery </li>
* </ul>
*/
Handlebars.registerHelper('ul', function(context, options) {
@@ -1170,6 +1192,7 @@ define([], function() {
}).join('\n') + "</ul>";
});
+
/**
* <ol>
* Same as the `ul` helper but creates and ordered list.
@@ -1180,6 +1203,47 @@ define([], function() {
}).join('\n') + "</ol>";
});
+
+ /**
+ * Gist
+ *
+ * Embed public GitHub Gists by adding only the Id of the Gist. The helper also accepts an optional second parameter for targeting a specific file on the Gist.
+ * filename
+ * Usage:
+ *
+ * {{ gist [id] }}
+ *
+ */
+ Handlebars.registerHelper('gist', function(id) {
+ id = Handlebars.Utils.escapeExpression(id);
+ var result = '<script src="https://gist.github.com/' + id + '.js"></script>';
+ return new Handlebars.SafeString(result);
+ });
+
+ /**
+ * 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'}}
+ *
+ */
+ Handlebars.registerHelper('link', function(url, text) {
+ url = Handlebars.Utils.escapeExpression(url);
+ text = Handlebars.Utils.escapeExpression(text);
+ var result = '<a class="" href="' + url + '" title="' + text + '">' + text + '</a>';
+ return new Handlebars.SafeString(result);
+ });
+
+ // Handlebars.registerHelper('ul', function(context, options) {
+ // return ("<ul " + (HTML.parseAttributes(options.hash)) + ">") + context.map(function(item) {
+ // return "<li>" + (options.fn(item)) + "</li>";
+ // }).join('\n') + "</ul>";
+ // });
+
/**
* <br>
* Returns `<br>` tags based on a count.
@@ -1225,7 +1289,7 @@ define([], function() {
/**
* Inline Partials
- * Loop through an objects properties
+ * Loop through an object's properties
* Usage:
*
* {{{include "scripts"}}}
View
@@ -11,10 +11,16 @@
(function(exports) {
- exports.FrontMatter = require('./frontMatter').FrontMatter;
- exports.Markdown = require('./markdown').Markdown;
+ // YAML Front Matter
+ exports.FrontMatter = require('./frontMatter').FrontMatter;
+
+ // Markdown
+ exports.Markdown = require('./markdown').Markdown;
+
+ // Template Engines
exports.EngineLoader = require('./engineLoader').EngineLoader;
+ // Extensions Map
exports.ExtensionMap = require('../config/extensionMap');
}(typeof exports === 'object' && exports || this));

0 comments on commit b66c4b2

Please sign in to comment.