Cool Helpers is a Handlebars.js helpers compilation with AMD support
To start using cool-helpers you can:
- Download the last release
- Install with bower:
bower install cool-helpers --save-dev
If you want to build the project locally, you have to run the Grunt task grunt build. This task will concat and minify the sources and create the README.md. Before all this, you do not forget to run npm install and bower install.
If you want to keep growing cool-helpers up, send us a pull request with your new helpers. You must follow this steps:
- Add the helper to its proper category file inside src/helpers directory. If you want to create a new category, create the new js file and add it at src/helpers/start.js.
- Do your commit message following the commit conventions. The changelog will be created using the commited messages.
- Document the helper. No pull request will be accepted without proper documentation. Documentation directory is doc. If you need to create a new documentation section, remember to add it at Gruntfile, inside readme_generator.readme.order. Also, you have to write low-level documentation using JSDoc.
- Remember to build the project before doing the pull-request.
'use strict'
require.config({
deps: [
'cool-helpers'
],
paths: {
'cool-helpers': 'bower_components/cool-helpers/lib/cool-helpers',
handlebars: 'bower_components/handlebars/handlebars',
moment: 'bower_components/moment/moment'
}
});
Commons
Generates data-attribute from context.type and context.value
{{#data attribute}}{{/data}}
Generates data-attributes from context.type and context.value
{{#datas attributes}}{{/datas}}
Generates data-attribute from context.type and context.value
{{#attributes attributes}}{{/attributes}}
Generates a new helper with name key
{{#macro "mymacro" options=""}}
{{#each options}}
{{/each}}
{{/macro}}
{{mymacro options=options}
Changes each nl to a br tag
{{#nl2br title}}{{/nl2br}}
Log one or multiple values to the console:
{{#log title}}{{/log}}
Log one or multiple values to the console, with the current context:
{{#debug title}}{{/debug}}
Comparison
Conditionally render a block if string matches pattern
{{#contains title "pattern"}}
text
{{/contains}}
Conditionally render a block if array list is empty
{{#isEmpty list }}
text
{{/isEmpty}}
Conditionally render a block if array list inst empty
{{#isntEmpty list }}
text
{{/isntEmpty}}
Conditionally render a block if if obj is undefined
{{#isUndefined obj }}
text
{{/isUndefined}}
Conditionally render a block if obj exists
{{#exists obj }}
text
{{/exists}}
Conditionally render a block if both a and b properties exists and are not null or undefined
{{#and title name}}
text
{{/and}}
Conditionally render a block if value > test
{{#gt 5 2}}
text
{/gt}}
Conditionally render a block if value >= test
{{#gte 5 2}}
text
{/gte}}
Conditionally render a block if value === test
{{#is 5 5}}
text
{/is}}
Conditionally render a block if value !== test
{{#isnt 5 5}}
text
{/isnt}}
Conditionally render a block if value < test
{{#lt 5 2}}
text
{/lt}}
Conditionally render a block if value <= test
{{#lte 5 2}}
text
{/lte}}
Conditionally render a block if a || b
{{#or a b}}
text
{/or}}
Conditionally render a block if nr%v === 0
{{#ifNth 10 2}}
text
{{/ifNth}}
Compares two values with given operator. Operators are: ==, ===, !=, !==, <, >, <=, >=, typeof. Operator must be between quotes "";
{{#compare unicorns "<" ponies}}
I knew it, unicorns are just low-quality ponies!
{{/compare}}
{{#compare value ">=" 10}}
The value is greater or equal than 10
{{else}}
The value is lower than 10
{{/compare}}
Math
Returns value + adition
{{add 5 1}}
Returns value - substraction
{{substract 5 1}}
Returns value % divisor
{{divide 6 3}}
Returns value * multiplier
{{multiply 5 2}}
Returns Math.floor(value)
{{floor 3.2222}}
Returns Math.ceil(value)
{{ceil 3.2222}}
Returns Math.round(value)
{{round 3.2222}}
Returns sum of each argument
{{sum 1 1 2 3 5 8}}
Date
Formats date in given format
{{formatDate date 'yyyy/mm/dd'}}
Returns the difference between two dates in given format
{{subtractDates date1 date2 "d"}}
This readme has been automatically generated by readme generator on Sun Mar 22 2015 17:38:16 GMT+0100 (Hora estándar romance).
