Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 50 lines (33 sloc) 1.434 kb
f7bcad2 @rtomayko starting in on template engine docs
authored
1 Templates
2 =========
3
4 ERB (`erb`, `rhtml`)
5 --------------------
6
7 [Docs](http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html) |
8 [Syntax](http://vision-media.ca/resources/ruby/ruby-rdoc-documentation-syntax)
9
10 ### Example
11
12 Hello <%= world %>!
13
14 ### Usage
15
16 The `Tilt::ERBTemplate` class is registered for all files ending in `.erb` or
17 `.rhtml` by default. ERB templates support custom evaluation scopes and locals:
18
19 >> require 'erb'
20 >> template = Tilt.new('hello.html.erb', :trim => '<>')
21 => #<Tilt::ERBTemplate @file='hello.html.erb'>
22 >> template.render(self, :world => 'World!')
23 => "Hello World!"
24
25 Or, use the `Tilt::ERBTemplate` class directly to process strings:
26
27 require 'erb'
28 template = Tilt::ERBTemplate.new(nil, :trim => '<>') { "Hello <%= world %>!" }
29 template.render(self, :world => 'World!')
30
31 ### Options
32
33 `:trim => '-'`
34
35 The ERB trim mode flags. This is a string consisting
36 of any combination of the following characters:
37
38 * `'>'` omits newlines for lines ending in `>`
39 * `'<>'` omits newlines for lines starting with `<%` and ending in `%>`
40 * `'-'` omits newlines for lines ending in `-%>`.
41 * `'%'` enables processing of lines beginning with `%`
42
43 `:safe => nil`
44
45 The `$SAFE` level; when set, ERB code will be run in a
46 separate thread with `$SAFE` set to the provided level.
47
48 It's suggested that your program require 'erb' at load time when using this
49 template engine.
Something went wrong with that request. Please try again.