README.md in handlebars_assets-0.6.7 vs README.md in handlebars_assets-0.7.0

- old
+ new

@@ -1,8 +1,8 @@ # Use handlebars.js templates with the asset pipeline and sprockets -Are your `handlebars.js` templates littering your Rails views with `script` tags? Wondering why the nifty Rails 3.1 asset pipeline streamlines all your Javascript except for your Handlebars templates? Wouldn't it be nice to have your Handlebars templates compiled, compressed, and cached like your other Javascript? +Are your `handlebars.js` templates littering your Rails views with `script` tags? Wondering why the nifty Rails 3.1 asset pipeline streamlines all your JavaScript except for your Handlebars templates? Wouldn't it be nice to have your Handlebars templates compiled, compressed, and cached like your other JavaScript? Yea, I think so too. That is why I wrote **handlebars_assets**. Give your Handlebars templates their own files (including partials) and have them compiled, compressed, and cached as part of the Rails 3.1 asset pipeline! Using `sprockets` with Sinatra or another framework? **handlebars_assets** works outside of Rails too (as of v0.2.0) @@ -34,17 +34,17 @@ require 'handlebars_assets' env.append_path HandlebarsAssets.path -# Compiling your Javascript templates in the Rails asset pipeline +# Compiling your JavaScript templates in the Rails asset pipeline -Require `handlebars.runtime.js` in your Javascript manifest (i.e. `application.js`) +Require `handlebars.runtime.js` in your JavaScript manifest (i.e. `application.js`) //= require handlebars.runtime -If you need to compile your Javascript templates in the browser as well, you should instead require `handlebars.js` (which is significantly larger) +If you need to compile your JavaScript templates in the browser as well, you should instead require `handlebars.js` (which is significantly larger) //= require handlebars ## Precompiling @@ -52,11 +52,11 @@ config.assets.initialize_on_precompile = false ## Templates directory -You should locate your templates with your other assets, for example `app/assets/javascripts/templates`. In your Javascript manifest file, use `require_tree` to pull in the templates +You should locate your templates with your other assets, for example `app/assets/javascripts/templates`. In your JavaScript manifest file, use `require_tree` to pull in the templates //= require_tree ./templates ## The template file @@ -70,25 +70,41 @@ edit.hbs show.hbs Your file extensions tell the asset pipeline how to process the file. Use `.hbs` to compile the template with Handlebars. -If your file is `templates/contacts/new.hbs`, the asset pipeline will generate Javascript code +If your file is `templates/contacts/new.hbs`, the asset pipeline will generate JavaScript code -1. Compile the Handlebars template to Javascript code +1. Compile the Handlebars template to JavaScript code 1. Add the template code to the `HandlebarsTemplates` global under the name `contacts/new` -You can then invoke the resulting template in your application's Javascript +You can then invoke the resulting template in your application's JavaScript HandlebarsTemplates['contacts/new'](context); ## The template namespace -By default, the global Javascript object that holds the compiled templates is `HandlebarsTemplates`, but it can +By default, the global JavaScript object that holds the compiled templates is `HandlebarsTemplates`, but it can be easily renamed. Another common template namespace is `JST`. Just change the `template_namespace` configuration option when you initialize your application. HandlebarsAssets::Config.template_namespace = 'JST' + +## `.hamlbars` + +If you name your templates with the extension `.hamlbars`, you can use Haml syntax for your markup! Use `HandlebarsAssets::Config.haml_options` to pass custom options to the Haml rendering engine. + +For example, if you have a file `widget.hamlbars` that looks like this: + + %h1 {{title}} + %p {{body}} + +Haml will first convert it to: + + <h1> {{title}} </h1> + <p> {{body}} </p> + +And the Handlebars will turn it into a JavaScript template. ## Partials If you begin the name of the template with an underscore, it will be recognized as a partial. You can invoke partials inside a template using the Handlebars partial syntax: