Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Simple Text Template System

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 notes
Octocat-spinner-32 test
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 handlebar.gemspec
README.rdoc

handlebar

A simple text template system for generating output for a variety of uses including plain-text, HTML, and JavaScript.

Examples

The straight-forward usage is substitutions:

template = Handlebar::Template.new("This {{noun}} is {{adjective}}")

template.render(:noun => 'shoe', :adjective => 'red')
# => "This shoe is red"

If required, the content can be HTML-escaped automatically:

template = Handlebar::Template.new(
  "This {{noun}} is {{adjective}}",
  :escape => :html
)

template.render(:noun => 'goose', :adjective => '<em>blue</em>')
# => "This goose is &lt;em&gt;blue&lt;/em&gt;"

This can also be engaged on a case-by-case basis:

template = Handlebar::Template.new("This {{&noun}} is {{adjective}}")

template.render(:noun => '<b>goose</b>', :adjective => '<em>blue</em>')
# => "This &lt;b&gt;goose&lt;/b&gt; is <em>blue</em>"

Also available is URI encoding for links:

template = Handlebar::Template.new(
  "<a href='/home?user_id={{%user_id}}'>{{&label}}</a>"
)

template.render(:user_id => 'joe&2', :label => 'Joe&2')
# => "<a href='/home?user_id=joe%262'>Joe&amp;2</a>"

A number of other usage cases are described in test/test_handlebar_template.rb as a reference.

Copyright

Copyright © 2011 Scott Tadman, The Working Group Inc. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.