Giter VIP home page Giter VIP logo

cool-helpers's Introduction

cool-helpers

Build Status

Cool Helpers is a Handlebars.js helpers compilation with AMD support

Jump to Section

Quickstart

[Back To Top]

To start using cool-helpers you can:

###Build the project

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.

####Contribute

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.

Usage

[Back To Top]

'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

[Back To Top]

Commons

###data

Generates data-attribute from context.type and context.value

{{#data attribute}}{{/data}}

###datas

Generates data-attributes from context.type and context.value

{{#datas attributes}}{{/datas}}

###attributes

Generates data-attribute from context.type and context.value

{{#attributes attributes}}{{/attributes}}

###macro

Generates a new helper with name key

{{#macro "mymacro" options=""}}
    {{#each options}}
    {{/each}}
{{/macro}}
 
{{mymacro options=options}

###nl2br

Changes each nl to a br tag

{{#nl2br title}}{{/nl2br}}

###log

Log one or multiple values to the console:

{{#log title}}{{/log}}

###debug

Log one or multiple values to the console, with the current context:

{{#debug title}}{{/debug}}

Comparison

[Back To Top]

Comparison

###contains

Conditionally render a block if string matches pattern

{{#contains title "pattern"}}
    text
{{/contains}}

###and

Conditionally render a block if both a and b properties exists and are not null or undefined

{{#and title name}}
    text
{{/and}}

###gt

Conditionally render a block if value > test

{{#@gt 5 2}}
    text
{/gt}}

###gte

Conditionally render a block if value >= test

{{#@gte 5 2}}
    text
{/gte}}

###is

Conditionally render a block if value === test

{{#@is 5 5}}
    text
{/is}}

###isnt

Conditionally render a block if value !== test

{{#@isnt 5 5}}
    text
{/isnt}}

###lt

Conditionally render a block if value < test

{{#@lt 5 2}}
    text
{/lt}}

###lte

Conditionally render a block if value <= test

{{#@lte 5 2}}
    text
{/lte}}

###or

Conditionally render a block if a || b

{{#@or a b}}
    text
{/or}}

###ifNth

Conditionally render a block if nr%v === 0

{{#ifNth 10 2}}
    text
{{/ifNth}}

###compare

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

[Back To Top]

Math

###add

Returns value + adition

{{add 5 1}}

###substract

Returns value - substraction

{{substract 5 1}}

###divide

Returns value % divisor

{{divide 6 3}}

###multiply

Returns value * multiplier

{{multiply 5 2}}

###floor

Returns Math.floor(value)

{{floor 3.2222}}

###ceil

Returns Math.ceil(value)

{{ceil 3.2222}}

###round

Returns Math.round(value)

{{round 3.2222}}

###sum

Returns sum of each argument

{{sum 1 1 2 3 5 8}}

Date

[Back To Top]

Date

###formatDate

Formats date in given format

{{formatDate date 'yyyy/mm/dd'}}

###subtractDate

Returns the difference between two dates in given format

{{subtractDates date1 date2 "d"}}

This readme has been automatically generated by readme generator on Tue Mar 10 2015 10:19:07 GMT+0100 (CET).

cool-helpers's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.