1ERB(1) Ruby Programmers Reference Guide ERB(1)
2
4 erb — Ruby Templating
5
7 erb [--version] [-UPdnvx] [-E ext[:int]] [-S level] [-T mode]
8 [-r library] [--] [file ...]
9
11 erb is a command line front-end for ERB library, which is an implementa‐
12 tion of eRuby.
13
14 ERB provides an easy to use but powerful templating system for Ruby.
15 Using ERB, actual Ruby code can be added to any plain text document for
16 the purposes of generating document information details and/or flow con‐
17 trol.
18
19 erb is a part of Ruby.
20
22 --version Prints the version of erb.
23
24 -E external[:internal]
25 --encoding external[:internal]
26 Specifies the default value(s) for external encodings and
27 internal encoding. Values should be separated with colon
28 (:).
29
30 You can omit the one for internal encodings, then the
31 value (Encoding.default_internal) will be nil.
32
33 -P Evaluates lines starting with % as Ruby code and removes
34 the tailing EOLs.
35
36 -S level Specifies the safe level in which eRuby script will run.
37
38 -T mode Specifies trim mode (default 0). mode can be one of
39
40 0 EOL remains after the embedded ruby script
41 is evaluated.
42
43 1 EOL is removed if the line ends with %>.
44
45 2 EOL is removed if the line starts with <%
46 and ends with %>.
47
48 - EOL is removed if the line ends with -%>.
49 And leading whitespaces are removed if the
50 erb directive starts with <%-.
51
52 -U can be one of Sets the default value for internal encod‐
53 ings (Encoding.default_internal) to UTF-8.
54
55 -d
56 --debug Turns on debug mode. $DEBUG will be set to true.
57
58 -h
59 --help Prints a summary of the options.
60
61 -n Used with -x. Prepends the line number to each line in
62 the output.
63
64 -v Enables verbose mode. $VERBOSE will be set to true.
65
66 -x Converts the eRuby script into Ruby script and prints it
67 without line numbers.
68
70 Here is an eRuby script
71
72 <?xml version="1.0" ?>
73 <% require 'prime' -%>
74 <erb-example>
75 <calc><%= 1+1 %></calc>
76 <var><%= __FILE__ %></var>
77 <library><%= Prime.each(10).to_a.join(", ") %></library>
78 </erb-example>
79
80 Command
81 % erb -T - example.erb
82 prints
83
84 <?xml version="1.0" ?>
85 <erb-example>
86 <calc>2</calc>
87 <var>example.erb</var>
88 <library>2, 3, 5, 7</library>
89 </erb-example>
90
92 ruby(1).
93
94 And see ri(1) documentation for ERB class.
95
97 Security vulnerabilities should be reported via an email to
98 ⟨security@ruby-lang.org⟩. Reported problems will be published after
99 being fixed.
100
101 And you can report other bugs and feature requests via the Ruby Issue
102 Tracking System (http://bugs.ruby-lang.org). Do not report security vul‐
103 nerabilities via the system because it publishes the vulnerabilities
104 immediately.
105
107 Written by Masatoshi SEKI.
108
109UNIX November 7, 2012 UNIX