$.template()
Use $.template() like _.template(), compiles JavaScript templates into functions that can be evaluated for rendering.
Code copied from Underscore.js, just renamed _.template
to $.template
, and exports some dependency methods to $. You can use it as a jQuery or Zepto plugin, or use directly in Node.js.
Installation
NPM
npm install dollar.template
Bower
bower install dollar.template
Usage
Node.js
var template = template; var compiled = ;; // "hello: moe" var tmpl = ;; // "<b><script></b>"
Browser
<!-- also works with zepto -->
var compiled = $;; // "hello: moe"
Require.js
$.template()
Testing
npm test
API
- $.isObject -
$.isObject({});
=>true
- $.keys -
$.keys({one: 1, two: 2, three: 3});
=>["one", "two", "three"]
- $.allkeys - See _.allkeys
- $.invert -
$.invert({Moe: "Moses", Larry: "Louis", Curly: "Jerome"});
=>{Moses: "Moe", Louis: "Larry", Jerome: "Curly"};
- $.has -
$.has({a: 1, b: 2, c: 3}, "b");
=>true
- $.escape -
$.escape('Curly, Larry & Moe');
=>"Curly, Larry & Moe"
- $.unescape -
$.unescape('Curly, Larry & Moe');
=>"Curly, Larry & Moe"
- $.defaults - See _.defaults
- $.template - See _.template