You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

helper-lib

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

helper-lib - npm Package Compare versions

Comparing version
0.1.2
to
0.1.3
+9
.gitattributes
# Set default behaviour, in case users don't have core.autocrlf set.
* text=lf
* text eol=lf
*.* eol=lf
*.jpg binary
*.gif binary
*.png binary
*.jpeg binary
language: node_js
node_js:
- "0.8"
before_script:
- npm install -g grunt-cli
- npm install grunt
Brian Woodward (http://github.com/doowb)
Jon Schlinkert (http://github.com/jonschlinkert)
# Embed Helper
```
title: Fodder
description: different file formats for testing helpers
```
``` css
.alert {
padding: 8px 35px 8px 14px;
margin-bottom: 20px;
color: #c09853;
background-color: #fcf8e3;
border: 1px solid #fbeed5;
border-radius: 4px;
}
.alert h4 {
margin-top: 0;
color: inherit;
}
.alert hr {
border-top-color: #f8e5be;
}
.alert > a,
.alert > p > a {
font-weight: 500;
color: #a47e3c;
}
```
``` hbs
---
title: Fodder
description: different file formats for testing helpers
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ title }}</title>
</head>
<body>
<h1>{{ title }}</h1>
<p>{{ description }}</p>
</body>
</html>
```
``` html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fodder</title>
</head>
<body>
<h1>Fodder</h1>
<p>different file formats for testing helpers</p>
</body>
</html>
```
``` javascript
// Assemble Engine Loader
var EngineLoader = options.EngineLoader = assemble.EngineLoader(options);
var engine = null;
EngineLoader.getEngine(function(err, results) {
if(err) {
console.log(err);
return;
}
engine = options.engine = results;
});
```
``` json
{"title": "Fodder",
"description": "different file formats for testing helpers"}
```
``` less
.alert {
padding: 8px 35px 8px 14px;
margin-bottom: @line-height-base;
color: @state-warning-text;
background-color: @state-warning-background;
border: 1px solid @state-warning-border;
border-radius: @border-radius-base;
// Headings for larger alerts
h4 {
margin-top: 0;
// Specified for the h4 to prevent conflicts of changing @headingsColor
color: inherit;
}
// Match the hr to the border of the alert
hr {
border-top-color: darken(@state-warning-border, 5%);
}
// Inherit color for immediate links and bolden them some
> a,
> p > a {
font-weight: 500;
color: darken(@state-warning-text, 10%);
}
}
```
``` txt
title: Fodder
description: different file formats for testing helpers
```
``` yml
title: Fodder
description: different file formats for testing helpers
```
<h1>Extension Helper</h1>
Exension: html
<h1>Gist Helper</h1>
<script src="https://gist.github.com/5102394.js"></script>
<h2><pre>link</pre> Helper</h2>
<a class="" href="http://github.com" title="GitHub">GitHub</a>
<a class="nav-link" href="http://github.com" title="GitHub">GitHub</a>
<ul class="nav"><li>
one
</li>
<li>
two
</li>
<li>
three
</li></ul>
<ul class="nav"><li>
<a href="one">two</a>
</li>
<li>
<a href="three">four</a>
</li>
<li>
<a href="five">size</a>
</li></ul>
<img src="img/img-icon.png"><span>test.png</span>
<img src="img/pdf-icon.png"><span>test.pdf</span>
<img src="img/word-icon.png"><span>test.doc</span>
<img src="img/txt-icon.png"><span>test.txt</span>
<img src="img/other-icon.png"><span>test</span>
<h1>Markdown Helpers: Includes and Blocks</h1>
<h2>Markdown "Include": Escaped</h2>
<h4>relative</h4>
<p><em>Derive the relative path from one absolute path to another.</em></p>
<p>Parameters: <code>string</code> (the value to test against)
Default: <code>none</code></p>
<p>Usage:</p>
<pre><code class="lang-html">[]()</code></pre>
<p>Example:</p>
<pre><code class="lang-handlebars">&lt;a href=&quot;../dist/assets/css/styles.css&quot;&gt;&lt;/a&gt;</code></pre>
<p>Renders to: </p>
<pre><code class="lang-html">&lt;a href=&quot;../../dist/assets/css/styles.css&quot;&gt;&lt;/a&gt;</code></pre>
<h2>Markdown "Include": Un-escaped</h2>
<h4>relative</h4>
<p><em>Derive the relative path from one absolute path to another.</em></p>
<p>Parameters: <code>string</code> (the value to test against)
Default: <code>none</code></p>
<p>Usage:</p>
<pre><code class="lang-html">[]()</code></pre>
<p>Example:</p>
<pre><code class="lang-handlebars">&lt;a href=&quot;../dist/assets/css/styles.css&quot;&gt;&lt;/a&gt;</code></pre>
<p>Renders to: </p>
<pre><code class="lang-html">&lt;a href=&quot;../../dist/assets/css/styles.css&quot;&gt;&lt;/a&gt;</code></pre>
<h2>Markdown Block</h2>
<h1>h1 Heading</h1>
<h2>h2 Heading</h2>
<h3>h3 Heading</h3>
<h4>h4 Heading</h4>
<h5>h5 Heading</h5>
<h6>h6 Heading</h6>
<h2>relative</h2>
<p><em>Derive the relative path from one absolute path to another.</em></p>
<p>Parameters: <code>string</code> (the value to test against)
Default: <code>none</code></p>
<p>Usage:</p>
<pre><code class="lang-html">[]()</code></pre>
<p>Example:</p>
<pre><code class="lang-handlebars">&lt;a href=&quot;../dist/assets/css/styles.css&quot;&gt;&lt;/a&gt;</code></pre>
<p>Renders to: </p>
<pre><code class="lang-html">&lt;a href=&quot;../../dist/assets/css/styles.css&quot;&gt;&lt;/a&gt;</code></pre>
<h1>Pages (Collection) Variables</h1>
<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>
<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>
```
<div class="page-header">
<h1>Associative arrays</h1>
</div>
<div class="examples">
<h4>Associative arrays</h4>
<dl class="dl-horizontal">
<dt>Name:</dt> <dd>John Smith</dd>
<dt>Age:</dt> <dd>33</dd>
<dt>Name:</dt> <dd>Grace Jones</dd>
<dt>Age:</dt> <dd>21</dd>
</dl>
</div>
---
title: Embed Helper
lang:
none: <%= content %>/TEST
css: <%= content %>/test.css
hbs: <%= content %>/test.hbs
html: <%= content %>/test.html
js: <%= content %>/test.js
json: <%= content %>/test.json
less: <%= content %>/test.less
md: <%= content %>/test.md
text: <%= content %>/test.txt
yml: <%= content %>/test.yml
---
# {{ title }}
{{embed lang.none}}
{{embed lang.css 'css'}}
{{embed lang.hbs 'hbs'}}
{{embed lang.html 'html'}}
{{embed lang.js 'javascript'}}
{{embed lang.json 'json'}}
{{embed lang.less 'less'}}
{{!embed lang.md 'md'}} {{! currently does not work on markdown. fences need to be escaped }}
{{embed lang.text 'txt'}}
{{embed lang.yml 'yml'}}
# File Helpers
Copy from "A to B": true
# 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>
```
# Inspect Helper
``` json
{
text: './examples/src/content/test.txt',
less: './examples/src/content/test.less',
none: './examples/src/content/TEST',
hbs: './examples/src/content/test.hbs',
js: './examples/src/content/test.js',
json: './examples/src/content/test.json',
css: './examples/src/content/test.css',
md: './examples/src/content/test.md',
yml: './examples/src/content/test.yml',
html: './examples/src/content/test.html'
}
```
# `jsFiddle Helper` helper
Easily embed a jsfiddle in a page with: `{{ jsfiddle [id] }}`
<iframe width="100%" height="300" src="http://jsfiddle.net/VfSv9/embedded/result,js,html,css/presentation/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
<iframe width="100%" height="300" src="http://jsfiddle.net/VfSv9/embedded/css,html/presentation/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
# Miscellaneous Helpers
## Icons
<img src="img/img-icon.png"><span>test.png</span>
<img src="img/pdf-icon.png"><span>test.pdf</span>
<img src="img/word-icon.png"><span>test.doc</span>
<img src="img/txt-icon.png"><span>test.txt</span>
<img src="img/csv-icon.png"><span>test.csv</span>
## Highlight text
<span class="highlight">This is content</span>
<span class="alert-info">This is content</span>
## JSON
#### `property`
**Name**
{
"name": "helper-lib"
}
#### `value`
**Name**
helper-lib
#### `stringify`
**package.json**
{
"name": "helper-lib",
"description": "Extensive collection of Handlebars helpers.",
"version": "0.1.3",
"homepage": "https://github.com/assemble/helper-lib",
"author": {
"name": "assemble",
"url": "https://github.com/assemble/assemble"
},
"contributors": [
{
"name": "Brian Woodward",
"url": "https://github.com/doowb"
},
{
"name": "Jon Schlinkert",
"url": "https://github.com/jonschlinkert"
}
],
"repository": {
"type": "git",
"url": "git://github.com/assemble/helper-lib"
},
"bugs": {
"url": "git://github.com/assemble/helper-lib/isues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/assemble/helper-lib/blob/master/LICENSE-MIT"
}
],
"main": "index.js",
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "grunt test"
},
"dependencies": {
"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",
"js-yaml": "~2.0.4",
"lodash": "~1.1.1",
"marked": "~0.2.8",
"mime": "latest",
"should": "~1.2.2"
},
"devDependencies": {
"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",
"handlebars": "~1.0.10",
"amdefine": "0.0.4"
},
"keywords": [
"assemble",
"block helper",
"client-side templates",
"example helper",
"handle bars js",
"handlebar helper",
"handlebars block helper",
"handlebars custom helpers",
"handlebars escape",
"handlebars for loop",
"handlebars helper",
"handlebars helpers",
"handlebars if helper",
"handlebars list",
"handlebars loop index",
"handlebars loop",
"handlebars register helper",
"handlebars view helper",
"handlebars",
"helper library",
"helper",
"helpers",
"javascript templates",
"jst",
"loop handlebars",
"mustache or handlebars",
"mustaches template",
"mustaches templates",
"site builder",
"template helpers",
"templates",
"use handlebars",
"utilities"
]
}
# Path Helpers
## `basename`
Basename: toc
## `filename`
File name: toc.md
## `extname`
File name: md
## relative
One: ../changelog.md
Two: ../../impl/bbb
Three: ../docs/toc.md
Four: lib
Five: ../..
Five: ../../js-yaml
Six: ../../lib
Seven: ../../js-yaml
Eight: js-yaml/bin
Nine: ../../js-yaml
Nine: js-yaml/bin
<a href="../../lib/assets/css/styles.css"></a>
<a href="lib/assets/css/styles.css"></a>
<a href="../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>
## absolutes
One: examples/result/md/changelog.md
Two: C:/orandea/impl/bbb
Three: lib
Four: .
Eight: ./
Five: docs/toc.md
Five: js-yaml
Six: js-yaml/bin
Seven: docs/toc.md
## directory
One: .
Two: .
Three: .
Four: .
Eight: .
Five: .
Five: .
Six: .
Seven: .
# Special Helpers
#### version
Get version from root `package.json`
Project Version: v0.1.3
Project Name: helper-lib
Project Description: Extensive collection of Handlebars helpers.
<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>
<p>Default after section content</p>
</body>
</html>
Brian Woodward (http://github.com/doowb)
Jon Schlinkert (http://github.com/jonschlinkert)
Another "One" Someone (lskskljasdl;jasdljas)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

.alert {
padding: 8px 35px 8px 14px;
margin-bottom: 20px;
color: #c09853;
background-color: #fcf8e3;
border: 1px solid #fbeed5;
border-radius: 4px;
}
.alert h4 {
margin-top: 0;
color: inherit;
}
.alert hr {
border-top-color: #f8e5be;
}
.alert > a,
.alert > p > a {
font-weight: 500;
color: #a47e3c;
}
---
title: Fodder
description: different file formats for testing helpers
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ title }}</title>
</head>
<body>
<h1>{{ title }}</h1>
<p>{{ description }}</p>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fodder</title>
</head>
<body>
<h1>Fodder</h1>
<p>different file formats for testing helpers</p>
</body>
</html>
// Assemble Engine Loader
var EngineLoader = options.EngineLoader = assemble.EngineLoader(options);
var engine = null;
EngineLoader.getEngine(function(err, results) {
if(err) {
console.log(err);
return;
}
engine = options.engine = results;
});
{"title": "Fodder",
"description": "different file formats for testing helpers"}
.alert {
padding: 8px 35px 8px 14px;
margin-bottom: @line-height-base;
color: @state-warning-text;
background-color: @state-warning-background;
border: 1px solid @state-warning-border;
border-radius: @border-radius-base;
// Headings for larger alerts
h4 {
margin-top: 0;
// Specified for the h4 to prevent conflicts of changing @headingsColor
color: inherit;
}
// Match the hr to the border of the alert
hr {
border-top-color: darken(@state-warning-border, 5%);
}
// Inherit color for immediate links and bolden them some
> a,
> p > a {
font-weight: 500;
color: darken(@state-warning-text, 10%);
}
}
#### 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>
```
title: Fodder
description: different file formats for testing helpers
title: Fodder
description: different file formats for testing helpers
# README
## {{chapter './examples/src/content/test.md'}}
---
title: Associative arrays
# Indented Blocks, common in YAML data files, use indentation and new lines to separate the 'key: value' pairs
people:
name: John Smith
age: 33
# Inline Blocks, common in YAML data streams, use comma+space to separate the 'key: value' pairs between braces
morePeople: {name: Grace Jones, age: 21}
tags: "foo, bar, baz"
---
<div class="page-header">
<h1>{{{title}}}</h1>
</div>
<div class="examples">
<h4>Associative arrays</h4>
<dl class="dl-horizontal">
{{#people}}
<dt>Name:</dt> <dd>{{name}}</dd>
<dt>Age:</dt> <dd>{{age}}</dd>
{{/people}}
{{#morePeople}}
<dt>Name:</dt> <dd>{{name}}</dd>
<dt>Age:</dt> <dd>{{age}}</dd>
{{/morePeople}}
</dl>
</div>
{{!arrayify tags}}
---
title: File Helpers
from: ./examples/src/templates/embed.hbs
---
# {{title}}
Copy from "A to B": {{copy from './examples/result/md/copied.hbs'}}
---
title: Embed Helper
lang:
none: <%= content %>/TEST
css: <%= content %>/test.css
hbs: <%= content %>/test.hbs
html: <%= content %>/test.html
js: <%= content %>/test.js
json: <%= content %>/test.json
less: <%= content %>/test.less
md: <%= content %>/test.md
text: <%= content %>/test.txt
yml: <%= content %>/test.yml
---
# {{ title }}
{{embed lang.none}}
{{embed lang.css 'css'}}
{{embed lang.hbs 'hbs'}}
{{embed lang.html 'html'}}
{{embed lang.js 'javascript'}}
{{embed lang.json 'json'}}
{{embed lang.less 'less'}}
{{!embed lang.md 'md'}} {{! currently does not work on markdown. fences need to be escaped }}
{{embed lang.text 'txt'}}
{{embed lang.yml 'yml'}}
---
title: Extension Helper
---
<h1>{{title}}</h1>
Exension: {{extname "docs/toc.html"}}
---
title: Gist Helper
---
<h1>{{title}}</h1>
{{gist '5102394'}}
# README
## {{glob './examples/src/content/*.md'}}
---
title: HTML Helpers
links:
- one
- two
- three
moreLinks:
-
url: one
text: two
-
url: three
text: four
-
url: five
text: size
---
<h2><pre>link</pre> Helper</h2>
{{link 'http://github.com' 'GitHub'}}
{{link 'http://github.com' 'GitHub' 'nav-link'}}
{{#ul links class="nav"}}
{{.}}
{{/ul}}
{{#ul moreLinks class="nav"}}
<a href="{{url}}">{{text}}</a>
{{/ul}}
---
title: Icon Helper
---
{{icon 'test.png'}}
{{icon 'test.pdf'}}
{{icon 'test.doc'}}
{{icon 'test.txt'}}
{{icon 'test'}}
---
title: Include
---
# {{title}}
{{include './examples/src/content/test.md'}}
---
title: Inspect Helper
lang:
none: <%= content %>/TEST
css: <%= content %>/test.css
hbs: <%= content %>/test.hbs
html: <%= content %>/test.html
js: <%= content %>/test.js
json: <%= content %>/test.json
less: <%= content %>/test.less
md: <%= content %>/test.md
text: <%= content %>/test.txt
yml: <%= content %>/test.yml
---
# {{ title }}
{{inspect lang 'json'}}
---
title: jsFiddle Helper
---
# `{{title}}` helper
Easily embed a jsfiddle in a page with: `\{{ jsfiddle [id] }}`
{{!jsfiddle}}
{{jsfiddle 'VfSv9'}}
{{jsfiddle 'VfSv9' 'css,html'}}
<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: Markdown Helpers
link:
-
text: Assemble
url: http://github.com/assemble/
---
<h1>{{title}}: Includes and Blocks</h1>
<h2>Markdown "Include": Escaped</h2>
{{md './examples/src/content/test.md'}}
<h2>Markdown "Include": Un-escaped</h2>
{{{md './examples/src/content/test.md'}}}
<h2>Markdown Block</h2>
{{#markdown}}
# h1 Heading
## h2 Heading
### h3 Heading
#### h4 Heading
##### h5 Heading
###### h6 Heading
## 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>
```
{{/markdown}}
---
title: Miscellaneous Helpers
pkg: ./package.json
---
# {{title}}
## Icons
{{icon 'test.png'}}
{{icon 'test.pdf'}}
{{icon 'test.doc'}}
{{icon 'test.txt'}}
{{icon 'test.csv'}}
## Highlight text
{{highlight 'This is content'}}
{{highlight 'This is content' 'alert-info'}}
## JSON
#### `property`
**Name**
{{property './package.json' 'name'}}
#### `value`
**Name**
{{value './package.json' 'name'}}
#### `stringify`
**package.json**
{{stringify './package.json'}}
---
title: Pages (Collection) Variables
url:
assemble: http://github.com/assemble/
---
<h1>{{title}}</h1>
<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.assemble}}">Visit Assemble</a></li></ul>
</div>
</div>
</div>
{{#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}}
---
title: Path Helpers
from: ./examples/result/md/authors.md
to: ./examples/result/md/changelog.md
---
# {{title}}
## `basename`
Basename: {{basename "docs/toc.md"}}
## `filename`
File name: {{filename "docs/toc.md"}}
## `extname`
File name: {{extname "docs/toc.md"}}
## relative
One: {{relative from to}}
Two: {{relative 'C:\\orandea\\test\\aaa' 'C:\\orandea\\impl\\bbb'}}
Three: {{relative "lib" "docs/toc.md"}}
Four: {{relative "." "lib"}}
Five: {{relative "docs/toc.md" "."}}
Five: {{relative "docs/toc.md" "js-yaml"}}
Six: {{relative "js-yaml/bin" "lib"}}
Seven: {{relative "docs/toc.md" "js-yaml"}}
Eight: {{relative "./" "js-yaml/bin"}}
Nine: {{relative "docs/toc.md" "js-yaml"}}
Nine: {{relative "." "js-yaml/bin"}}
<a href="{{relative "docs/toc.md" "lib"}}/assets/css/styles.css"></a>
<a href="{{relative "." "lib"}}/assets/css/styles.css"></a>
<a href="{{relative " " "lib"}}/assets/css/styles.css"></a>
<a href="{{relative "/" "lib"}}/assets/css/styles.css"></a>
<a href="{{relative "docs/toc.md" "."}}/assets/css/styles.css"></a>
<a href="{{relative "docs/toc.md" "/"}}/assets/css/styles.css"></a>
## absolutes
One: {{absolute to}}
Two: {{absolute 'C:\\orandea\\impl\\bbb'}}
Three: {{absolute "lib"}}
Four: {{absolute "."}}
Eight: {{absolute "./"}}
Five: {{absolute "docs/toc.md"}}
Five: {{absolute "js-yaml"}}
Six: {{absolute "js-yaml/bin"}}
Seven: {{absolute "docs/toc.md"}}
## directory
One: {{directory to}}
Two: {{directory 'C:\\orandea\\impl\\bbb'}}
Three: {{directory "lib"}}
Four: {{directory "."}}
Eight: {{directory "./"}}
Five: {{directory "docs/toc.md"}}
Five: {{directory "js-yaml"}}
Six: {{directory "js-yaml/bin"}}
Seven: {{directory "docs/toc.md"}}
---
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}}
---
title: Special Helpers
---
# {{title}}
#### version
Get version from root `package.json`
Project Version: v{{value './package.json' 'version'}}
Project Name: {{{value './package.json' 'name'}}
Project Description: {{value './package.json' 'description'}}
module.exports = require('./lib/helper-lib');
(function() {
var dir, fs, path;
fs = require('fs');
path = require('path');
dir = path.join(__dirname, 'helpers');
module.exports.register = function(Handlebars, options) {
var endsWith, file, loadFile, _i, _len, _ref, _results;
endsWith = function(str, search) {
var result;
result = str.indexOf(search, str.length - search.length);
return result !== -1;
};
loadFile = function(file) {
var helper;
if (!endsWith(file, 'helpers.js')) {
helper = require(file);
}
if (!(typeof helper === 'undefined' || typeof helper.register === 'undefined')) {
return helper.register(Handlebars, options);
}
};
_ref = fs.readdirSync(dir);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
file = _ref[_i];
_results.push(loadFile(path.join(dir, file)));
}
return _results;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
var Utils;
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;
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;
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;
array = array.slice(count);
result = '';
for (item in array) {
result += options.fn(array[item]);
}
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);
result = '';
for (item in array) {
result += options.fn(array[item]);
}
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.
*/
Handlebars.registerHelper('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;
});
Handlebars.registerHelper('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;
});
Handlebars.registerHelper("arrayify", function(data) {
var result;
result = data.split(",").map(function(tag) {
return "\"" + tag + "\"";
});
return result;
});
return this;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
Handlebars.registerHelper('is', function(value, test, options) {
if (value === test) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
Handlebars.registerHelper('isnt', function(value, test, options) {
if (value !== test) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
Handlebars.registerHelper('gt', function(value, test, options) {
if (value > test) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
Handlebars.registerHelper('gte', function(value, test, options) {
if (value >= test) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
Handlebars.registerHelper('lt', function(value, test, options) {
if (value < test) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
Handlebars.registerHelper('lte', function(value, test, options) {
if (value <= test) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
Handlebars.registerHelper('or', function(testA, testB, options) {
if (testA || testB) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
Handlebars.registerHelper('and', function(testA, testB, options) {
if (testA && testB) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
/*
If Equals
if_eq this compare=that
*/
Handlebars.registerHelper("if_eq", function(context, options) {
if (context === options.hash.compare) {
return options.fn(this);
}
return options.inverse(this);
});
/*
Unless Equals
unless_eq this compare=that
*/
Handlebars.registerHelper("unless_eq", function(context, options) {
if (context === options.hash.compare) {
return options.inverse(this);
}
return options.fn(this);
});
/*
If Greater Than
if_gt this compare=that
*/
Handlebars.registerHelper("if_gt", function(context, options) {
if (context > options.hash.compare) {
return options.fn(this);
}
return options.inverse(this);
});
/*
Unless Greater Than
unless_gt this compare=that
*/
Handlebars.registerHelper("unless_gt", function(context, options) {
if (context > options.hash.compare) {
return options.inverse(this);
}
return options.fn(this);
});
/*
If Less Than
if_lt this compare=that
*/
Handlebars.registerHelper("if_lt", function(context, options) {
if (context < options.hash.compare) {
return options.fn(this);
}
return options.inverse(this);
});
/*
Unless Less Than
unless_lt this compare=that
*/
Handlebars.registerHelper("unless_lt", function(context, options) {
if (context < options.hash.compare) {
return options.inverse(this);
}
return options.fn(this);
});
/*
If Greater Than or Equal To
if_gteq this compare=that
*/
Handlebars.registerHelper("if_gteq", function(context, options) {
if (context >= options.hash.compare) {
return options.fn(this);
}
return options.inverse(this);
});
/*
Unless Greater Than or Equal To
unless_gteq this compare=that
*/
Handlebars.registerHelper("unless_gteq", function(context, options) {
if (context >= options.hash.compare) {
return options.inverse(this);
}
return options.fn(this);
});
/*
If Less Than or Equal To
if_lteq this compare=that
*/
Handlebars.registerHelper("if_lteq", function(context, options) {
if (context <= options.hash.compare) {
return options.fn(this);
}
return options.inverse(this);
});
/*
Unless Less Than or Equal To
unless_lteq this compare=that
*/
Handlebars.registerHelper("unless_lteq", function(context, options) {
if (context <= options.hash.compare) {
return options.inverse(this);
}
return options.fn(this);
});
return this;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
var Dates, Utils;
Utils = require('../utils/utils');
Dates = require('../utils/dates');
Handlebars.registerHelper('formatDate', function(date, format) {
date = new Date(date);
return Dates.format(date, format);
});
Handlebars.registerHelper('now', function(format) {
var date;
date = new Date();
if (Utils.isUndefined(format)) {
return date;
} else {
return Dates.format(date, format);
}
});
Handlebars.registerHelper('timeago', function(date) {
var interval, seconds;
date = new Date(date);
seconds = Math.floor((new Date() - date) / 1000);
interval = Math.floor(seconds / 31536000);
if (interval > 1) {
return "" + interval + " years ago";
}
interval = Math.floor(seconds / 2592000);
if (interval > 1) {
return "" + interval + " months ago";
}
interval = Math.floor(seconds / 86400);
if (interval > 1) {
return "" + interval + " days ago";
}
interval = Math.floor(seconds / 3600);
if (interval > 1) {
return "" + interval + " hours ago";
}
interval = Math.floor(seconds / 60);
if (interval > 1) {
return "" + interval + " minutes ago";
}
if (Math.floor(seconds) === 0) {
return 'Just now';
} else {
return Math.floor(seconds) + ' seconds ago';
}
});
return this;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
var Utils, path, _;
Utils = require('../utils/utils');
path = require('path');
_ = require('lodash');
Handlebars.registerHelper("value", function(file, prop) {
file = Utils.readJSON(file);
prop = _.pick(file, prop);
prop = _.pluck(prop);
return new Handlebars.SafeString(prop);
});
Handlebars.registerHelper("property", function(file, prop) {
file = Utils.readJSON(file);
prop = _.pick(file, prop);
return new Handlebars.SafeString(JSON.stringify(prop, null, 2));
});
Handlebars.registerHelper("stringify", function(file, props) {
file = Utils.readJSON(file);
return new Handlebars.SafeString(JSON.stringify(file, null, 2));
});
/*
Copy: copies src file from A to B. USE WITH CAUTION!!!
Usage: {{copy [a] [b]}}
*/
return Handlebars.registerHelper('copy', function(a, b) {
return Utils.copyFile(a, b);
});
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
var HTML, Utils;
Utils = require('../utils/utils');
HTML = require('../utils/html');
/*
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("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);
});
/*
List: <ul>
*/
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>";
});
/*
List: <ol>
Same as the `ul` helper but creates ordered lists.
*/
Handlebars.registerHelper("ol", function(context, options) {
return ("<ol " + (HTML.parseAttributes(options.hash)) + ">") + context.map(function(item) {
return "<li>" + (options.fn(item)) + "</li>";
}).join("\n") + "</ol>";
});
/*
Break helper: Add the specified number of br tags
Usage: {{br 5}}
*/
Handlebars.registerHelper('br', function(count, options) {
var br, i;
br = '<br>';
if (!Utils.isUndefined(count)) {
i = 0;
while (i < count - 1) {
br += '<br>';
i++;
}
}
return Utils.safeString(br);
});
/*
Convert new line (\n) to <br>
from http://phpjs.org/functions/nl2br:480
*/
Handlebars.registerHelper('nl2br', function(text) {
var nl2br;
nl2br = (text + "").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, "$1" + "<br>" + "$2");
return Utils.safeString(nl2br);
});
Handlebars.registerHelper('newLineToBr', function(str) {
return str.replace(/\r?\n|\r/g, '<br>');
});
/*
<!DOCTYPE>
Same as the `ul` helper but creates and ordered list.
*/
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("icon", function(attachment) {
var extension, value;
extension = attachment.substr(attachment.lastIndexOf(".") + 1);
value = Handlebars.Utils.escapeExpression(extension);
switch (value) {
case "jpg":
case "jpeg":
case "png":
case "gif":
return Utils.safeString('<img src="img/img-icon.png"><span>' + attachment + '</span>');
case "zip":
case "rar":
return Utils.safeString('<img src="img/archive-icon.png"><span>' + attachment + '</span>');
case "pdf":
return Utils.safeString('<img src="img/pdf-icon.png"><span>' + attachment + '</span>');
case "txt":
return Utils.safeString('<img src="img/txt-icon.png"><span>' + attachment + '</span>');
case "doc":
case "docx":
return Utils.safeString('<img src="img/word-icon.png"><span>' + attachment + '</span>');
case "xls":
case "xlsx":
return Utils.safeString('<img src="img/xls-icon.png"><span>' + attachment + '</span>');
case "csv":
return Utils.safeString('<img src="img/csv-icon.png"><span>' + attachment + '</span>');
case "ppt":
case "pptx":
return Utils.safeString('<img src="img/ppt-icon.png"><span>' + attachment + '</span>');
case "mp3":
return Utils.safeString('<img src="img/audio-icon.png"><span>' + attachment + '</span>');
default:
return Utils.safeString('<img src="img/other-icon.png"><span>' + attachment + '</span>');
}
});
return this;
};
}).call(this);
(function() {
var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
module.exports.register = function(Handlebars, options) {
var Utils;
Utils = require('../utils/utils');
Handlebars.registerHelper('inflect', function(count, singular, plural, include) {
var word;
word = count > 1 || count === 0 ? plural : singular;
if (Utils.isUndefined(include) || include === false) {
return word;
} else {
return "" + count + " " + word;
}
});
Handlebars.registerHelper('ordinalize', function(value) {
var normal, _ref;
normal = Math.abs(Math.round(value));
if (_ref = normal % 100, __indexOf.call([11, 12, 13], _ref) >= 0) {
return "" + value + "th";
} else {
switch (normal % 10) {
case 1:
return "" + value + "st";
case 2:
return "" + value + "nd";
case 3:
return "" + value + "rd";
default:
return "" + value + "th";
}
}
});
return this;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
var Utils;
Utils = require('../utils/utils');
Handlebars.registerHelper('inspect', function(obj, language) {
var result;
if (Utils.isUndefined(language)) {
language = "";
}
result = '``` ' + language + '\n' + require('util').inspect(obj, 10, null).replace('{', '{\n ').replace('}', '\n}') + '\n```';
return Utils.safeString(result);
});
Handlebars.registerHelper('log', function(value) {
return console.log(value);
});
Handlebars.registerHelper('debug', function(value) {
console.log('Context: ', this);
if (!Utils.isUndefined(value)) {
console.log('Value: ', value);
}
return console.log('-----------------------------------------------');
});
return this;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
var Utils, fs, glob, isServer, markdown, opts, path, yaml, _;
fs = require('fs');
path = require('path');
_ = require('lodash');
yaml = require('js-yaml');
glob = require('globule');
Utils = require('../utils/utils');
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);
markdown = require('../utils/markdown').Markdown(opts);
isServer = typeof process !== 'undefined';
/*
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);
});
/*
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.
Syntax: {{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}} {{{@key}}} {{#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.
Syntax: {{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}} {{{@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;
file = Utils.read(file);
content = file.replace(/(^[^ ]*\s)(.+)([^#]+(?=.*)$)/gim, '$2\n' + '$3') || [];
return Utils.safeString(content);
});
/*
Glob: reads in data from a markdown file, and uses the first heading
as a section heading, and then copies the rest of the content inline.
Usage: {{{ glob [file] }}
*/
Handlebars.registerHelper('glob', function(file) {
var content;
file = glob.find(file);
content = Utils.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
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
rendered the markdown inline with the HTML
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.read(path);
tmpl = Handlebars.compile(content);
md = tmpl(this);
html = markdown.convert(md);
return Utils.safeString(html);
});
}
return this;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
Handlebars.registerHelper('add', function(value, addition) {
return value + addition;
});
Handlebars.registerHelper('subtract', function(value, substraction) {
return value - substraction;
});
Handlebars.registerHelper('divide', function(value, divisor) {
return value / divisor;
});
Handlebars.registerHelper('multiply', function(value, multiplier) {
return value * multiplier;
});
Handlebars.registerHelper('floor', function(value) {
return Math.floor(value);
});
Handlebars.registerHelper('ceil', function(value) {
return Math.ceil(value);
});
Handlebars.registerHelper('round', function(value) {
return Math.round(value);
});
return this;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
Handlebars.registerHelper('default', function(value, defaultValue) {
return value != null ? value : defaultValue;
});
/*
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)
*/
return this;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
var Utils;
Utils = require('../utils/utils');
Handlebars.registerHelper('toFixed', function(number, digits) {
if (Utils.isUndefined(digits)) {
digits = 0;
}
return number.toFixed(digits);
});
Handlebars.registerHelper('toPrecision', function(number, precision) {
if (Utils.isUndefined(precision)) {
precision = 1;
}
return number.toPrecision(precision);
});
Handlebars.registerHelper('toExponential', function(number, fractions) {
if (Utils.isUndefined(fractions)) {
fractions = 0;
}
return number.toExponential(fractions);
});
Handlebars.registerHelper('toInt', function(number) {
return parseInt(number, 10);
});
Handlebars.registerHelper('toFloat', function(number) {
return parseFloat(number);
});
Handlebars.registerHelper('addCommas', function(number) {
return number.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
});
return this;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
var Utils, path;
path = require('path');
Utils = require('../utils/utils');
/*
WARNING!!! WARNING!!! WARNING!!!
These are not correct orstable, feel free to test
or submit pull requests for fixes, but do not
use them in projects yet!!!
*/
/*
directory: Returns the absolute path to the current directory.
Usage: {{directory [path]}}
Returns: C:\path\to\the\current\current\directory
*/
Handlebars.registerHelper("directory", function(dir) {
return dir = path.dirname();
});
/*
absolute: Returns the absolute path to the current directory.
Usage: {{absolute [to]}}
Returns: C:\path\to\the\current\current\directory
*/
Handlebars.registerHelper("absolute", function(to) {
var absolutePath;
return absolutePath = Utils.urlNormalize(path.normalize(to, path.dirname()));
});
/*
Relative: {{relative [from] [to]}}
Returns the derived relative path from one to the other.
*/
Handlebars.registerHelper("relative", function(from, to) {
var relativePath;
return relativePath = Utils.getRelativePath(from, to);
});
/*
filename: Returns the full-name of a given file.
Usage: {{filename "docs/toc.md"}}
Returns: toc.md
*/
Handlebars.registerHelper('filename', function(base, ext) {
var fullName;
return fullName = path.basename(base, ext);
});
/*
Basename: Returns the basename of a given file.
Usage: {{base "docs/toc.md"}}
Returns: toc
*/
Handlebars.registerHelper('basename', function(base, ext) {
var basename;
return basename = Utils.getBasename(base, ext);
});
/*
Extension: Returns the extension of a given file.
Usage: {{ext "docs/toc.md"}}
Returns: .md
*/
Handlebars.registerHelper("extname", function(ext) {
var extname;
return extname = Utils.getExt(ext);
});
return this;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
var Utils, fs, _;
fs = require('fs');
_ = require('lodash');
Utils = require('../utils/utils');
/*
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
Usage: {{ jsfiddle [id] [tabs] }}
*/
Handlebars.registerHelper('jsfiddle', function(id, tabs) {
var result;
if (Utils.isUndefined(tabs)) {
tabs = "result,js,html,css";
}
result = '<iframe width="100%" height="300" src="http://jsfiddle.net/' + id + '/embedded/' + tabs + '/presentation/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>';
return Utils.safeString(result);
});
/*
Gist: Downloads and embeds public GitHub Gists by
adding only the Id of the Gist.
Usage: {{ gist [id] [file] }}
*/
Handlebars.registerHelper('gist', function(id, file) {
var result;
id = Handlebars.Utils.escapeExpression(id);
if (Utils.isUndefined(file)) {
file = "";
}
result = '<script src="https://gist.github.com/' + id + '.js"></script>';
return Utils.safeString(result);
});
/*
Highlight: wraps the output in a span with the class "highlight".
Usage: {{highlight 'value' 'class'}}
*/
Handlebars.registerHelper('highlight', function(text, modifier) {
var result;
if (Utils.isUndefined(modifier)) {
modifier = "highlight";
}
result = '<span class="' + modifier + '">' + text + '</span>';
return Utils.safeString(result);
});
/*
Format Phone Number
from: http://blog.teamtreehouse.com/handlebars-js-part-2-partials-and-helpers
Helper function to output a formatted phone number
Usage: {{formatPhoneNumber phoneNumber}}
*/
Handlebars.registerHelper("formatPhoneNumber", function(phoneNumber) {
phoneNumber = phoneNumber.toString();
return "(" + phoneNumber.substr(0, 3) + ") " + phoneNumber.substr(3, 3) + "-" + phoneNumber.substr(6, 4);
});
return this;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
var Utils;
Utils = require('../utils/utils');
Handlebars.registerHelper("safeString", function(value) {
return Utils.safeString(value);
});
Handlebars.registerHelper('lowercase', function(str) {
return str.toLowerCase();
});
Handlebars.registerHelper('uppercase', function(str) {
return str.toUpperCase();
});
Handlebars.registerHelper('capitalizeFirst', function(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
});
Handlebars.registerHelper('capitalizeEach', function(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1);
});
});
Handlebars.registerHelper('titleize', function(str) {
var capitalize, title, word, words;
title = str.replace(/[ \-_]+/g, ' ');
words = title.match(/\w+/g);
capitalize = function(word) {
return word.charAt(0).toUpperCase() + word.slice(1);
};
return ((function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = words.length; _i < _len; _i++) {
word = words[_i];
_results.push(capitalize(word));
}
return _results;
})()).join(' ');
});
Handlebars.registerHelper('sentence', function(str) {
return str.replace(/((?:\S[^\.\?\!]*)[\.\?\!]*)/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
});
Handlebars.registerHelper('reverse', function(str) {
return str.split('').reverse().join('');
});
Handlebars.registerHelper('truncate', function(str, length, omission) {
if (Utils.isUndefined(omission)) {
omission = '';
}
if (str.length > length) {
return str.substring(0, length - omission.length) + omission;
} else {
return str;
}
});
Handlebars.registerHelper('center', function(str, spaces) {
var i, space;
space = '';
i = 0;
while (i < spaces) {
space += '&nbsp;';
i++;
}
return "" + space + str + space;
});
Handlebars.registerHelper("hyphenate", function(tag) {
return tag.split(" ").join("-");
});
Handlebars.registerHelper("dashify", function(tag) {
return tag.split(".").join("-");
});
return this;
};
}).call(this);
(function() {
module.exports.register = function(Handlebars, options) {
Handlebars.registerHelper("stripQuerystring", function(url) {
return url.split("?")[0];
});
/*
encode URI
Encodes a Uniform Resource Identifier (URI) component by replacing each instance of
certain characters by one, two, three, or four escape sequences representing the
UTF-8 encoding of the character
*/
Handlebars.registerHelper("encodeURI", function(uri) {
return encodeURIComponent(uri);
});
/*
Decode URI
Decodes a Uniform Resource Identifier (URI) component previously created
by encodeURIComponent or by a similar routine.
*/
return Handlebars.registerHelper("decodeURI", function(encodedURI) {
return decodeURIComponent(encodedURI);
});
};
}).call(this);
(function() {
var Handlebars;
if (typeof window !== "undefined" && window !== null) {
Handlebars = window.Handlebars;
}
if (typeof module !== "undefined" && module !== null) {
Handlebars = module.exports.Handlebars = require('handlebars');
}
}).call(this);
(function() {
var Dates;
Dates = module.exports = {};
Dates.padNumber = function(num, count, padCharacter) {
var lenDiff, padding;
if (typeof padCharacter === 'undefined') {
padCharacter = '0';
}
lenDiff = count - String(num).length;
padding = '';
if (lenDiff > 0) {
while (lenDiff--) {
padding += padCharacter;
}
}
return padding + num;
};
Dates.dayOfYear = function(date) {
var oneJan;
oneJan = new Date(date.getFullYear(), 0, 1);
return Math.ceil((date - oneJan) / 86400000);
};
Dates.weekOfYear = function(date) {
var oneJan;
oneJan = new Date(date.getFullYear(), 0, 1);
return Math.ceil((((date - oneJan) / 86400000) + oneJan.getDay() + 1) / 7);
};
Dates.isoWeekOfYear = function(date) {
var dayDiff, dayNr, jan4, target;
target = new Date(date.valueOf());
dayNr = (date.getDay() + 6) % 7;
target.setDate(target.getDate() - dayNr + 3);
jan4 = new Date(target.getFullYear(), 0, 4);
dayDiff = (target - jan4) / 86400000;
return 1 + Math.ceil(dayDiff / 7);
};
Dates.tweleveHour = function(date) {
if (date.getHours() > 12) {
return date.getHours() - 12;
} else {
return date.getHours();
}
};
Dates.timeZoneOffset = function(date) {
var hoursDiff, result;
hoursDiff = -date.getTimezoneOffset() / 60;
result = Dates.padNumber(Math.abs(hoursDiff), 4);
return (hoursDiff > 0 ? '+' : '-') + result;
};
Dates.format = function(date, format) {
return format.replace(Dates.formats, function(m, p) {
switch (p) {
case 'a':
return Dates.abbreviatedWeekdays[date.getDay()];
case 'A':
return Dates.fullWeekdays[date.getDay()];
case 'b':
return Dates.abbreviatedMonths[date.getMonth()];
case 'B':
return Dates.fullMonths[date.getMonth()];
case 'c':
return date.toLocaleString();
case 'C':
return Math.round(date.getFullYear() / 100);
case 'd':
return Dates.padNumber(date.getDate(), 2);
case 'D':
return Dates.format(date, '%m/%d/%y');
case 'e':
return Dates.padNumber(date.getDate(), 2, ' ');
case 'F':
return Dates.format(date, '%Y-%m-%d');
case 'h':
return Dates.format(date, '%b');
case 'H':
return Dates.padNumber(date.getHours(), 2);
case 'I':
return Dates.padNumber(Dates.tweleveHour(date), 2);
case 'j':
return Dates.padNumber(Dates.dayOfYear(date), 3);
case 'k':
return Dates.padNumber(date.getHours(), 2, ' ');
case 'l':
return Dates.padNumber(Dates.tweleveHour(date), 2, ' ');
case 'L':
return Dates.padNumber(date.getMilliseconds(), 3);
case 'm':
return Dates.padNumber(date.getMonth() + 1, 2);
case 'M':
return Dates.padNumber(date.getMinutes(), 2);
case 'n':
return '\n';
case 'p':
if (date.getHours() > 11) {
return 'PM';
} else {
return 'AM';
}
case 'P':
return Dates.format(date, '%p').toLowerCase();
case 'r':
return Dates.format(date, '%I:%M:%S %p');
case 'R':
return Dates.format(date, '%H:%M');
case 's':
return date.getTime() / 1000;
case 'S':
return Dates.padNumber(date.getSeconds(), 2);
case 't':
return '\t';
case 'T':
return Dates.format(date, '%H:%M:%S');
case 'u':
if (date.getDay() === 0) {
return 7;
} else {
return date.getDay();
}
case 'U':
return Dates.padNumber(Dates.weekOfYear(date), 2);
case 'v':
return Dates.format(date, '%e-%b-%Y');
case 'V':
return Dates.padNumber(Dates.isoWeekOfYear(date), 2);
case 'W':
return Dates.padNumber(Dates.weekOfYear(date), 2);
case 'w':
return Dates.padNumber(date.getDay(), 2);
case 'x':
return date.toLocaleDateString();
case 'X':
return date.toLocaleTimeString();
case 'y':
return String(date.getFullYear()).substring(2);
case 'Y':
return date.getFullYear();
case 'z':
return Dates.timeZoneOffset(date);
default:
return match;
}
});
};
Dates.formats = /%(a|A|b|B|c|C|d|D|e|F|h|H|I|j|k|l|L|m|M|n|p|P|r|R|s|S|t|T|u|U|v|V|W|w|x|X|y|Y|z)/g;
Dates.abbreviatedWeekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'];
Dates.fullWeekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
Dates.abbreviatedMonths = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
Dates.fullMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
}).call(this);
(function() {
var HTML;
HTML = module.exports = {};
HTML.parseAttributes = function(hash) {
return Object.keys(hash).map(function(key) {
return "" + key + "=\"" + hash[key] + "\"";
}).join(' ');
};
}).call(this);
(function() {
var Markdown, fs, hljs, marked, _;
fs = require("fs");
_ = require("lodash");
marked = require("marked");
hljs = require("highlight.js");
/*
Some of the following code is from grunt-markdown
https://github.com/treasonx/grunt-markdown
*/
Markdown = function(options) {
return this.init(options);
};
Markdown.prototype.init = function(options) {
var defaults;
defaults = {
fromFile: true
};
this.options = _.extend(defaults, options);
return this;
};
Markdown.prototype.read = function(src) {
var md;
if (!fs.existsSync(src)) {
console.log("File " + src + " not found.");
return "";
}
md = fs.readFileSync(src, "utf8");
return this.convert(md);
};
Markdown.prototype.convert = function(src) {
var codeLines, html, shouldWrap, wrapLines;
codeLines = this.options.codeLines;
shouldWrap = false;
if (codeLines && codeLines.before && codeLines.after) {
shouldWrap = true;
}
wrapLines = function(code) {
var after, before, out;
out = [];
before = codeLines.before;
after = codeLines.after;
code = code.split("\n");
code.forEach(function(line) {
return out.push(before + line + after);
});
return out.join("\n");
};
if (typeof this.options.highlight === "string") {
if (this.options.highlight === "auto") {
this.options.highlight = function(code) {
var out;
out = hljs.highlightAuto(code).value;
if (shouldWrap) {
out = wrapLines(out);
}
return out;
};
} else if (this.options.highlight === "manual") {
this.options.highlight = function(code, lang) {
var e, out;
out = code;
try {
code = hljs.highlight(lang, code).value;
} catch (_error) {
e = _error;
out = hljs.highlightAuto(code).value;
}
if (shouldWrap) {
out = wrapLines(out);
}
return out;
};
}
}
marked.setOptions(this.options);
html = marked(src);
return html;
};
module.exports.Markdown = function(options) {
return new Markdown(options);
};
}).call(this);
(function() {
var Handlebars, Utils, fs, glob, grunt, mout, path;
Handlebars = require('../helpers/helpers').Handlebars;
fs = require('fs');
path = require('path');
grunt = require("grunt");
glob = require('globule');
mout = require('mout');
Utils = module.exports = {};
Utils.toString = Object.prototype.toString;
Utils.isUndefined = function(value) {
return value === 'undefined' || Utils.toString.call(value) === '[object Function]' || (value.hash != null);
};
Utils.safeString = function(str) {
return new Handlebars.SafeString(str);
};
Utils.trim = function(str) {
var trim;
trim = /\S/.test("\xA0") ? /^[\s\xA0]+|[\s\xA0]+$/g : /^\s+|\s+$/g;
return str.toString().replace(trim, '');
};
Utils.pluck = mout.collection.pluck;
/*
node.path utils
*/
Utils.getExt = function(str) {
var extname;
extname = path.extname(str);
if (extname) {
str = extname;
}
if (str[0] === ".") {
str = str.substring(1);
}
return str;
};
Utils.getBasename = function(base, ext) {
var fullName;
fullName = path.basename(base, ext);
return base = path.basename(base, path.extname(fullName));
};
Utils.getRelativePath = function(from, to) {
var relativePath;
return relativePath = Utils.urlNormalize(path.relative(from, to));
};
Utils.getPropString = function(prop) {
return prop = grunt.config.getPropString(prop);
};
/*
Globbing
*/
glob = function(pattern, config) {
var options, results;
options = {};
if (config.dir) {
options.cwd = path.normalize(config.dir);
}
results = glob.sync(pattern, options);
if (!config.exclude) {
return results;
}
results = results.filter(function(path) {
return !config.exclude.test(path);
});
return results;
};
Utils.exists = function(file) {
var src;
return src = grunt.file.exists(file);
};
Utils.read = function(filepath, options) {
var src;
return src = grunt.file.read(filepath, options);
};
Utils.expand = function(filepath, options) {
var src;
return src = grunt.file.expand(filepath, options);
};
Utils.readJSON = function(filepath, options) {
var src;
return src = grunt.file.readJSON(filepath, options);
};
Utils.readYAML = function(filepath, options) {
var src;
return src = grunt.file.readYAML(filepath, options);
};
Utils.write = function(filepath, contents, options) {
var src;
return src = grunt.file.write(file);
};
Utils.copyFile = function(filepath, options) {
var src;
src = grunt.file.copy(filepath, options);
return true;
};
Utils.mkDir = function(dirpath, mode) {
var src;
return src = grunt.file.mdDir(dirpath, mode);
};
Utils.urlNormalize = function(filepath) {
var win32;
win32 = process.platform === "win32";
if (win32) {
return filepath.replace(/\\/g, "/");
} else {
return filepath;
}
};
}).call(this);
+0
-0

@@ -0,0 +0,0 @@ {

@@ -1,4 +0,40 @@

- version: v0.1.0
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:
date: "2013-04-07"
changes:
- Add markdown helpers back, add more tests.
v0.1.20:
date: "2013-04-06"
changes:
- Generalized helpers structure, externalized utilities.
v0.1.11:
date: "2013-04-05"
changes:
- New authors and gist helpers, general cleanup and new tests.
v0.1.10:
date: "2013-04-04"
changes:
- Externalized utility javascript from helpers.js
v0.1.8:
date: "2013-03-28"
changes:
- Gruntfile updated with mocha tests for 71 helpers, bug fixes.
v0.1.7:
date: "2013-03-18"
changes:
- New path helper "relative", for resolving relative path from one absolute path to another.
v0.1.3:
date: "2013-03-16"
changes:
- New helpers, "formatPhoneNumber" and "eachProperty"
v0.1.2:
date: "2013-03-15"
changes:
- Update README.md with documentation, examples.
v0.1.0:
date: "2013-03-06"
changes:
- First commit.
+33
-13
{
"name": "helper-lib",
"description": "A massive collection of useful Handlebars helpers.",
"version": "0.1.2",
"description": "Extensive collection of Handlebars helpers.",
"version": "0.1.3",
"homepage": "https://github.com/assemble/helper-lib",
"authors": [
"author": {
"name": "assemble",
"url": "https://github.com/assemble/assemble"
},
"contributors": [
{
"name": "Brian Woodward",
"url": "http://github.com/doowb/"
"url": "https://github.com/doowb"
},
{
"name": "Jon Schlinkert",
"url": "http://github.com/jonschlinkert/"
"url": "https://github.com/jonschlinkert"
}

@@ -29,3 +33,3 @@ ],

],
"main": "lib/helpers",
"main": "index.js",
"engines": {

@@ -35,14 +39,29 @@ "node": ">= 0.8.0"

"scripts": {
"test": "grunt nodeunit"
"test": "grunt test"
},
"dependencies": {
"assemble": "0.3.9"
"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",
"js-yaml": "~2.0.4",
"lodash": "~1.1.1",
"marked": "~0.2.8",
"mime": "latest",
"should": "~1.2.2"
},
"devDependencies": {
"grunt": "~0.4.0",
"grunt-contrib-jshint": "~0.1.1",
"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-watch": "~0.2.0"
"handlebars": "~1.0.10",
"amdefine": "0.0.4"
},
"keywords": [
"assemble",
"block helper",

@@ -77,5 +96,6 @@ "client-side templates",

"template helpers",
"templates",
"use handlebars",
"templates"
"utilities"
]
}
}
+1330
-875

@@ -1,1214 +0,1669 @@

# Helpers Lib
# [Helper Library v0.1.3](http://github.com/assemble/helper-lib) [![Build Status](https://travis-ci.org/assemble/helper-lib.png)](https://travis-ci.org/assemble/helper-lib)
> A growing collection of useful helpers for Assemble.
> Extensive collection of Handlebars helpers.
## Getting Started
Install the module with: `npm install helpers`
```javascript
var helpers = require('helpers');
helpers.awesome(); // "awesome"
```
## Documentation
TODO...
## Quick start
This plugin requires Grunt `~0.4.1` for linting and testing, but Grunt is **not required** to use the helpers.
If you want to learn more about using Grunt, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins.
### Handlebars
[Handlebars.js](https://github.com/wycats/handlebars.js) is currently the default template library for [assemble](http://github.com/assemble/assemble).
```shell
npm install helper-lib --save-dev
```
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
```js
grunt.loadNpmTasks('helper-lib');
```
### Equals
#### If x Equals y
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_.
**Parameters**:
**Usage**:
###
When completed, you'll be able to run the various `grunt` commands provided:
#### build - `grunt`
Runs the Less.js compiler to rebuild the specified `/test/fixtures/**` files. .
{{#if_eq x compare=y}} ... {{/if_eq}}
#### test - `grunt test`
Runs jshint on JavaScripts and nodeunit tests on .
#### 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.
#### Unless x Equals y
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`.
**Parameters**:
**Usage**:
**Table of Contents**
{{#unless_eq x compare=y}} ... {{/unless_eq}}
- [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)
- [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)
## Overview
Handlebars.js ships with some built-in helpers, such as `{{#each}}`, `{{#if}}` and `{{#unless}}`. Here is how helpers work:
* A Handlebars helper call is a simple identifier, followed by zero or more parameters (separated by space).
* Each parameter is a Handlebars expression.
* Handlebars helpers can be accessed from any context in a template.
### Greater Than
[Handlebars.js](https://github.com/wycats/handlebars.js) is currently the default template library for [assemble](http://github.com/assemble/assemble).
#### If x > y
**Parameters**:
**Usage**:
#### Custom Helpers
{{#if_gt x compare=y}} ... {{/if_gt}}
> Contributions welcome! Please consider adding your own helpers to this library.
Handlebars accels over other templating libraries when it comes to creating your own custom helpers. Just register your function into Handlebars with the `Handlebars.registerHelper` method, and that helper will be available to any template you compile afterwards.
#### Unless x > y
Handlebars allows two different kinds of helpers:
**Parameters**:
**Usage**:
* **Expression helpers** are basically regular functions that take the name of the helper and the helper function as arguments. Once an expression helper is registered, it can be called anywhere in your templates, then Handlebars takes the expression's return value and writes it into the template.
* **Block helpers** There are a few block helpers included by default with Handlebars, `{{#each}}`, `{{#if}}` and `{{#unless}}`. Custom block helpers are registered the same way as exptression helpers, but the difference is that Handlebars will pass the contents of the block compiled into a function to the helper.
{{#unless_gt x compare=y}} ... {{/unless_gt}}
## The Helpers
### Special
#### formatPhoneNumber
_Output a formatted phone number_
Credit: [Treehouse Blog](http://blog.teamtreehouse.com/handlebars-js-part-2-partials-and-helpers)
```js
phoneNumber: 4444444444
```
``` handlebars
{{formatPhoneNumber phoneNumber}}
```
Result:
```
(444) 444-4444
```
### Greater Than or Equal To
#### If x >= y
**Parameters**:
**Usage**:
{{#if_gteq x compare=y}} ... {{/if_gteq}}
#### Unless x >= y
**Parameters**:
**Usage**:
{{#unless_gteq x compare=y}} ... {{/unless_gteq}}
### Less Than
#### If x < y
**Parameters**:
**Usage**:
{{#if_lt x compare=y}} ... {{/if_lt}}
#### Unless x < y
**Parameters**:
**Usage**:
{{#unless_lt x compare=y}} ... {{/unless_lt}}
### Less Than or Equal To
#### If x <= y
**Parameters**:
**Usage**:
{{#if_lteq x compare=y}} ... {{/if_lteq}}
#### Unless x <= y
**Parameters**:
**Usage**:
{{#unless_lteq x compare=y}} ... {{/unless_lteq}}
### nl2br
Convert new lines (`\r\n`, `\n\r`, `\r`, `\n`) to line breaks
`{{nl2br description}}`
### Strings
#### hyphenate
_Replace spaces in string with hyphens._
<br>Parameters: `none`
``` handlebars
{{hyphenate "make this all hyphenated"}}
Replace spaces in string with hyphens.
// Result
make-this-all-hyphenated
```
**Parameters**: none.
**Usage**:
{{hyphenate "make this all hyphenated"}}
**result**
make-this-all-hyphenated
#### dashify
_Same as `hyphenate`, but replaces dots in string with hyphens._
<br>Parameters: `none`
``` handlebars
{{dashify "make.this.all.hyphenated"}}
Same as `hyphenate`, but replaces dots in string with hyphens.
// Result
make-this-all-hyphenated
```
**Parameters**: none.
**Usage**:
{{dashify "make.this.all.hyphenated"}}
**result**
make-this-all-hyphenated
#### lowercase
_Turns a string to lowercase._
<br>Parameters: `none`
``` handlebars
{{lowercase "MAKE THIS ALL LOWERCASE"}}
Turns a string to lowercase.
// Result
make this all lowercase
```
**Parameters**: none.
**Usage**:
{{lowercase "MAKE THIS ALL LOWERCASE"}}
**result**
make this all lowercase
#### uppercase
_Turns a string to uppercase. Opposite of `{{lowercase}}`._
<br>Parameters: `none`
``` handlebars
{{uppercase "make this all uppercase"}}
Turns a string to uppercase. Opposite of `{{lowercase}}`.
// Result
MAKE THIS ALL UPPERCASE
```
**Parameters**: none.
**Usage**:
{{uppercase "make this all uppercase"}}
**result**
MAKE THIS ALL UPPERCASE
#### capitalizeFirst
_Capitalizes the first word in a string._
<br>Parameters: `none`
``` handlebars
{{capitalizeFirst "capitalize first word in this sentence"}}
Capitalizes the first word in a string.
// Result
Capitalize first word in this sentence
```
**Parameters**: none.
**Usage**:
{{capitalizeFirst "capitalize first word in this sentence"}}
**result**
Capitalize first word in this sentence
#### capitalizeEach
_Capitalizes each word in a string._
<br>Parameters: `none`
``` handlebars
{{capitalizeEach "capitalize EACH word in this sentence"}}
Capitalizes each word in a string.
// Result
Capitalize EACH Word In This Sentence
```
**Parameters**: none.
**Usage**:
{{capitalizeEach "capitalize EACH word in this sentence"}}
**result**
Capitalize EACH Word In This Sentence
#### titleize
_Capitalizes all words within a string. Taken from the templating library [Walrus](https://github.com/jeremyruppel/walrus) by [Jeremy Ruppel](https://github.com/jeremyruppel)._
<br>Parameters: `none`
``` handlebars
{{titleize "capitalize EACH word in this sentence"}}
Capitalizes all words within a string. Taken from the templating library [Walrus](https://github.com/jeremyruppel/walrus) by [Jeremy Ruppel](https://github.com/jeremyruppel).
// Result
Capitalize Each Word In This Sentence.
```
**Parameters**: none.
**Usage**:
{{titleize "capitalize EACH word in this sentence"}}
**result**
Capitalize Each Word In This Sentence.
#### sentence
_Capitalizes the first word of each sentence in a string and converts the rest of the sentence to lowercase._
Parameters: `none`
``` handlebars
{{sentence "capitalize the FIRST word in each sentence. but make the OTHER words lowercase."}}
Capitalizes the first word of each sentence in a string and converts the rest of the sentence to lowercase.
// Result
Capitalize the first word in each sentence. But make the other words lowercase.
```
**Parameters**: none.
**Usage**:
{{sentence "capitalize the FIRST word in each sentence. but make the OTHER words lowercase."}}
**result**
Capitalize the first word in each sentence. But make the other words lowercase.
#### reverse
_Reverses a string._
<br>Parameters: `none`
``` handlebars
{{reverse "bender should NOT be allowed on TV."}}
Reverses a string.
// Result
.VT no dewolla eb TON dluohs redneb
```
**Parameters**: none.
**Usage**:
{{reverse "bender should NOT be allowed on TV."}}
**result**
.VT no dewolla eb TON dluohs redneb
#### truncate
_Truncates a string given a specified `length`, providing a custom string to denote an `omission`._
<br>Parameters:
Truncates a string given a specified `length`, providing a custom string to denote an `omission`.
* length: `int`- The number of characters to keep (Required).
* omission: `string` - A string to denote an omission (Optional).
**Parameters**:
``` handlebars
{{truncate "Bender should not be allowed on tv." 31 "..."}}
length [int] - The number of characters to keep (Required)
omission [string] - A string to denote an omission (Optional)
**Usage**:
// Result
Bender should not be allowed...
```
{{truncate "Bender should not be allowed on tv." 31 "..."}}
**result**
Bender should not be allowed...
#### center
_Centers a string using non-breaking spaces._
<br>Parameters: spaces: `int` - The number of spaces. (Required)
``` handlebars
{{center "Bender should not be allowed on tv." 10}}
Centers a string using non-breaking spaces.
**Parameters**:
spaces [int] - The number of spaces. (Required)
**Usage**:
{{center "Bender should not be allowed on tv." 10}}
**result**
```
// Result:
| Bender should not be allowed on tv. |
```
#### newLineToBr
#### nl2br
_Convert new lines (`\r\n`, `\n\r`, `\r`, `\n`) to line breaks_
<br>Parameters: `none`
``` handlebars
{{nl2br <br>description}}
Converts new line characters `\n` to line breaks `<br>`.
// Result:
<br>
```
**Parameters**: none.
**Usage**:
{{{newLineToBr "Bender \n should \n not \n be allowed on tv."}}}
**result**
Bender <br> should <br> not <br> be allowed on tv.
### Collections
#### first
_Returns the first item in a collection._
<br>Parameters: `none`
``` js
// Data
collection = [
'Amy Wong',
'Bender',
'Dr. Zoidberg',
'Fry',
'Hermes Conrad',
'Leela',
'Professor Farnsworth',
'Scruffy'
]
Returns the first item in a collection.
```
``` html
// Template
{{first collection}}
**Parameters**: none.
**Usage**:
// Result:
Amy Wong
```
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{first collection}}
**result**
Amy Wong
#### withFirst
_Use the first item in a collection inside a block._
<br>Parameters: `none`
``` js
// Data
collection = [
'Amy Wong',
'Bender',
'Dr. Zoidberg',
'Fry',
'Hermes Conrad',
'Leela',
'Professor Farnsworth',
'Scruffy'
]
```
``` html
// Template
{{#withFirst collection}}
<p>{{this}} is smart.</p>
{{/withFirst}}
Use the first item in a collection inside a block.
// Result:
<p>Amy Wong is smart.</p>
```
**Parameters**: none.
**Usage**:
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{#withFirst collection}}
<p>{{this}} is smart.</p>
{{/withFirst}}
**result**
<p>Amy Wong is smart.</p>
#### last
_Returns the last item in a collection. Opposite of `first`._
<br>Parameters: `none`
``` js
// Data
collection = [
'Amy Wong',
'Bender',
'Dr. Zoidberg',
'Fry',
'Hermes Conrad',
'Leela',
'Professor Farnsworth',
'Scruffy'
]
```
``` html
// Template
{{last collection}}
Returns the last item in a collection. Opposite of `first`.
// Result:
Scruffy
```
**Parameters**: none.
**Usage**:
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{last collection}}
**result**
Scruffy
#### withLast
_Use the last item in a collection inside a block. Opposite of `withFirst`._
<br>Parameters: `none`
``` js
// Data
collection = [
'Amy Wong',
'Bender',
'Dr. Zoidberg',
'Fry',
'Hermes Conrad',
'Leela',
'Professor Farnsworth',
'Scruffy'
]
```
``` html
// Template
{{#withLast collection}}
<p>{{this}} is lazy.</p>
{{/withLast}}
Use the last item in a collection inside a block. Opposite of `withFirst`.
// Result:
<p>Scruffy is lazy.</p>
```
**Parameters**: none.
**Usage**:
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{#withLast collection}}
<p>{{this}} is lazy.</p>
{{/withLast}}
**result**
<p>Scruffy is lazy.</p>
#### after
_Returns all of the items in the collection after the specified count._
<br>Parameters: count `int` - How many items to omit from the beginning. (Required)
```
// Date
collection = [
'Amy Wong',
'Bender',
'Dr. Zoidberg',
'Fry',
'Hermes Conrad',
'Leela',
'Professor Farnsworth',
'Scruffy'
]
```
``` html
// Template
{{after collection 5}}
Returns all of the items in the collection after the specified count.
// Result:
Leela, Professor Farnsworth, Scruffy
```
**Parameters**:
count [int] - How many items to omit from the beginning. (Required)
**Usage**:
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{after collection 5}}
**result**
Leela, Professor Farnsworth, Scruffy
#### withAfter
_Use all of the items in the collection after the specified count inside a block._
<br>Parameters: count `int` - How many items to omit from the beginning. (Required)
``` js
// Data
collection = [
'Amy Wong',
'Bender',
'Dr. Zoidberg',
'Fry',
'Hermes Conrad',
'Leela',
'Professor Farnsworth',
'Scruffy'
]
```
``` html
// Template
{{#withAfter collection 5}}
{{titleize this}}
{{/withAfter}}
Use all of the items in the collection after the specified count inside a block.
// Result:
Leela Professor Farnsworth Scruffy
```
**Parameters**:
count [int] - How many items to omit from the beginning. (Required)
**Usage**:
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{#withAfter collection 5}}
{{titleize this}}
{{/withAfter}}
**result**
Leela Professor Farnsworth Scruffy
#### before
_Returns all of the items in the collection before the specified count. Opposite of `after`._
<br>Parameters: count `int` - How many items to omit from the end. (Required)
``` js
// Data
collection = [
'Amy Wong',
'Bender',
'Dr. Zoidberg',
'Fry',
'Hermes Conrad',
'Leela',
'Professor Farnsworth',
'Scruffy'
]
```
``` html
// Template
{{before collection 5}}
Returns all of the items in the collection before the specified count. Opposite of `after`.
// Result:
Amy Wong, Bender, Dr. Zoidberg
```
**Parameters**:
count [int] - How many items to omit from the end. (Required)
**Usage**:
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{before collection 5}}
**result**
Amy Wong, Bender, Dr. Zoidberg
#### withBefore
_Use all of the items in the collection before the specified count inside a block. Opposite of `withAfter`._
<br>Parameters: count `int` - How many items to omit from the end. (Required)
``` js
// Data
collection = [
'Amy Wong',
'Bender',
'Dr. Zoidberg',
'Fry',
'Hermes Conrad',
'Leela',
'Professor Farnsworth',
'Scruffy'
]
```
``` html
// Template
{{#withBefore collection 5}}
{{reverse this}}
{{/withBefore}}
Use all of the items in the collection before the specified count inside a block. Opposite of `withAfter`.
// Result:
gnoW ymA redneB grebdioZ .rD
```
**Parameters**:
count [int] - How many items to omit from the end. (Required)
**Usage**:
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{#withBefore collection 5}}
{{reverse this}}
{{/withBefore}}
**result**
gnoW ymA redneB grebdioZ .rD
#### join
_Joins all elements of a collection into a string using a separator if specified._
<br>Parameters: separator `string` - A string to use as a separator between the items. (Optional)
``` js
// Data
collection = [
'Amy Wong',
'Bender',
'Dr. Zoidberg',
'Fry',
'Hermes Conrad',
'Leela',
'Professor Farnsworth',
'Scruffy'
]
```
``` html
// Template
{{join collection " & "}}
Joins all elements of a collection into a string using a separator if specified.
// Result:
Amy Wong & Bender & Dr. Zoidberg & Fry & Hermes Conrad & Leela & Professor Farnsworth & Scruffy
```
**Parameters**:
separator [string] - A string to use as a separator between the items. (Optional)
**Usage**:
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
{{join collection " & "}}
**result**
Amy Wong & Bender & Dr. Zoidberg & Fry & Hermes Conrad & Leela & Professor Farnsworth & Scruffy
#### sort
_Returns the collection sorted._
Parameters: `none`
``` js
// Data
collection = [
'Amy Wong',
'Bender',
'Dr. Zoidberg',
'Fry',
'Hermes Conrad',
'Leela',
'Professor Farnsworth',
'Scruffy'
]
```
``` html
// Template
{{sort collection}}
Returns the collection sorted.
// Result:
Amy Wong, Bender, Dr. Zoidberg, Fry, Hermes Conrad, Leela, Professor Farnsworth, Scruffy
```
**Parameters**:
none.
**Usage**:
collection = ['Dr. Zoidberg', 'Fry', 'Amy Wong', 'Professor Farnsworth', 'Bender', 'Hermes Conrad', 'Leela', 'Scruffy']
{{sort collection}}
**result**
Amy Wong, Bender, Dr. Zoidberg, Fry, Hermes Conrad, Leela, Professor Farnsworth, Scruffy
#### withSort
_Uses the sorted collection inside the block._
<br>Parameters: field `string` - String name of the field or property to sort by. (Optional)
``` js
// Data
collection = [
name: 'Leela'
deliveries: 8021,
Uses the sorted collection inside the block.
name: 'Bender'
deliveries: 239,
**Parameters**:
name: 'Fry'
deliveries: -12
]
field [string] - String name of the field or property to sort by. (Optional)
**Usage**:
```
``` html
// Template
{{#withSort collection "deliveries"}}
{{name}}: {{deliveries}} <br>
{{/withSort}}
collection = [
name: 'Leela'
deliveries: 8021
,
name: 'Bender'
deliveries: 239
,
name: 'Fry'
deliveries: -12
]
// Result:
Fry: -12
Bender: 239
Leela: 8021
```
{{#withSort collection "deliveries"}}
{{name}}: {{deliveries}} <br>
{{/withSort}}
**result**
Fry: -12
Bender: 239
Leela: 8021
#### length
_Returns the length of the collection._
<br>Parameters: `none`
``` js
// Data
collection = [
'Amy Wong',
'Bender',
'Dr. Zoidberg',
'Fry',
'Hermes Conrad',
'Leela',
'Professor Farnsworth',
'Scruffy'
]
Returns the length of the collection.
```
``` html
// Template
{{length collection}}
**Parameters**: none.
// Result:
8
```
collection = ['Dr. Zoidberg', 'Fry', 'Amy Wong', 'Professor Farnsworth', 'Bender', 'Hermes Conrad', 'Leela', 'Scruffy']
{{length collection}}
**result**
8
#### lengthEqual
_Conditionally render a block based on the length of a collection._
<br>Parameters: length `int` - The value to test against. (Required)
``` js
// Data
collection = [
name: 'Leela'
deliveries: 8021,
Conditionally render a block based on the length of a collection.
name: 'Bender'
deliveries: 239,
**Parameters**:
length [int] - The value to test against. (Required)
**Usage**:
collection = [
name: 'Leela'
deliveries: 8021
,
name: 'Bender'
deliveries: 239
,
name: 'Fry'
deliveries: -12
]
{{#lengthEqual collection 3}}
name: 'Fry'
deliveries: -12
]
```
``` html
// Template
{{#lengthEqual collection 3}}
There are 3 people in Planet Express.
{{else}}
{{else}}
This is not Planet Express.
{{/lengthEqual}}
{{/lengthEqual}}
**result**
There are 3 people in Planet Express.
// Result:
There are 3 people in Planet Express.
```
#### empty
Conditionally render a block if the collection is empty.
**Parameters**: none.
**Usage**:
collection = []
{{#empty collection}}
_Conditionally render a block if the collection is empty._
<br>Parameters: `none`
``` js
// Data
collection = []
```
``` html
// Template
{{#empty collection}}
Good news everyone!
{{else}}
{{else}}
Bad news everyone!
{{/empty}}
{{/empty}}
**result**
Good news everyone!
// Result:
Good news everyone!
```
#### any
Conditionally render a block if the collection isn't empty. Opposite of `empty`
**Parameters**: none.
**Usage**:
collection = ['Professor Farnsworth']
{{#any collection}}
_Conditionally render a block if the collection isn't empty. Opposite of `empty`_
<br>Parameters: `none`
``` js
// Data
collection = ['Professor Farnsworth']
```
``` html
// Templates
{{#any collection}}
Good news everyone!
{{else}}
{{else}}
Bad news everyone!
{{/any}}
{{/any}}
**result**
Good news everyone!
// Result:
Good news everyone!
```
#### inArray
Conditionally render a block if a specified value is in the collection.
**Parameters**:
value [string|int] - A value to test against. (Required)
**Usage**:
collection = ['Professor Farnsworth', 'Fry', 'Bender']
{{#inArray collection "Fry"}}
_Conditionally render a block if a specified value is in the collection._
<br>Parameters: value `string|int` - A value to test against. (Required)
``` js
// Data
collection = ['Professor Farnsworth', 'Fry', 'Bender']
```
``` html
// Templates
{{#inArray collection "Fry"}}
I'm walking on sunshine!
{{else}}
{{else}}
I'm walking on darkness.
{{/any}}
{{/any}}
**result**
I'm walking on sunshine!
// Result:
I'm walking on sunshine!
```
#### eachIndex
_Current implementation of the default Handlebars loop helper {{#each}} adding index (0-based index) to the loop context._
<br>Parameters: `none`
``` js
// Data
collection = ['Professor Farnsworth', 'Fry', 'Bender']
```
``` html
// Templates
{{#eachIndex collection}}
{{this}} is {{index}}
{{/eachIndex}}
Current implementation of the default Handlebars loop helper {{#each}} adding index (0-based index) to the loop context.
// Result:
Professor Farnsworth is 0, Fry is 1, Bender is 2
```
**Parameters**: none.
**Usage**:
#### eachProperty
_Loop through an objects properties_
<br>Parameters: `none`
``` js
// Data
TODO...
```
``` html
// Templates
{{#eachProperty object}}
{{property}}: {{value}}<br/>
{{/eachProperty }}
collection = ['Professor Farnsworth', 'Fry', 'Bender']
// Result
TODO...
```
{{#eachIndex collection}}
{{this}} is {{index}}
{{/eachIndex}}
**result**
Professor Farnsworth is 0, Fry is 1, Bender is 2
### Math
#### add
_Returns the sum of two numbers._
<br>Parameters: value `int` - The number to add to the expression. (Required)
``` js
// Data
value = 5
```
``` html
// Template
{{add value 5}}
Returns the sum of two numbers.
// Result:
10
```
**Parameters**:
value [int] - The number to add to the expression. (Required)
**Usage**:
value = 5
{{add value 5}}
**result**
10
#### subtract
_Returns the difference of two numbers. Opposite of `add`_
<br>Parameters: value `int` - The number to subtract from the expression. (Required)_
``` js
// Data
value = 5
```
``` html
// Template
{{subtract value 5}}
Returns the difference of two numbers. Opposite of `add`
// Result:
0
```
**Parameters**:
value [int] - The number to subtract from the expression. (Required)
**Usage**:
value = 5
{{subtract value 5}}
**result**
0
#### divide
_Returns the division of two numbers._
<br>Parameters: value `int` - The number to divide the expression. (Required)
``` js
// Data
value = 5
```
``` html
// Template
{{divide value 5}}
Returns the division of two numbers.
// Result:
1
```
**Parameters**:
value [int] - The number to divide the expression. (Required)
**Usage**:
value = 5
{{divide value 5}}
**result**
1
#### multiply
_Returns the multiplication of two numbers._
<br>Parameters: value `int` - The number to multiply the expression. (Required)
``` js
// Data
value = 5
Returns the multiplication of two numbers.
```
``` html
// Template
{{multiply value 5}}
**Parameters**:
// Result:
25
```
value [int] - The number to multiply the expression. (Required)
**Usage**:
value = 5
{{multiply value 5}}
**result**
25
#### floor
_Returns the value rounded down to the nearest integer._
<br>Parameters: `none`
``` js
// Data
value = 5.6
```
``` html
// Template
{{floor value}}
Returns the value rounded down to the nearest integer.
// Result:
5
```
**Parameters**: none.
**Usage**:
value = 5.6
{{floor value}}
**result**
5
#### ceil
_Returns the value rounded up to the nearest integer._
<br>Parameters: `none`
``` js
// Data
value = 5.6
```
``` html
// Template
{{ceil value}}
Returns the value rounded up to the nearest integer.
// Result:
6
```
**Parameters**: none.
**Usage**:
value = 5.6
{{ceil value}}
**result**
6
#### round
_Returns the value rounded to the nearest integer._
<br>Parameters: `none`
``` js
// Data
value = 5.69
```
``` html
// Template
{{round value}}
Returns the value rounded to the nearest integer.
// Result:
6
```
**Parameters**: none.
**Usage**:
value = 5.69
{{round value}}
**result**
6
### Numbers
#### toFixed
_Returns exactly `digits` after the decimal place. The number is rounded if necessary, and the fractional part is padded with zeros if necessary so that it has the specified length._
<br>Parameters: digits `int` - The number of digits to appear after the decimal point. (Optional)
``` js
// Data
value = 5.53231
```
``` html
// Template
{{toFixed value 3}}
Returns exactly `digits` after the decimal place. The number is rounded if necessary, and the fractional part is padded with zeros if necessary so that it has the specified length.
// Result:
5.532
```
**Parameters**:
digits [int] - The number of digits to appear after the decimal point. (Optional)
**Usage**:
value = 5.53231
{{toFixed value 3}}
**result**
5.532
#### toPrecision
_Returns the number in fixed-point or exponential notation rounded to `precision` significant digits._
<br>Parameters: precision `int` - The number of digits. If omitted, it returns the entire number (without any formatting). (Optional)
``` js
// Data
value = 555.322
```
``` html
// Template
{{toPrecision value 4}}
Returns the number in fixed-point or exponential notation rounded to `precision` significant digits.
// Result:
555.3
```
**Parameters**:
precision [int] - The number of digits. If omitted, it returns the entire number (without any formatting). (Optional)
**Usage**:
value = 555.322
{{toPrecision value 4}}
**result**
555.3
#### toExponential
_Returns the number in exponential notation with one digit before the decimal point, rounded to `fractions` digits after the decimal point._
<br>Parameters: fractions `int` - An integer specifying the number of digits after the decimal point. (Optional)
``` js
// Data
value = 5
Returns the number in exponential notation with one digit before the decimal point, rounded to `fractions` digits after the decimal point.
```
``` html
// Template
{{toExponential value 5}}
**Parameters**:
// Result:
5.00000e+0
```
fractions [int] - An integer specifying the number of digits after the decimal point. (Optional)
**Usage**:
value = 5
{{toExponential value 5}}
**result**
5.00000e+0
#### toInt
_Returns an integer._
<br>Parameters: `none`
``` js
// Data
value = '22.2abc'
```
``` html
// Template
{{toInt value}}
Returns an integer.
// Result:
22
```
**Parameters**: none.
**Usage**:
value = '22.2abc'
{{toInt value}}
**result**
22
#### toFloat
_Returns a floating point number._
<br>Parameters: `none`
``` js
// Data
value = '22.2abc'
```
``` html
// Template
{{toFloat value}}
Returns a floating point number.
// Result:
22.2
```
**Parameters**: none.
**Usage**:
value = '22.2abc'
{{toFloat value}}
**result**
22.2
#### addCommas
_Adds commas to a number._
<br>Parameters: `none`
``` js
// Data
value = 2222222
Adds commas to a number.
```
``` html
// Template
{{addCommas value}}
**Parameters**: none.
**Usage**:
// Result:
2,222,222
```
value = 2222222
{{addCommas value}}
### Comparisons: Equal
#### is
_Conditionally render a block if the condition is true (if x = y)._
**result**
2,222,222
Parameters: `string|int` (the value to test against)
Default: `undefined`
Example #1:
``` js
// Data
---
number = 5
---
```
``` html
// Template
{{#is number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/is}}
// Result:
Kiss my shiny metal ass!
```
### Comparisons
Example #2:
#### is
If you are using [Assemble](https://github.com/assemble/assemble), data from _YAML front matter_ or any specified `JSON` and/or `YAML` source files will get passed through to the context in your templates.
Conditionally render a block if the condition is true.
``` yaml
--- # YAML Front Matter
page:
title: About Us
---
```
``` html
{{#is page.title "home"}}
<h1> About Us </h1>
{{else}}
Never mind :(
{{/is}}
```
Result:
```
<h1> About Us </h1>
```
**Parameters**:
#### if_eq
**Same as `is`, consider consolidating**
_Conditionally render a block if the condition is true (If x = y)._
Parameters: `none`
``` handlebars
{{#if_eq x compare=y}} ... {{/if_eq}}
```
value [string|int] - the value to test against.
**Usage**:
#### isnt
_Conditionally render a block if the condition is false. Opposite of `is`._
<br>Parameters: value `string|int` - the value to test against.
``` js
// Data
number = 5
```
``` html
// Template
{{#isnt number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/isnt}}
number = 5
// Result:
Never mind :(
```
{{#is number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/is}}
**result**
#### or
_Conditionally render a block if one of the values is truthy._
<br>Parameters: values `string|int` - the values to test against.
``` js
great = no
magnificent = true
```
``` html
// Template
{{#or great magnificent}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/or}}
#### isnt
// Result:
Kiss my shiny metal ass!
```
Conditionally render a block if the condition is false. Opposite of `is`.
#### and
_Conditionally render a block if both values are truthy._
<br>Parameters: values `string|int` - the values to test against.
``` js
// Data
great = true
magnificent = true
```
``` html
// Template
{{#and great magnificent}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/and}}
**Parameters**:
// Result:
Kiss my shiny metal ass!
```
value [string|int] - the value to test against.
**Usage**:
#### unless_eq
**Same as `isnt`, consider consolidating**
_Conditionally render a block if the condition is false (Unless x = y). Opposite of `is`._
Parameters: `none`
``` handlebars
{{#unless_eq x compare=y}} ... {{/unless_eq}}
```
number = 5
{{#isnt number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/isnt}}
**result**
Never mind :(
### Comparisons: Greater Than
#### if_gt
_Conditionally render a block if the value is greater than a given number (If x > y)._
Parameters: `none`
``` handlebars
{{#if_gt x compare=y}} ... {{/if_gt}}
```
#### gt
**Same as `if_gt`, consider consolidating**
_Conditionally render a block if the value is greater than a given number (If x > y)._
<br>Parameters: value `string|int` - the value to test against.
``` js
// Data
number = 5
```
``` html
// Template
{{#gt number 8}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/gt}}
Conditionally render a block if the value is greater than a given number.
// Result:
Never mind :(
```
**Parameters**:
#### unless_gt
_Unless greater than (Unless x > y)_
Parameters: `none`
``` handlebars
{{#unless_gt x compare=y}} ... {{/unless_gt}}
```
value [string|int] - the value to test against.
**Usage**:
#### if_gteq
_Conditionally render a block if the value is greater or equal than a given number (If x >= y)._
Parameters: `none`
``` handlebars
{{#if_gteq x compare=y}} ... {{/if_gteq}}
```
number = 5
{{#gt number 8}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/gt}}
**result**
Never mind :(
#### gte
**Same as `if_gteq`, consider consolidating**
_Conditionally render a block if the value is greater or equal than a given number (If x >= y)._
<br>Parameters: value `string|int` - the value to test against.
Conditionally render a block if the value is greater or equal than a given number.
``` js
number = 5
```
``` html
// Template
{{#gte number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/gte}}
**Parameters**:
// Result:
Kiss my shiny metal ass!
```
value [string|int] - the value to test against.
**Usage**:
number = 5
#### unless_gteq
_Render block, unless given value is greater than or equal to._
Parameters: `none`
_Unless x >= y_
``` handlebars
{{#unless_gteq x compare=y}} ... {{/unless_gteq}}
```
{{#gte number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/gte}}
**result**
### Comparisons: Less Than
#### lt
_Conditionally render a block if the value is less than a given number. Opposite of `gt`._
<br>Parameters: value `string|int` - the value to test against.
``` js
number = 5
```
``` html
{{#lt number 3}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/lt}}
#### lt
// Result:
Never mind :(
```
Conditionally render a block if the value is less than a given number. Opposite of `gt`.
#### lte
_Conditionally render a block if the value is less or equal than a given number. Opposite of `gte`._
<br>Parameters: value `string|int` - the value to test against.
``` js
number = 5
```
``` html
// Template
{{#lte number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/lte}}
**Parameters**:
// Result:
Kiss my shiny metal ass!
```
value [string|int] - the value to test against.
**Usage**:
#### unless_lt
_Render block, unless value is less than a given number (Unless x < y)_
Parameters: `none`
``` handlebars
{{#unless_lt x compare=y}} ... {{/unless_lt}}
```
number = 5
#### unless_lteq
_Render block, unless value is less than or equal to a given number (Unless x <= y)_
Parameters: `none`
``` handlebars
{{#unless_lteq x compare=y}} ... {{/unless_lteq}}
```
{{#lt number 3}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/lt}}
**result**
Never mind :(
#### lte
### Dates
#### formatDate
_Formats a date into a string given a format. Accepts any value that can be passed to `new Date()`. This helper is a port of the [formatDate-js](http://https://github.com/michaelbaldry/formatDate-js) library by [Michael Baldry](https://github.com/michaelbaldry)._
<br>Parameters: format `string`, `required`
The format string, according to these tokens: [strftime](http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime)
``` js
// Data
date = new Date()
```
``` html
// Template
{{formatDate date "%m/%d/%Y"}}
{{formatDate date "%I:%M%p"}}
{{formatDate date "%F"}}
{{formatDate date "%Y%m%dT%H%M%S%z"}}
Conditionally render a block if the value is less or equal than a given number. Opposite of `gte`.
// Result:
07/26/2012
11:38PM
2012-07-26
20120726T233805-0004
```
**Parameters**:
#### now
_Returns the current date._
<br>Parameters: format `string` - The format string, according to these tokens: [http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime]() (Optional)
``` html
// Template
{{now}}
{{now "%m/%d/%Y"}}
value [string|int] - the value to test against.
**Usage**:
// Result:
Thu Jul 26 2012 23:41:02 GMT-0400 (AST)
07/26/2012
```
number = 5
#### timeago
_Returns a human-readable time phrase from the given date._
<br>Parameters: `none`
``` js
// Data
date = 'Thu Jul 22 2012 23:41:02 GMT-0400 (AST)'
```
``` html
// Template
{{timeago date}}
{{#lte number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/lte}}
// Result:
4 days ago
```
**result**
Kiss my shiny metal ass!
#### or
Conditionally render a block if one of the values is truthy.
### Inflections
#### inflect
_Returns the plural or singular form of a word based on a count._
<br>Parameters:
* singular `string` - The singular form of the word. (Required)
* plural `string` - The plural form of the word. (Required)
* include `boolean` - whether or not to include the count before the word. (Optional)
``` js
// Data
enemies = 0
friends = 1
```
``` html
// Template
{{inflect enemies "enemy" "enemies"}}
{{inflect friends "friend" "friends" true}}
**Parameters**:
// Result:
enemies
1 friend
values [string|int] - the values to test against.
**Usage**:
#### ordinalize
_Turns a number into an ordinal string. Taken from the templating library [Walrus](https://github.com/jeremyruppel/walrus) by [Jeremy Ruppel](https://github.com/jeremyruppel)._
<br>Parameters: `none`
``` html
// Template
{{ordinalize 3}}
{{ordinalize 1}}
{{ordinalize 22}}
great = no
magnificent = true
// Result:
3rd
1st
22nd
```
{{#or great magnificent}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/or}}
**result**
Kiss my shiny metal ass!
### HTML
#### 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.._
#### and
Parameters: `String`
Default: `undefined`
Usage: `{{ gist [id] }}`
Conditionally render a block if both values are truthy.
Example:
``` hbs
{{gist '5193239'}}
```
Result:
``` html
<script src="https://gist.github.com/5193239.js"></script>
```
**Parameters**:
#### embed
_Embed Code Snippets_
values [string|int] - the values to test against.
**Usage**:
Embed code snippets from any file with the `embed` variable. You can also pass in a second parameter to force syntax highlighting for a specific language.
great = true
magnificent = true
Parameters: `String|String (optional)`
Default: `undefined`
Syntax: `{{ embed [filename] [syntax] }}`
{{#and great magnificent}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/and}}
Example:
``` hbs
{{ embed 'src/test.json' }}
```
**result**
Kiss my shiny metal ass!
Forced highlighting:
``` hbs
{{ embed 'src/test.json' 'javascript' }}
```
In the second example, highlighting was forced as `javascript` instead of `json`.
### Dates
#### formatDate
#### blockquote
_Create a blockquote_
Formats a date into a string given a format. Accepts any value that can be passed to `new Date()`. This helper is a port of the [formatDate-js](http://https://github.com/michaelbaldry/formatDate-js) library by [Michael Baldry](https://github.com/michaelbaldry).
Outputs a string with a given attribution as a quote
**Parameters**:
``` hbs
{{#blockquote '@doowb' 'http://github.com/source/for/your/quote' 'This is the title' }}
This is your quote.
{{/blockquote}}
```
results in:
format [string] - The format string, according to these tokens: (http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime) (Required)
**Usage**:
``` html
<blockquote>
<p>This is your quote.</p>
<footer>
<strong>@doowb</strong>
<cite>
<a href="http://github.com/source/for/your/quote">This is the title</a>
</cite>
</footer>
</blockquote>
```
#### stripes
_Iterates through an array, letting the contents know whether to add an even or odd row._
date = new Date()
Parameters:
{{formatDate date "%m/%d/%Y"}}
{{formatDate date "%I:%M%p"}}
{{formatDate date "%F"}}
{{formatDate date "%Y%m%dT%H%M%S%z"}}
* `array` to iterate over,
* `string`: CSS class name for even rows
* `string`: CSS class name for odd rows
**result**
07/26/2012
11:38PM
2012-07-26
20120726T233805-0004
Credit: [treehouse blog](http://blog.teamtreehouse.com/handlebars-js-part-2-partials-and-helpers)
#### now
Usage:
``` handlebars
{{#stripes myArray "even" "odd"}}
<div class="{{stripeClass}}">
... code for the row ...
</div>
{{else}}
<em>There aren't any people.</em>
{{/stripes}}
```
Returns the current date.
#### timeline
_Iterates through an array, letting the contents know whether a timeline entry belongs in the left or right column._
**Parameters**:
Parameters:
format [string] - The format string, according to these tokens: http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime (Optional)
**Usage**:
* `array` to iterate over,
* `string`: CSS class name for left columns
* `string`: CSS class name for right columns
{{now}}
{{now "%m/%d/%Y"}}
Credit: by [@jonschlinkert](http://github.com/jonschlinkert), and based on striped helper from [treehouse blog](http://blog.teamtreehouse.com/handlebars-js-part-2-partials-and-helpers)
**result**
Thu Jul 26 2012 23:41:02 GMT-0400 (AST)
07/26/2012
Usage:
``` handlebars
<div class="timeline">
{{#timeline myArray "left" "right"}}
<div class="{{columnClass}}">
{{> entry}}
</div>
{{else}}
<em>There aren't any entries.</em>
{{/timeline}}
</div>
```
#### timeago
#### ul
_Creates an unordered list._
Returns a human-readable time phrase from the given date.
Parameters: `Hash|HTML attributes`, `Optional`
**Parameters**: none.
**Usage**:
HTML attributes to use on the `ul` element.
``` js
// Data
collection = [
name: 'Leela'
deliveries: 8021,
name: 'Bender'
deliveries: 239,
name: 'Fry'
deliveries: 1
]
```
Template:
``` handlebars
{{#ul collection class="deliveries-list"}}
{{name}} - {{inflect deliveries "delivery" "deliveries" true}}
{{/ul}}
```
``` html
// Result:
<ul class="deliveries-list">
<li> Leela - 8021 deliveries </li>
<li> Bender - 239 deliveries </li>
<li> Fry - 1 delivery </li>
</ul>
```
#### ol
_Same as the `ul` helper but creates and ordered list. Returns `<br>` tags based on a count._
date = 'Thu Jul 22 2012 23:41:02 GMT-0400 (AST)'
Parameters: `Hash`, `HTML attributes`, `Optional`
{{timeago date}}
HTML attributes to use on the `ol` element.
``` js
// Data
collection = [
name: 'Leela'
deliveries: 8021,
name: 'Bender'
deliveries: 239,
name: 'Fry'
deliveries: 1
]
```
**result**
4 days ago
Template:
``` handlebars
{{#ol collection class="deliveries-list"}}
{{name}} - {{inflect deliveries "delivery" "deliveries" true}}
{{/ol}}
```
``` html
// Result:
<ol class="deliveries-list">
<li> Leela - 8021 deliveries </li>
<li> Bender - 239 deliveries </li>
<li> Fry - 1 delivery </li>
</ol>
```
### Inflections
#### br
_Renders `<br>` elements in the output, based on the number given as a parameter. Not really recommended for general use, but it's here if you need it._
#### inflect
Parameters: `Integer|Count`, `Optional`
Returns the plural or singular form of a word based on a count.
The number of `br` elements to render.
**Parameters**:
`template.hbs`
``` handlebars
{{br 5}}
```
renders to:
``` html
`<br><br><br><br><br>`
```
singular [string] - The singular form of the word. (Required)
plural [string] - The plural form of the word. (Required)
include [boolean] - whether or not to include the count before the word. (Optional)
**Usage**:
enemies = 0
friends = 1
### Logging
#### log
_Simple `console.log()`_
<br>Parameters: `none`
``` html
// Template
{{log "Hi console :)"}}
{{inflect enemies "enemy" "enemies"}}
{{inflect friends "friend" "friends" true}}
// Result:
Hi console :)
```
**result**
enemies
1 friend
#### debug
_Simple `console.debug()` that shows the current context._
<br>Parameters: `none`
``` js
// Data
collection = [
name: 'Leela'
deliveries: 8021,
name: 'Bender'
deliveries: 239,
name: 'Fry'
deliveries: 1
]
```
``` html
// Template
{{#withFirst collection}}
{{debug name}}
{{/withFirst}}
#### ordinalize
// Result:
Context: { deliveries: 8021, name: "Leela" }
Value: Leela
```
Turns a number into an ordinal string. Taken from the templating library [Walrus](https://github.com/jeremyruppel/walrus) by [Jeremy Ruppel](https://github.com/jeremyruppel).
**Parameters**: none.
**Usage**:
### Miscellaneous
#### default
_Provides a default or fallback value if a value doesn't exist._
<br>Parameters: defaultValue `string|int` - The default value to use. `title = ''`
{{ordinalize 3}}
{{ordinalize 1}}
{{ordinalize 22}}
``` html
// Template
{{default title "Not title available."}}
**result**
3rd
1st
22nd
// Result:
Not title available.
```
### HTML
#### include
_Provides an easy way to register and use partials inside your templates._
#### ul
This helper only works if you define your templates as common.js modules, since it uses the common.js `require` function to find and register your templates with `Handlebars.registerPartial`.
Creates an unordered list.
<br>Pattern: `{{include [name] [data]}}`
<br>Parameters:
**Parameters**:
* name (required): `[string]` - The name or path of the file in which your template is defined. (Required)
* data (optional): `[int|string|collection]` - Data you want to use inside the include.
hash [html attributes] - HTML attributes to use on the ul element. (Optional)
**Usage**:
Data (collection): `planet-express.json`
collection = [
name: 'Leela'
deliveries: 8021
,
name: 'Bender'
deliveries: 239
,
name: 'Fry'
deliveries: 1
]
``` js
[
"Professor Farnsworth",
"Fry",
"Bender"
]
```
{{#ul collection class="deliveries-list"}}
{{name}} - {{inflect deliveries "delivery" "deliveries" true}}
{{/ul}}
Include (partial to be "included"): `planet-express.hbs`
``` html
{{sort this}}
```
**result**
<ul class="deliveries-list">
<li>
Leela - 8021 deliveries
</li>
<li>
Bender - 239 deliveries
</li>
<li>
Fry - 1 delivery
</li>
</ul>
Template:
``` html
<p>{{include "planet-express.hbs" data}}</p>
```
#### ol
Result:
``` html
<p>Bender, Fry, Professor Farnsworth</p>
```
Same as the `ul` helper but creates and ordered list.
#### br
Returns `<br>` tags based on a count.
**Parameters**:
## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
count [int] - The number of `br` elements to render. (Optional)
**Usage**:
{{br 5}}
**result**
<br><br><br><br><br>
## Authors
### Logging
**Jon Schlinkert**
#### log
+ [http://twitter.com/jonschlinkert](http://twitter.com/jonschlinkert)
+ [http://github.com/jonschlinkert](http://github.com/jonschlinkert)
Simple console.log()
**Brian Woodward**
**Parameters**: none.
**Usage**:
+ [http://twitter.com/doowb](http://twitter.com/doowb)
+ [http://github.com/doowb](http://github.com/doowb)
{{log "Hi console :)"}}
**result**
Hi console :)
## Credit
> Many of these helpers come from the following repos:
#### debug
* [Handlebars Helpers, by Dan Harper](http://github.com/danharper)
* [Swag v0.2.1, by Elving Rodriguez](http://elving.github.com/swag/)
Simple console.debug() that shows the current context.
**Parameters**: none.
**Usage**:
## Copyright and license
Copyright NaN Assemble
collection = [
name: 'Leela'
deliveries: 8021
,
name: 'Bender'
deliveries: 239
,
name: 'Fry'
deliveries: 1
]
[MIT License](LICENSE-MIT)
{{#withFirst collection}}
{{debug name}}
{{/withFirst}}
## Release History
* 2013-04-07 v0.1.21 Add markdown helpers back, add more tests.
* 2013-04-06 v0.1.20 Generalized helpers structure, externalized utilities.
* 2013-04-05 v0.1.11 New authors and gist helpers, general cleanup and new tests.
* 2013-04-04 v0.1.10 Externalized utility javascript from helpers.js
* 2013-03-28 v0.1.8 Gruntfile updated with mocha tests for 71 helpers, bug fixes.
* 2013-03-18 v0.1.7 New path helper "relative", for resolving relative path from one absolute path to another.
* 2013-03-16 v0.1.3 New helpers, "formatPhoneNumber" and "eachProperty"
* 2013-03-15 v0.1.2 Update README.md with documentation, examples.
* 2013-03-06 v0.1.0 First commit.
**result**
Context: { deliveries: 8021, name: "Leela" }
Value: Leela
-----------------------------------------------
### Miscellaneous
### Roadmap
* Separate into modules
* YAML format, use templates for easier maintenance
#### default
Provides a default or fallback value if a value doesn't exist.
---
Authored by [assemble](https://github.com/assemble/assemble)
**Parameters**:
_This file was generated using Grunt and [assemble](http://github.com/assemble/assemble) on Fri Apr 19 2013 16:08:16._
defaultValue [string|int] - The default value to use.
**Usage**:
title = ''
{{default title "Not title available."}}
**result**
Not title available.
[download]: https://github.com/assemble/helper-lib/zipball/master
#### partial
Provides an easy way to register and use partials inside your templates. This helper only works if you define your templates as common.js modules, since it uses the common.js `require` function to find and register your templates with `Handlebars.registerPartial`. It was created with [brunch](http://brunch.io) in mind (which I use a lot), because brunch automatically wraps your scripts and templates in common.js modules to use in the browser.
[org]: https://github.com/assemble
[assemble]: https://github.com/assemble/assemble
[issues]: https://github.com/assemble/assemble/issues
[wiki]: https://github.com/assemble/assemble/wiki
**Parameters**:
name [string] - The name or path of the file in which your template is defined. (Required)
data [int|string|collection] - The data you want to use inside the partial. (Optional)
**Usage**:
[config]: https://github.com/assemble/assemble/wiki/Configuration
[gruntfile]: https://github.com/assemble/assemble/wiki/Gruntfile
[tasks]: https://github.com/assemble/assemble/wiki/Task-and-Targets
[options]: https://github.com/assemble/assemble/wiki/Options
# Path to your templates from where you override config.partialsPath
# The path must finish with a foward slash '/'
config.partialsPath = '../views/templates/'
collection = ['Professor Farnsworth', 'Fry', 'Bender']
[templates]: https://github.com/assemble/assemble/wiki/Templates
[layouts]: https://github.com/assemble/assemble/wiki/Layouts
[pages]: https://github.com/assemble/assemble/wiki/Pages
[partials]: https://github.com/assemble/assemble/wiki/Partials
# Your Partial (planet_express.hbs)
{{sort this}}
# Your template
<p>
{{partial "planet_express" collection}}
</p>
[content]: https://github.com/assemble/assemble/wiki/Content
[data]: https://github.com/assemble/assemble/wiki/Data
[yaml]: https://github.com/assemble/assemble/wiki/YAML-front-matter
[markdown]: https://github.com/assemble/assemble/wiki/Markdown
**result**
<p>Bender, Fry, Professor Farnsworth</p>
[helpers]: https://github.com/assemble/assemble/wiki/Helpers
[assets]: https://github.com/assemble/assemble/wiki/Assets
[collections]: https://github.com/assemble/assemble/wiki/Collections
## Credit
[examples]: https://github.com/assemble/assemble-examples
[exampleReadme]: https://github.com/assemble/assemble-examples-readme
[exampleBasic]: https://github.com/assemble/assemble-examples-basic
[exampleAdvanced]: https://github.com/assemble/assemble-examples-advanced
[exampleGrid]: https://github.com/assemble/assemble-examples-grid
[exampleTable]: https://github.com/assemble/assemble-examples-table
[exampleForm]: https://github.com/assemble/assemble-examples-form
[exampleSite]: https://github.com/assemble/assemble-examples-site
[exampleSitemap]: https://github.com/assemble/assemble-examples-sitemap
Many of these helpers come from the following repos:
* [Handlebars Helpers, by Dan Harper](http://github.com/danharper)
* [Swag v0.2.1, by Elving Rodriguez](http://elving.github.com/swag/)
[contribute]: https://github.com/assemble/assemble/wiki/Contributing-to-Assemble
[extend]: https://github.com/assemble/assemble/wiki/Extending-Assemble
[helpers-lib]: https://github.com/assemble/assemble/wiki/Helpers
[grunt]: http://gruntjs.com/
[upgrading]: http://gruntjs.com/upgrading-from-0.3-to-0.4
[getting-started]: http://gruntjs.com/getting-started
[package]: https://npmjs.org/doc/json.html
## Examples
_(Coming soon)_
## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
## Release History
_(Nothing yet)_
## License
Copyright (c) 2013 Jon Schlinkert
Licensed under the MIT license.
[assemble]: https://github.com/assemble/assemble
[pre]: https://github.com/assemble/pre
[dry]: https://github.com/assemble/dry
[assemble-github-com]: https://github.com/assemble/assemble.github.com
[assemble-examples-bootstrap]: https://github.com/assemble/assemble-examples-bootstrap
[assemble-internal]: https://github.com/assemble/assemble-internal
[assemble-less]: https://github.com/assemble/assemble-less
[assemble-examples-readme]: https://github.com/assemble/assemble-examples-readme
[grunt-toc]: https://github.com/assemble/grunt-toc
[helper-lib]: https://github.com/assemble/helper-lib
[grunt-dry]: https://github.com/assemble/grunt-dry
[assemble-examples]: https://github.com/assemble/assemble-examples
# Helpers Library
> A growing collection of useful helpers for Assemble.
## Handlebars
[Handlebars.js](https://github.com/wycats/handlebars.js) is currently the default template library for [assemble](http://github.com/assemble/assemble).
### Equals
#### If x Equals y
Parameters: `none`
``` handlebars
{{#if_eq x compare=y}} ... {{/if_eq}}
```
#### Unless x Equals y
Parameters: `none`
``` handlebars
{{#unless_eq x compare=y}} ... {{/unless_eq}}
```
### Greater Than
#### If x > y
Parameters: `none`
``` handlebars
{{#if_gt x compare=y}} ... {{/if_gt}}
```
#### Unless x > y
Parameters: `none`
``` handlebars
{{#unless_gt x compare=y}} ... {{/unless_gt}}
```
### Greater Than or Equal To
#### If x >= y
Parameters: `none`
``` handlebars
{{#if_gteq x compare=y}} ... {{/if_gteq}}
```
#### Unless x >= y
Parameters: `none`
``` handlebars
{{#unless_gteq x compare=y}} ... {{/unless_gteq}}
```
### Less Than
#### If x < y
Parameters: `none`
``` handlebars
{{#if_lt x compare=y}} ... {{/if_lt}}
```
#### Unless x < y
Parameters: `none`
``` handlebars
{{#unless_lt x compare=y}} ... {{/unless_lt}}
```
### Less Than or Equal To
#### If x <= y
Parameters: `none`
``` handlebars
{{#if_lteq x compare=y}} ... {{/if_lteq}}
```
#### Unless x <= y
Parameters: `none`
``` handlebars
{{#unless_lteq x compare=y}} ... {{/unless_lteq}}
```
### Strings
#### hyphenate
Parameters: `none`
<br>Description: _Replace spaces in string with hyphens._
``` handlebars
{{hyphenate "make this all hyphenated"}}
// Result
make-this-all-hyphenated
```
#### dashify
Parameters: `none`
<br>Description: _Same as `hyphenate`, but replaces dots in string with hyphens._
``` handlebars
{{dashify "make.this.all.hyphenated"}}
// Result
make-this-all-hyphenated
```
#### lowercase
Parameters: `none`
<br>Description: _Turns a string to lowercase._
``` handlebars
{{lowercase "MAKE THIS ALL LOWERCASE"}}
// Result
make this all lowercase
```
#### uppercase
Parameters: `none`
<br>Description: Turns a string to uppercase. Opposite of `{{lowercase}}`.
``` handlebars
{{uppercase "make this all uppercase"}}
// Result
MAKE THIS ALL UPPERCASE
```
#### capitalizeFirst
Parameters: `none`
<br>Description: Capitalizes the first word in a string.
``` handlebars
{{capitalizeFirst "capitalize first word in this sentence"}}
// Result
Capitalize first word in this sentence
```
#### capitalizeEach
Parameters: `none`
<br>Description: Capitalizes each word in a string.
``` handlebars
{{capitalizeEach "capitalize EACH word in this sentence"}}
// Result
Capitalize EACH Word In This Sentence
```
#### titleize
Parameters: `none`
Description: Capitalizes all words within a string. Taken from the templating library [Walrus](https://github.com/jeremyruppel/walrus) by [Jeremy Ruppel](https://github.com/jeremyruppel).
``` handlebars
{{titleize "capitalize EACH word in this sentence"}}
// Result
Capitalize Each Word In This Sentence.
```
#### sentence
Parameters: `none`
Description: Capitalizes the first word of each sentence in a string and converts the rest of the sentence to lowercase.
``` handlebars
{{sentence "capitalize the FIRST word in each sentence. but make the OTHER words lowercase."}}
// Result
Capitalize the first word in each sentence. But make the other words lowercase.
```
#### reverse
Parameters: `none`
Description: Reverses a string.
``` handlebars
{{reverse "bender should NOT be allowed on TV."}}
// Result
.VT no dewolla eb TON dluohs redneb
```
#### truncate
Parameters:
<br>length: `int`- The number of characters to keep (Required).
<br>omission: `string` - A string to denote an omission (Optional).
<br>Description: Truncates a string given a specified `length`, providing a custom string to denote an `omission`.
``` handlebars
{{truncate "Bender should not be allowed on tv." 31 "..."}}
// Result
Bender should not be allowed...
```
#### center
Parameters:
<br>spaces: `int` - The number of spaces. (Required)
<br>Description: Centers a string using non-breaking spaces.
``` handlebars
{{center "Bender should not be allowed on tv." 10}}
// Result:
| Bender should not be allowed on tv. |
```
#### newLineToBr
Parameters: `none`
<br>Description: Converts new line characters `\n` to line breaks `<br>`.
```
{{{newLineToBr "Bender \n should \n not \n be allowed on tv."}}}
// Result:
Bender <br> should <br> not <br> be allowed on tv.
````
#### nl2br
Parameters: `none`
<br>Description: Convert new lines (`\r\n`, `\n\r`, `\r`, `\n`) to line breaks
``` handlebars
{{nl2br description}}
// Result:
<br>
```
### Collections
#### first
Parameters: `none`
<br>Description: Returns the first item in a collection.
```
// Data
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
// Template
{{first collection}}
// Result:
Amy Wong
```
#### withFirst
Parameters: `none`
<br>Description: Use the first item in a collection inside a block.
```
// Data
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
// Template
{{#withFirst collection}}
<p>{{this}} is smart.</p>
{{/withFirst}}
// Result:
<p>Amy Wong is smart.</p>
```
#### last
Parameters: `none`
<br>Description: Returns the last item in a collection. Opposite of `first`.
```
// Data
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
// Template
{{last collection}}
// Result:
Scruffy
```
#### withLast
Parameters: `none`
<br>Description: Use the last item in a collection inside a block. Opposite of `withFirst`.
```
// Data
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
// Template
{{#withLast collection}}
<p>{{this}} is lazy.</p>
{{/withLast}}
// Result:
<p>Scruffy is lazy.</p>
```
#### after
Parameters:
<br>count `int` - How many items to omit from the beginning. (Required)
<br>Description: Returns all of the items in the collection after the specified count.
```
// Date
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
// Template
{{after collection 5}}
// Result:
Leela, Professor Farnsworth, Scruffy
```
#### withAfter
Parameters:
<br>count `int` - How many items to omit from the beginning. (Required)
<br>Description: Use all of the items in the collection after the specified count inside a block.
```
// Data
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
// Template
{{#withAfter collection 5}}
{{titleize this}}
{{/withAfter}}
// Result:
Leela Professor Farnsworth Scruffy
```
#### before
Parameters:
<br>count `int` - How many items to omit from the end. (Required)
<br>Description: Returns all of the items in the collection before the specified count. Opposite of `after`.
```
// Data
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
// Template
{{before collection 5}}
// Result:
Amy Wong, Bender, Dr. Zoidberg
```
#### withBefore
Parameters:
<br>count `int` - How many items to omit from the end. (Required)
<br>Description: Use all of the items in the collection before the specified count inside a block. Opposite of `withAfter`.
```
// Data
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
// Template
{{#withBefore collection 5}}
{{reverse this}}
{{/withBefore}}
// Result:
gnoW ymA redneB grebdioZ .rD
```
#### join
Parameters:
<br>separator `string` - A string to use as a separator between the items. (Optional)
<br>Description: Joins all elements of a collection into a string using a separator if specified.
``` handlebars
// Data
collection = ['Amy Wong', 'Bender', 'Dr. Zoidberg', 'Fry', 'Hermes Conrad', 'Leela', 'Professor Farnsworth', 'Scruffy']
// Template
{{join collection " & "}}
// Result:
Amy Wong & Bender & Dr. Zoidberg & Fry & Hermes Conrad & Leela & Professor Farnsworth & Scruffy
```
#### sort
Parameters: `none`
<br>Description: Returns the collection sorted.
```
// Data
collection = ['Dr. Zoidberg', 'Fry', 'Amy Wong', 'Professor Farnsworth', 'Bender', 'Hermes Conrad', 'Leela', 'Scruffy']
// Template
{{sort collection}}
// Result:
Amy Wong, Bender, Dr. Zoidberg, Fry, Hermes Conrad, Leela, Professor Farnsworth, Scruffy
```
#### withSort
Parameters:
<br>field `string` - String name of the field or property to sort by. (Optional)
<br>Description: Uses the sorted collection inside the block.
```
// Data
collection = [
name: 'Leela'
deliveries: 8021,
name: 'Bender'
deliveries: 239,
name: 'Fry'
deliveries: -12
]
// Template
{{#withSort collection "deliveries"}}
{{name}}: {{deliveries}} <br>
{{/withSort}}
// Result:
Fry: -12
Bender: 239
Leela: 8021
```
#### length
Parameters: `none`
<br>Description: Returns the length of the collection.
```
// Data
collection = ['Dr. Zoidberg', 'Fry', 'Amy Wong', 'Professor Farnsworth', 'Bender', 'Hermes Conrad', 'Leela', 'Scruffy']
// Template
{{length collection}}
// Result:
8
```
#### lengthEqual
Parameters:
<br>length `int` - The value to test against. (Required)
<br>Description: Conditionally render a block based on the length of a collection.
```
// Data
collection = [
name: 'Leela'
deliveries: 8021,
name: 'Bender'
deliveries: 239,
name: 'Fry'
deliveries: -12
]
// Template
{{#lengthEqual collection 3}}
There are 3 people in Planet Express.
{{else}}
This is not Planet Express.
{{/lengthEqual}}
// Result:
There are 3 people in Planet Express.
```
#### empty
Parameters: `none`
<br>Description: Conditionally render a block if the collection is empty.
```
// Data
collection = []
// Template
{{#empty collection}}
Good news everyone!
{{else}}
Bad news everyone!
{{/empty}}
// Result:
Good news everyone!
```
#### any
Parameters: `none`
<br>Description: Conditionally render a block if the collection isn't empty. Opposite of `empty`
```
// Data
collection = ['Professor Farnsworth']
// Templates
{{#any collection}}
Good news everyone!
{{else}}
Bad news everyone!
{{/any}}
// Result:
Good news everyone!
```
#### inArray
Parameters:
<br>value `string|int` - A value to test against. (Required)
<br>Description: Conditionally render a block if a specified value is in the collection.
```
// Data
collection = ['Professor Farnsworth', 'Fry', 'Bender']
// Templates
{{#inArray collection "Fry"}}
I'm walking on sunshine!
{{else}}
I'm walking on darkness.
{{/any}}
// Result:
I'm walking on sunshine!
```
#### eachIndex
Parameters: `none`
<br>Description: Current implementation of the default Handlebars loop helper {{#each}} adding index (0-based index) to the loop context.
```
// Data
collection = ['Professor Farnsworth', 'Fry', 'Bender']
// Templates
{{#eachIndex collection}}
{{this}} is {{index}}
{{/eachIndex}}
// Result:
Professor Farnsworth is 0, Fry is 1, Bender is 2
```
### Math
#### add
Parameters:
<br>value `int` - The number to add to the expression. (Required)
<br>Description: Returns the sum of two numbers.
```
// Data
value = 5
// Template
{{add value 5}}
// Result:
10
```
#### subtract
Parameters:
<br>value `int` - The number to subtract from the expression. (Required)
<br>Description: Returns the difference of two numbers. Opposite of `add`
```
// Data
value = 5
// Template
{{subtract value 5}}
// Result
Result:
0
```
#### divide
Returns the division of two numbers.
Parameters:
value `int` - The number to divide the expression. (Required)
<br>Example:
value = 5
{{divide value 5}}
Result:
1
#### multiply
Returns the multiplication of two numbers.
Parameters:
value `int` - The number to multiply the expression. (Required)
<br>Example:
value = 5
{{multiply value 5}}
Result:
25
#### floor
Returns the value rounded down to the nearest integer.
Parameters: `none`
<br>Example:
value = 5.6
{{floor value}}
Result:
5
#### ceil
Returns the value rounded up to the nearest integer.
Parameters: `none`
<br>Example:
value = 5.6
{{ceil value}}
Result:
6
#### round
Returns the value rounded to the nearest integer.
Parameters: `none`
<br>Example:
value = 5.69
{{round value}}
Result:
6
### Numbers
#### toFixed
Returns exactly `digits` after the decimal place. The number is rounded if necessary, and the fractional part is padded with zeros if necessary so that it has the specified length.
Parameters:
digits `int` - The number of digits to appear after the decimal point. (Optional)
<br>Example:
value = 5.53231
{{toFixed value 3}}
Result:
5.532
#### toPrecision
Returns the number in fixed-point or exponential notation rounded to `precision` significant digits.
Parameters:
precision `int` - The number of digits. If omitted, it returns the entire number (without any formatting). (Optional)
<br>Example:
value = 555.322
{{toPrecision value 4}}
Result:
555.3
#### toExponential
Returns the number in exponential notation with one digit before the decimal point, rounded to `fractions` digits after the decimal point.
Parameters:
fractions `int` - An integer specifying the number of digits after the decimal point. (Optional)
<br>Example:
value = 5
{{toExponential value 5}}
Result:
5.00000e+0
#### toInt
Returns an integer.
Parameters: `none`
<br>Example:
value = '22.2abc'
{{toInt value}}
Result:
22
#### toFloat
Returns a floating point number.
Parameters: `none`
<br>Example:
value = '22.2abc'
{{toFloat value}}
Result:
22.2
#### addCommas
Adds commas to a number.
Parameters: `none`
<br>Example:
value = 2222222
{{addCommas value}}
Result:
2,222,222
### Comparisons
#### is
Conditionally render a block if the condition is true.
Parameters:
value `string|int` - the value to test against.
<br>Example:
number = 5
{{#is number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/is}}
Result:
Kiss my shiny metal ass!
#### isnt
Conditionally render a block if the condition is false. Opposite of `is`.
Parameters:
value `string|int` - the value to test against.
<br>Example:
number = 5
{{#isnt number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/isnt}}
Result:
Never mind :(
#### gt
Conditionally render a block if the value is greater than a given number.
Parameters:
value `string|int` - the value to test against.
<br>Example:
number = 5
{{#gt number 8}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/gt}}
Result:
Never mind :(
#### gte
Conditionally render a block if the value is greater or equal than a given number.
Parameters:
value `string|int` - the value to test against.
<br>Example:
number = 5
{{#gte number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/gte}}
Result:
Kiss my shiny metal ass!
#### lt
Conditionally render a block if the value is less than a given number. Opposite of `gt`.
Parameters:
value `string|int` - the value to test against.
<br>Example:
number = 5
{{#lt number 3}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/lt}}
Result:
Never mind :(
#### lte
Conditionally render a block if the value is less or equal than a given number. Opposite of `gte`.
Parameters:
value `string|int` - the value to test against.
<br>Example:
number = 5
{{#lte number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/lte}}
Result:
Kiss my shiny metal ass!
#### or
Conditionally render a block if one of the values is truthy.
Parameters:
values `string|int` - the values to test against.
<br>Example:
great = no
magnificent = true
{{#or great magnificent}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/or}}
Result:
Kiss my shiny metal ass!
#### and
Conditionally render a block if both values are truthy.
Parameters:
values `string|int` - the values to test against.
<br>Example:
great = true
magnificent = true
{{#and great magnificent}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/and}}
Result:
Kiss my shiny metal ass!
### Dates
#### formatDate
Formats a date into a string given a format. Accepts any value that can be passed to `new Date()`. This helper is a port of the [formatDate-js](http://https://github.com/michaelbaldry/formatDate-js) library by [Michael Baldry](https://github.com/michaelbaldry).
Parameters:
format `string` - The format string, according to these tokens: (http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime) (Required)
<br>Example:
date = new Date()
{{formatDate date "%m/%d/%Y"}}
{{formatDate date "%I:%M%p"}}
{{formatDate date "%F"}}
{{formatDate date "%Y%m%dT%H%M%S%z"}}
Result:
07/26/2012
11:38PM
2012-07-26
20120726T233805-0004
#### now
Returns the current date.
Parameters:
format `string` - The format string, according to these tokens: http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime (Optional)
<br>Example:
{{now}}
{{now "%m/%d/%Y"}}
Result:
Thu Jul 26 2012 23:41:02 GMT-0400 (AST)
07/26/2012
#### timeago
Returns a human-readable time phrase from the given date.
Parameters: `none`
<br>Example:
date = 'Thu Jul 22 2012 23:41:02 GMT-0400 (AST)'
{{timeago date}}
Result:
4 days ago
### Inflections
#### inflect
Returns the plural or singular form of a word based on a count.
Parameters:
singular `string` - The singular form of the word. (Required)
plural `string` - The plural form of the word. (Required)
include [boolean] - whether or not to include the count before the word. (Optional)
<br>Example:
enemies = 0
friends = 1
{{inflect enemies "enemy" "enemies"}}
{{inflect friends "friend" "friends" true}}
Result:
enemies
1 friend
#### ordinalize
Turns a number into an ordinal string. Taken from the templating library [Walrus](https://github.com/jeremyruppel/walrus) by [Jeremy Ruppel](https://github.com/jeremyruppel).
Parameters: `none`
<br>Example:
{{ordinalize 3}}
{{ordinalize 1}}
{{ordinalize 22}}
Result:
3rd
1st
22nd
### HTML
#### ul
Creates an unordered list.
Parameters:
hash [html attributes] - HTML attributes to use on the ul element. (Optional)
<br>Example:
collection = [
name: 'Leela'
deliveries: 8021
,
name: 'Bender'
deliveries: 239
,
name: 'Fry'
deliveries: 1
]
{{#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>
</ul>
#### ol
Same as the `ul` helper but creates and ordered list.
#### br
Returns `<br>` tags based on a count.
Parameters:
<br>count `int` - The number of `br` elements to render. (Optional)
<br>Example:
{{br 5}}
Result:
`<br><br><br><br><br>`
### Logging
#### log
Simple console.log()
Parameters: `none`
<br>Example:
{{log "Hi console :)"}}
Result:
Hi console :)
#### debug
Simple console.debug() that shows the current context.
Parameters: `none`
<br>Example:
collection = [
name: 'Leela'
deliveries: 8021
,
name: 'Bender'
deliveries: 239
,
name: 'Fry'
deliveries: 1
]
{{#withFirst collection}}
{{debug name}}
{{/withFirst}}
Result:
Context: { deliveries: 8021, name: "Leela" }
Value: Leela
-----------------------------------------------
### Miscellaneous
#### default
Provides a default or fallback value if a value doesn't exist.
Parameters:
defaultValue `string|int` - The default value to use.
<br>Example:
title = ''
{{default title "Not title available."}}
Result:
Not title available.
#### partial
Provides an easy way to register and use partials inside your templates. This helper only works if you define your templates as common.js modules, since it uses the common.js `require` function to find and register your templates with `Handlebars.registerPartial`. It was created with [brunch](http://brunch.io) in mind (which I use a lot), because brunch automatically wraps your scripts and templates in common.js modules to use in the browser.
Parameters:
name `string` - The name or path of the file in which your template is defined. (Required)
data [int|string|collection] - The data you want to use inside the partial. (Optional)
<br>Example:
# Path to your templates from where you override config.partialsPath
# The path must finish with a foward slash '/'
config.partialsPath = '../views/templates/'
collection = ['Professor Farnsworth', 'Fry', 'Bender']
# Your Partial (planet_express.hbs)
{{sort this}}
# Your template
<p>
{{partial "planet_express" collection}}
</p>
Result:
<p>Bender, Fry, Professor Farnsworth</p>
### Credit
Many of these helpers come from the following repos:
* [Handlebars Helpers, by Dan Harper](http://github.com/danharper)
* [Swag v0.2.1, by Elving Rodriguez](http://elving.github.com/swag/)
'use strict';
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
nodeunit: {
files: ['test/**/*_test.js'],
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
gruntfile: {
src: 'Gruntfile.js'
},
lib: {
src: ['lib/**/*.js']
},
test: {
src: ['test/**/*.js']
},
},
watch: {
gruntfile: {
files: '<%= jshint.gruntfile.src %>',
tasks: ['jshint:gruntfile']
},
lib: {
files: '<%= jshint.lib.src %>',
tasks: ['jshint:lib', 'nodeunit']
},
test: {
files: '<%= jshint.test.src %>',
tasks: ['jshint:test', 'nodeunit']
},
},
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
// Default task.
grunt.registerTask('default', ['jshint', 'nodeunit']);
};
/*
* helpers
* https://assemble.github.com/assemble/
*
* Copyright (c) 2013 Jon Schlinkert
* Licensed under the MIT license.
*/
'use strict';
exports.awesome = function() {
return 'awesome';
};
'use strict';
var helpers = require('../lib/helpers.js');
/*
======== A Handy Little Nodeunit Reference ========
https://github.com/caolan/nodeunit
Test methods:
test.expect(numAssertions)
test.done()
Test assertions:
test.ok(value, [message])
test.equal(actual, expected, [message])
test.notEqual(actual, expected, [message])
test.deepEqual(actual, expected, [message])
test.notDeepEqual(actual, expected, [message])
test.strictEqual(actual, expected, [message])
test.notStrictEqual(actual, expected, [message])
test.throws(block, [error], [message])
test.doesNotThrow(block, [error], [message])
test.ifError(value)
*/
exports['awesome'] = {
setUp: function(done) {
// setup here
done();
},
'no args': function(test) {
test.expect(1);
// tests here
test.equal(helpers.awesome(), 'awesome', 'should be awesome.');
test.done();
},
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet