GithubHelp home page GithubHelp logo

zsyed91 / handlebars-contrib Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 252 KB

Underscore contrib style handlebars helper functions. Adds helper functions to your handlebars templates as well as in your javascript.

License: MIT License

HTML 0.28% JavaScript 99.72%

handlebars-contrib's Introduction

handlebars-contrib

Build Status

Build Status

About

Underscore contrib style handlebars helper functions. Adds helper functions to your handlebars templates as well as in your javascript.

String Helpers

Capitalize

Capitalize the first character of the first word in the string.

var strings = require("handlebars.strings");

strings.capitalize("this is a sentence.");
// This is a sentence.
{{capitalize this.firstName}}

Capitalize All

var strings = require("handlebars.strings");

strings.capitalize_all("john smith");
// John Smith
{{capitalize-all this.name}}

Normalize Spaces

var strings = require("handlebars.strings");

strings.normalize_spaces("This   is a    sentence.");
// This is a sentence.
{{normalize-spaces this.summary}}

To URL Slug

var strings = require("handlebars.strings");

strings.to_url_slug("Blog Post title!");
// blog-post-title
<a href="localhost/blog/{{to-url-slug this.postTitle}}">post</a>

Match

This helper is a conditional and fully supports the else clause.

<!-- commonNameRegex = /^John/, for example -->
{{#match this.name this.commonNameRegex}}
    <p>What a common name!</p>
{{else}}
    <p>What a unique name!</p>
{{/match}}

Math Helpers

While you can use these in javascript, they are really designed for use within the templates. The calculate method in javascript would be easier to do it directly.

Calculate

The supported operators are [+, -, /, *, %]

{{calculate this.costOfCookies '+' this.costOfMilk}}
{{calculate this.totalPrice '*' this.taxRate}}

Compare

This helper is a conditional and fully supports the else clause. The supported operators are [<, <=, >, >=, ==, !=, ===, !==].

{{#compare this.price '<=' this.budget}}
    <p>Affordable</p>
{{else}}
    <p>Too expensive :(</p>
{{/compare}}

handlebars-contrib's People

Contributors

zsyed91 avatar

Watchers

 avatar  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.