erb 5.0.2 → 5.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +1 -1
- data/.github/workflows/dependabot_automerge.yml +30 -0
- data/.github/workflows/sync-ruby.yml +33 -0
- data/.github/workflows/test.yml +4 -1
- data/Gemfile +1 -0
- data/NEWS.md +4 -0
- data/README.md +64 -221
- data/_doc/erb_executable.md +240 -0
- data/lib/erb/util.rb +12 -12
- data/lib/erb/version.rb +2 -1
- data/lib/erb.rb +994 -278
- data/libexec/erb +35 -15
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 335faf3ef112b23c4f6066554480a40426ae7dc1d036f018e33bbac13c881c18
|
4
|
+
data.tar.gz: 341547a90647453d267fc035d0f7a2b6c05a617e958cafd45d07c4ee6b6b2ef2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd258645b17ca0e0045bdc3c2db4311221942be033b12da3c546022ebac4742fa31b157c448d274c5c7bdd222e396d364bb96abee179810724da44fd9d70c63f
|
7
|
+
data.tar.gz: 81763b69563026a2b0ba3a926524aa10f0bd2cf439c22fac2b4368a31257ffd629ad1f2236eefeca30bbf733381fee28f54318b25dc43c5f24421a04cdc9d28d
|
data/.github/dependabot.yml
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
name: Dependabot auto-merge
|
2
|
+
on:
|
3
|
+
pull_request:
|
4
|
+
|
5
|
+
permissions:
|
6
|
+
contents: write
|
7
|
+
pull-requests: write
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
automerge:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'ruby/erb'
|
13
|
+
steps:
|
14
|
+
- name: Dependabot metadata
|
15
|
+
uses: dependabot/fetch-metadata@v2
|
16
|
+
id: metadata
|
17
|
+
|
18
|
+
- name: Wait for status checks
|
19
|
+
uses: lewagon/wait-on-check-action@v1
|
20
|
+
with:
|
21
|
+
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
22
|
+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
23
|
+
check-regexp: 'build \(.*\)'
|
24
|
+
wait-interval: 30
|
25
|
+
|
26
|
+
- name: Auto-merge for Dependabot PRs
|
27
|
+
run: gh pr merge --auto --rebase "$PR_URL"
|
28
|
+
env:
|
29
|
+
PR_URL: ${{ github.event.pull_request.html_url }}
|
30
|
+
GITHUB_TOKEN: ${{ secrets.MATZBOT_DEPENDABOT_MERGE_TOKEN }}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: Sync ruby
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches: [master]
|
5
|
+
jobs:
|
6
|
+
sync:
|
7
|
+
name: Sync ruby
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
if: ${{ github.repository == 'ruby/erb' }}
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v5
|
12
|
+
|
13
|
+
- name: Create GitHub App token
|
14
|
+
id: app-token
|
15
|
+
uses: actions/create-github-app-token@v2
|
16
|
+
with:
|
17
|
+
app-id: 2060836
|
18
|
+
private-key: ${{ secrets.RUBY_SYNC_DEFAULT_GEMS_PRIVATE_KEY }}
|
19
|
+
owner: ruby
|
20
|
+
repositories: ruby
|
21
|
+
|
22
|
+
- name: Sync to ruby/ruby
|
23
|
+
uses: convictional/trigger-workflow-and-wait@v1.6.5
|
24
|
+
with:
|
25
|
+
owner: ruby
|
26
|
+
repo: ruby
|
27
|
+
workflow_file_name: sync_default_gems.yml
|
28
|
+
github_token: ${{ steps.app-token.outputs.token }}
|
29
|
+
ref: master
|
30
|
+
client_payload: |
|
31
|
+
{"gem":"erb","before":"${{ github.event.before }}","after":"${{ github.event.after }}"}
|
32
|
+
propagate_failure: true
|
33
|
+
wait_interval: 10
|
data/.github/workflows/test.yml
CHANGED
@@ -23,7 +23,7 @@ jobs:
|
|
23
23
|
fail-fast: false
|
24
24
|
runs-on: ${{ matrix.os }}
|
25
25
|
steps:
|
26
|
-
- uses: actions/checkout@
|
26
|
+
- uses: actions/checkout@v5
|
27
27
|
- name: Set up Ruby
|
28
28
|
uses: ruby/setup-ruby@v1
|
29
29
|
with:
|
@@ -31,3 +31,6 @@ jobs:
|
|
31
31
|
bundler-cache: true
|
32
32
|
- name: Run test
|
33
33
|
run: bundle exec rake test
|
34
|
+
- name: RDoc coverage
|
35
|
+
run: |
|
36
|
+
rdoc -C .
|
data/Gemfile
CHANGED
data/NEWS.md
CHANGED
data/README.md
CHANGED
@@ -1,255 +1,98 @@
|
|
1
|
-
# ERB
|
1
|
+
# \ERB (Embedded Ruby)
|
2
2
|
|
3
|
-
|
3
|
+
\ERB is an easy-to-use, but also very powerful, [template processor][template processor].
|
4
4
|
|
5
|
-
|
5
|
+
\ERB is commonly used to produce:
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
- Customized or personalized email messages.
|
8
|
+
- Customized or personalized web pages.
|
9
|
+
- Software code (in code-generating applications).
|
10
10
|
|
11
|
-
|
11
|
+
Like method [sprintf][sprintf], \ERB can format run-time data into a string.
|
12
|
+
\ERB, however, is *much more powerful*
|
12
13
|
|
13
|
-
|
14
|
-
require 'erb'
|
14
|
+
## How \ERB Works
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
EOF
|
20
|
-
puts template.result(binding)
|
21
|
-
```
|
16
|
+
Using \ERB, you can create a *template*: a plain-text string that has specially-formatted *tags*,
|
17
|
+
then store it into an \ERB object;
|
18
|
+
when \ERB produces _result_ string, it:
|
22
19
|
|
23
|
-
|
20
|
+
- Inserts run-time-evaluated expressions into the result.
|
21
|
+
- Executes snippets of Ruby code.
|
22
|
+
- Omits comments from the results.
|
24
23
|
|
25
|
-
|
24
|
+
In the result:
|
26
25
|
|
27
|
-
|
26
|
+
- All non-tag text is passed through, _unchanged_.
|
27
|
+
- Each tag is either _replaced_ (expression tag),
|
28
|
+
or _omitted_ entirely (execution tag or comment tag).
|
28
29
|
|
29
|
-
|
30
|
-
on the rules below:
|
30
|
+
There are three types of tags:
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
<%=
|
35
|
-
|
36
|
-
|
37
|
-
%% replaced with % if first thing on a line and % processing is used
|
38
|
-
<%% or %%> -- replace with <% or %> respectively
|
39
|
-
```
|
32
|
+
| Tag | Form | Action | Text in Result |
|
33
|
+
|----------------|:------------------------------------:|:-------------------------------------:|:--------------------:|
|
34
|
+
| Expression tag | <tt>'<%= _ruby_expression_ %>'</tt> | Evaluates <tt>_ruby_expression_</tt>. | Value of expression. |
|
35
|
+
| Execution tag | <tt>'<% _ruby_code_ %>'</tt> | Execute <tt>_ruby_code_</tt>. | None. |
|
36
|
+
| Comment tag | <tt>'<%# _comment_text_ %>'</tt> | None. | None. |
|
40
37
|
|
41
|
-
|
38
|
+
These examples use `erb`, the \ERB command-line interface;
|
39
|
+
each "echoes" a string template and pipes it to `erb` as input:
|
42
40
|
|
43
|
-
## Options
|
44
41
|
|
45
|
-
|
46
|
-
* the nature of the tags that are recognized;
|
47
|
-
* the binding used to resolve local variables in the template.
|
42
|
+
- Expression tag:
|
48
43
|
|
49
|
-
|
44
|
+
$ echo "<%= $VERBOSE %>" | erb
|
45
|
+
"false"
|
46
|
+
$ echo "<%= 2 + 2 %>" | erb
|
47
|
+
"4"
|
50
48
|
|
51
|
-
|
49
|
+
- Execution tag:
|
52
50
|
|
53
|
-
|
54
|
-
|
55
|
-
a magic comment, however, it returns a string in the encoding specified
|
56
|
-
by the magic comment.
|
51
|
+
echo "<% if $VERBOSE %> Long message. <% else %> Short message. <% end %>" | erb
|
52
|
+
" Short message. "
|
57
53
|
|
58
|
-
|
59
|
-
# -*- coding: utf-8 -*-
|
60
|
-
require 'erb'
|
54
|
+
- Comment tag:
|
61
55
|
|
62
|
-
|
63
|
-
|
64
|
-
__ENCODING__ is <%= __ENCODING__ %>.
|
65
|
-
EOF
|
66
|
-
puts template.result
|
67
|
-
```
|
56
|
+
echo "<%# TODO: Fix this nonsense. %> Nonsense." | erb
|
57
|
+
" Nonsense."
|
68
58
|
|
69
|
-
|
59
|
+
## How to Use \ERB
|
70
60
|
|
71
|
-
|
61
|
+
You can use \ERB either:
|
72
62
|
|
73
|
-
|
63
|
+
- In a program: see class ERB.
|
64
|
+
- From the command line: see [ERB Executable][erb executable].
|
74
65
|
|
75
|
-
|
76
|
-
convenient "% at start of line" tag, and we quote the template literally with
|
77
|
-
`%q{...}` to avoid trouble with the backslash.
|
66
|
+
## Installation
|
78
67
|
|
79
|
-
|
80
|
-
require "erb"
|
68
|
+
\ERB is installed with Ruby, and so there's no further installation needed.
|
81
69
|
|
82
|
-
|
83
|
-
template = %q{
|
84
|
-
From: James Edward Gray II <james@grayproductions.net>
|
85
|
-
To: <%= to %>
|
86
|
-
Subject: Addressing Needs
|
70
|
+
## Other Template Engines
|
87
71
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
addressed.
|
92
|
-
|
93
|
-
I want you to know that my team will keep working on the issues,
|
94
|
-
especially:
|
95
|
-
|
96
|
-
<%# ignore numerous minor requests -- focus on priorities %>
|
97
|
-
% priorities.each do |priority|
|
98
|
-
* <%= priority %>
|
99
|
-
% end
|
100
|
-
|
101
|
-
Thanks for your patience.
|
102
|
-
|
103
|
-
James Edward Gray II
|
104
|
-
}.gsub(/^ /, '')
|
105
|
-
|
106
|
-
message = ERB.new(template, trim_mode: "%<>")
|
107
|
-
|
108
|
-
# Set up template data.
|
109
|
-
to = "Community Spokesman <spokesman@ruby_community.org>"
|
110
|
-
priorities = [ "Run Ruby Quiz",
|
111
|
-
"Document Modules",
|
112
|
-
"Answer Questions on Ruby Talk" ]
|
113
|
-
|
114
|
-
# Produce result.
|
115
|
-
email = message.result
|
116
|
-
puts email
|
117
|
-
```
|
118
|
-
|
119
|
-
Generates:
|
120
|
-
|
121
|
-
```
|
122
|
-
From: James Edward Gray II <james@grayproductions.net>
|
123
|
-
To: Community Spokesman <spokesman@ruby_community.org>
|
124
|
-
Subject: Addressing Needs
|
125
|
-
|
126
|
-
Community:
|
127
|
-
|
128
|
-
Just wanted to send a quick note assuring that your needs are being addressed.
|
129
|
-
|
130
|
-
I want you to know that my team will keep working on the issues, especially:
|
131
|
-
|
132
|
-
* Run Ruby Quiz
|
133
|
-
* Document Modules
|
134
|
-
* Answer Questions on Ruby Talk
|
135
|
-
|
136
|
-
Thanks for your patience.
|
137
|
-
|
138
|
-
James Edward Gray II
|
139
|
-
```
|
140
|
-
|
141
|
-
### Ruby in HTML
|
142
|
-
|
143
|
-
ERB is often used in .rhtml files (HTML with embedded Ruby). Notice the need in
|
144
|
-
this example to provide a special binding when the template is run, so that the instance
|
145
|
-
variables in the Product object can be resolved.
|
146
|
-
|
147
|
-
```rb
|
148
|
-
require "erb"
|
149
|
-
|
150
|
-
# Build template data class.
|
151
|
-
class Product
|
152
|
-
def initialize( code, name, desc, cost )
|
153
|
-
@code = code
|
154
|
-
@name = name
|
155
|
-
@desc = desc
|
156
|
-
@cost = cost
|
157
|
-
|
158
|
-
@features = [ ]
|
159
|
-
end
|
160
|
-
|
161
|
-
def add_feature( feature )
|
162
|
-
@features << feature
|
163
|
-
end
|
164
|
-
|
165
|
-
# Support templating of member data.
|
166
|
-
def get_binding
|
167
|
-
binding
|
168
|
-
end
|
169
|
-
|
170
|
-
# ...
|
171
|
-
end
|
172
|
-
|
173
|
-
# Create template.
|
174
|
-
template = %{
|
175
|
-
<html>
|
176
|
-
<head><title>Ruby Toys -- <%= @name %></title></head>
|
177
|
-
<body>
|
178
|
-
|
179
|
-
<h1><%= @name %> (<%= @code %>)</h1>
|
180
|
-
<p><%= @desc %></p>
|
181
|
-
|
182
|
-
<ul>
|
183
|
-
<% @features.each do |f| %>
|
184
|
-
<li><b><%= f %></b></li>
|
185
|
-
<% end %>
|
186
|
-
</ul>
|
187
|
-
|
188
|
-
<p>
|
189
|
-
<% if @cost < 10 %>
|
190
|
-
<b>Only <%= @cost %>!!!</b>
|
191
|
-
<% else %>
|
192
|
-
Call for a price, today!
|
193
|
-
<% end %>
|
194
|
-
</p>
|
195
|
-
|
196
|
-
</body>
|
197
|
-
</html>
|
198
|
-
}.gsub(/^ /, '')
|
199
|
-
|
200
|
-
rhtml = ERB.new(template)
|
72
|
+
There are a variety of template engines available in various Ruby projects.
|
73
|
+
For example, [RDoc][rdoc], distributed with Ruby, uses its own template engine, which
|
74
|
+
can be reused elsewhere.
|
201
75
|
|
202
|
-
|
203
|
-
toy = Product.new( "TZ-1002",
|
204
|
-
"Rubysapien",
|
205
|
-
"Geek's Best Friend! Responds to Ruby commands...",
|
206
|
-
999.95 )
|
207
|
-
toy.add_feature("Listens for verbal commands in the Ruby language!")
|
208
|
-
toy.add_feature("Ignores Perl, Java, and all C variants.")
|
209
|
-
toy.add_feature("Karate-Chop Action!!!")
|
210
|
-
toy.add_feature("Matz signature on left leg.")
|
211
|
-
toy.add_feature("Gem studded eyes... Rubies, of course!")
|
76
|
+
Other popular template engines may be found in the [Ruby Toolbox][ruby toolbox].
|
212
77
|
|
213
|
-
|
214
|
-
rhtml.run(toy.get_binding)
|
215
|
-
```
|
78
|
+
## Code
|
216
79
|
|
217
|
-
|
80
|
+
The \ERB source code is in GitHub project [ruby/erb][ruby/erb]/
|
218
81
|
|
219
|
-
|
220
|
-
<html>
|
221
|
-
<head><title>Ruby Toys -- Rubysapien</title></head>
|
222
|
-
<body>
|
223
|
-
|
224
|
-
<h1>Rubysapien (TZ-1002)</h1>
|
225
|
-
<p>Geek's Best Friend! Responds to Ruby commands...</p>
|
226
|
-
|
227
|
-
<ul>
|
228
|
-
<li><b>Listens for verbal commands in the Ruby language!</b></li>
|
229
|
-
<li><b>Ignores Perl, Java, and all C variants.</b></li>
|
230
|
-
<li><b>Karate-Chop Action!!!</b></li>
|
231
|
-
<li><b>Matz signature on left leg.</b></li>
|
232
|
-
<li><b>Gem studded eyes... Rubies, of course!</b></li>
|
233
|
-
</ul>
|
234
|
-
|
235
|
-
<p>
|
236
|
-
Call for a price, today!
|
237
|
-
</p>
|
238
|
-
|
239
|
-
</body>
|
240
|
-
</html>
|
241
|
-
```
|
242
|
-
|
243
|
-
## Notes
|
244
|
-
|
245
|
-
There are a variety of templating solutions available in various Ruby projects.
|
246
|
-
For example, RDoc, distributed with Ruby, uses its own template engine, which
|
247
|
-
can be reused elsewhere.
|
82
|
+
## Bugs
|
248
83
|
|
249
|
-
|
250
|
-
[Category](https://www.ruby-toolbox.com/categories/template_engines) of
|
251
|
-
The Ruby Toolbox.
|
84
|
+
Bugs may be reported at [ERB Issues][erb issues].
|
252
85
|
|
253
86
|
## License
|
254
87
|
|
255
|
-
|
88
|
+
This software is available as open source under the terms
|
89
|
+
of the [2-Clause BSD License][2-clause bsd license].
|
90
|
+
|
91
|
+
[2-clause bsd license]: https://opensource.org/licenses/BSD-2-Clause
|
92
|
+
[erb executable]: rdoc-ref:erb_executable.md
|
93
|
+
[erb issues]: https://github.com/ruby/erb/issues
|
94
|
+
[rdoc]: https://ruby.github.io/rdoc/
|
95
|
+
[ruby/erb]: https://github.com/ruby/erb
|
96
|
+
[ruby toolbox]: https://www.ruby-toolbox.com/categories/template_engines
|
97
|
+
[sprintf]: https://docs.ruby-lang.org/en/master/Kernel.html#method-i-sprintf
|
98
|
+
[template processor]: https://en.wikipedia.org/wiki/Template_processor_
|
@@ -0,0 +1,240 @@
|
|
1
|
+
# \ERB Executable
|
2
|
+
|
3
|
+
The `erb` executable gives command-line access to ERB template processing.
|
4
|
+
|
5
|
+
The executable is installed with \ERB, which is part of the Ruby installation.
|
6
|
+
|
7
|
+
For a quick summary, type:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
$ erb --help
|
11
|
+
```
|
12
|
+
|
13
|
+
The format of the command is
|
14
|
+
`erb [_options_] [_filepaths_]`,
|
15
|
+
where:
|
16
|
+
|
17
|
+
- _options_ are zero or more [options][options].
|
18
|
+
- _filepaths_ are zero or more paths to files, each containing an plain text
|
19
|
+
that can include \ERB tags.
|
20
|
+
|
21
|
+
## Filepaths
|
22
|
+
|
23
|
+
With one or more _filepaths_ given, `erb` reads all the given files as a single template;
|
24
|
+
that is, `erb` processes multiple files into a single result:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
$ cat t.erb
|
28
|
+
<%= RUBY_VERSION %>
|
29
|
+
<%= Time.now %>
|
30
|
+
$ cat u.erb
|
31
|
+
% Encoding.list.take(4).each do |encoding|
|
32
|
+
* <%= encoding %>
|
33
|
+
% end
|
34
|
+
$ erb t.erb u.erb
|
35
|
+
3.4.5
|
36
|
+
2025-09-24 00:23:00 +0100
|
37
|
+
* ASCII-8BIT
|
38
|
+
* UTF-8
|
39
|
+
* US-ASCII
|
40
|
+
* UTF-16BE
|
41
|
+
```
|
42
|
+
|
43
|
+
There is a special "filepath", `'-'`, that specifies the standard input:
|
44
|
+
|
45
|
+
```bash
|
46
|
+
$ echo "<%= RUBY_VERSION %>" | erb u.erb -
|
47
|
+
* ASCII-8BIT
|
48
|
+
* UTF-8
|
49
|
+
* US-ASCII
|
50
|
+
* UTF-16BE
|
51
|
+
3.4.5
|
52
|
+
```
|
53
|
+
|
54
|
+
Any filepath, including `'-'`, may be repeated.
|
55
|
+
|
56
|
+
With no _filepaths_ given, `erb` reads and processes the standard input:
|
57
|
+
|
58
|
+
```bash
|
59
|
+
$ echo "<%= RUBY_VERSION %>" | erb # Prints the ERB version string.
|
60
|
+
```
|
61
|
+
|
62
|
+
## Options
|
63
|
+
|
64
|
+
### `-d`, `--debug`: Set $DEBUG
|
65
|
+
|
66
|
+
Use option `-d` or `--debug` to turn on debugging output:
|
67
|
+
|
68
|
+
```bash
|
69
|
+
$ echo "<%= $DEBUG %>" | erb
|
70
|
+
"false"
|
71
|
+
$echo "<%= $DEBUG %>" | erb --debug
|
72
|
+
"true"
|
73
|
+
```
|
74
|
+
|
75
|
+
### `-E`, `--encoding`: Set Encodings
|
76
|
+
|
77
|
+
Use option `-E` or `--encoding` to set the default external encoding to `_ex_`
|
78
|
+
and, if `_in_` is given, to set the default internal encoding to `_in_`.
|
79
|
+
|
80
|
+
Each encoding, `ex` and `in`, must be the name of an Encoding:
|
81
|
+
|
82
|
+
```
|
83
|
+
erb -E ASCII-8BIT:ASCII-8BIT t.erb
|
84
|
+
```
|
85
|
+
|
86
|
+
### `-h`, `--help`: Print Help
|
87
|
+
|
88
|
+
Use option `-h` or `--help` to print `erb` help text:
|
89
|
+
|
90
|
+
```bash
|
91
|
+
$ erb --help
|
92
|
+
```
|
93
|
+
|
94
|
+
### `-n`: Print Source with Line Numbers
|
95
|
+
|
96
|
+
Use option `-n` with option `-x` to print the output of ERB#src,
|
97
|
+
with numbered lines:
|
98
|
+
|
99
|
+
```bash
|
100
|
+
$ cat t.erb
|
101
|
+
<%= RUBY_VERSION %>
|
102
|
+
<%= Time.now %>
|
103
|
+
$ erb -n -x t.erb
|
104
|
+
1 #coding:UTF-8
|
105
|
+
2 _erbout = +''; _erbout.<<(( RUBY_VERSION ).to_s); _erbout.<< "\n".freeze
|
106
|
+
3 ; _erbout.<<(( Time.now ).to_s); _erbout.<< "\n".freeze
|
107
|
+
4 ; _erbout
|
108
|
+
```
|
109
|
+
|
110
|
+
Using option `-n` without option `-x` has no effect:
|
111
|
+
|
112
|
+
```bash
|
113
|
+
$ erb -n t.erb
|
114
|
+
3.4.5
|
115
|
+
2025-09-23 02:44:57 +0100
|
116
|
+
```
|
117
|
+
|
118
|
+
### `-P`: Disable Execution Tag Shorthand
|
119
|
+
|
120
|
+
By default, `erb` enables [execution tag shorthand][execution tag shorthand]:
|
121
|
+
|
122
|
+
```
|
123
|
+
$ cat u.erb
|
124
|
+
% Encoding.list.take(4).each do |encoding|
|
125
|
+
* <%= encoding %>
|
126
|
+
% end
|
127
|
+
$ erb u.erb
|
128
|
+
* ASCII-8BIT
|
129
|
+
* UTF-8
|
130
|
+
* US-ASCII
|
131
|
+
* UTF-16BE
|
132
|
+
```
|
133
|
+
|
134
|
+
You can use option `-P` to disable the shorthand:
|
135
|
+
|
136
|
+
```
|
137
|
+
$ erb -P u.erb # Raises NameError: "undefined local variable or method 'encoding'"
|
138
|
+
```
|
139
|
+
|
140
|
+
### `-r`: Load Library
|
141
|
+
|
142
|
+
You can use option `-r` to load a library;
|
143
|
+
the option may be given multiple times, to load multiple libraries:
|
144
|
+
|
145
|
+
```
|
146
|
+
$ erb -r csv -r bigdecimal t.erb
|
147
|
+
```
|
148
|
+
|
149
|
+
### `-T`: Set Trim Mode
|
150
|
+
|
151
|
+
You can use option `-T` to set the trim mode.
|
152
|
+
|
153
|
+
The values for the option are:
|
154
|
+
|
155
|
+
- `'0'`, meaning `'%'`; enable execution tag shorthand;
|
156
|
+
see [execution tag shorthand][execution tag shorthand].
|
157
|
+
- `'1'`, meaning `'%>'`: enable execution tag shorthand and omit newline for each line ending with `'%>'`;
|
158
|
+
see [suppressing unwanted newlines][suppressing unwanted newlines].
|
159
|
+
- `'2'`, meaning `'<>'`: to suppress the trailing newline for each line
|
160
|
+
that both begins with `'<%'` and ends with `'%>'`;
|
161
|
+
see [suppressing unwanted newlines][suppressing unwanted newlines].
|
162
|
+
- `'-'`, meaning `'%-'`: enable execution tag shorthand and omit each blank line ending with `'-%>'`.
|
163
|
+
see [execution tag shorthand][execution tag shorthand]
|
164
|
+
and [suppressing unwanted blank lines][suppressing unwanted blank lines].
|
165
|
+
|
166
|
+
Example:
|
167
|
+
|
168
|
+
```bash
|
169
|
+
$ erb -T 0 t.erb
|
170
|
+
```
|
171
|
+
|
172
|
+
### `-U`: Set Default Encodings to UTF-8
|
173
|
+
|
174
|
+
You can use option `-U` to set both external and internal encodings to UTF-8:
|
175
|
+
|
176
|
+
```bash
|
177
|
+
$ erb -U t.erb
|
178
|
+
```
|
179
|
+
|
180
|
+
### `-v`: Set $VERBOSE
|
181
|
+
|
182
|
+
Use option `-v` to turn on verbose output:
|
183
|
+
|
184
|
+
```bash
|
185
|
+
$ $ "<%= $VERBOSE %>" | erb
|
186
|
+
"false"
|
187
|
+
$ echo "<%= $VERBOSE %>" | erb -v
|
188
|
+
"true"
|
189
|
+
```
|
190
|
+
|
191
|
+
### `-v`: Print \ERB Version
|
192
|
+
|
193
|
+
Use option `--version` to print the \ERB version string:
|
194
|
+
|
195
|
+
```bash
|
196
|
+
$ erb --version
|
197
|
+
```
|
198
|
+
|
199
|
+
### `-x`: Print Source
|
200
|
+
|
201
|
+
Use option `-x` to print the output of ERB#src,
|
202
|
+
which is the Ruby code that is to be run when ERB#result is called:
|
203
|
+
|
204
|
+
```bash
|
205
|
+
$ cat t.erb
|
206
|
+
<%= RUBY_VERSION %>
|
207
|
+
<%= Time.now %>
|
208
|
+
$ erb -x t.erb
|
209
|
+
#coding:UTF-8
|
210
|
+
_erbout = +''; _erbout.<<(( RUBY_VERSION ).to_s); _erbout.<< "\n".freeze
|
211
|
+
; _erbout.<<(( Time.now ).to_s); _erbout.<< "\n".freeze
|
212
|
+
; _erbout
|
213
|
+
```
|
214
|
+
|
215
|
+
### `--`: End of Options
|
216
|
+
|
217
|
+
You can use option `'--'` to declare the end of options in the `erb` command;
|
218
|
+
`erb` treats each word following as a filepath (even if it looks like an option):
|
219
|
+
|
220
|
+
```
|
221
|
+
erb -- --help # Raises Errno::ENOENT: "No such file or directory @ rb_sysopen - --help"
|
222
|
+
```
|
223
|
+
|
224
|
+
### `name=value`: Set the Value of a Variable
|
225
|
+
|
226
|
+
You can use option `name=value` to set the value of the variable named `name`
|
227
|
+
to the given `value`.
|
228
|
+
|
229
|
+
The option may be given multiple times to set multiple variables:
|
230
|
+
|
231
|
+
```bash
|
232
|
+
$ echo "<%= foo %> <%= bar %>" | erb foo=1 bar=2
|
233
|
+
"1 2"
|
234
|
+
```
|
235
|
+
|
236
|
+
[erb.new]: https://docs.ruby-lang.org/en/master/ERB.html#method-c-new.
|
237
|
+
[execution tag shorthand]: rdoc-ref:ERB@Shorthand+Format+for+Execution+Tags
|
238
|
+
[options]: rdoc-ref:erb_executable.md@Options
|
239
|
+
[suppressing unwanted blank lines]: rdoc-ref:ERB@Suppressing+Unwanted+Blank+Lines
|
240
|
+
[suppressing unwanted newlines]: rdoc-ref:ERB@Suppressing+Unwanted+Newlines
|