erb 6.0.4 → 6.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b25d5fdfe9fee1fe6ecfb1e2e065899b51e0c1c4db0ad2d77684234b68483660
4
- data.tar.gz: cd8460dbde78e4a3989a45bc2f1ac355f8ab949d2f5b15e26fbe4f049da1458b
3
+ metadata.gz: f484b23ae67a9dd0f0e5038f8de3e10b470478d631efea2a5da0f3d26fe393dd
4
+ data.tar.gz: a294f6023602b66ad54e99a39fa90024301964f39e7f6ca68fead5802095c289
5
5
  SHA512:
6
- metadata.gz: dc41315bc958e50efdc1db906e998e9a6808410381be3ec70ffb0f9330b5520c89a5652fa0cf3e605caa237f52c8c5b05c9435d2a77fd08806664fdf769c56a9
7
- data.tar.gz: 9937928ce2742fe22dd16317ea011984046a227782ea71b50c57b8c2d00e41534ae9f548ca8d14d2dc2a87a0fd42367462a75b56ea9e8678783c86ad0d57827a
6
+ metadata.gz: 508eee6aee771568c731d256b165500ea862d969e7d906f758cec61801b4a0d6963d431e86a808036c1be546448fb5b8e9207180e7625c165a6ea304ffa5994d
7
+ data.tar.gz: e4fd77e01b81307eb28af44959ad1974f4d8b4018e1d4d2923ae850c33569f313b0dbcf0124f279bd7312e74dcb0894ea79d472f4ea5be940f5fd5f634a2f22b
data/Gemfile CHANGED
@@ -5,7 +5,12 @@ gemspec
5
5
  group :development do
6
6
  gem 'rake'
7
7
  gem 'rake-compiler'
8
- gem 'rdoc'
8
+ if RUBY_ENGINE == 'jruby'
9
+ # RDoc 8 pulls in RBS 4, which attempts to build a native extension on JRuby.
10
+ gem 'rdoc', '< 8'
11
+ else
12
+ gem 'rdoc'
13
+ end
9
14
  gem 'test-unit'
10
15
  gem "test-unit-ruby-core"
11
16
  end
data/NEWS.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.0.6
4
+
5
+ * Fix `-h` CLI option
6
+
7
+ ## 6.0.5
8
+
9
+ * Avoid overridable method dispatch in the initialization guard
10
+
3
11
  ## 6.0.4
4
12
 
5
13
  * Prohibit `def_method` on marshal-loaded ERB instances
@@ -12,6 +20,10 @@
12
20
 
13
21
  * Freeze `src` in `ERB#initialize` for Ractor compatibility https://github.com/ruby/erb/pull/105
14
22
 
23
+ ## 6.0.1.1
24
+
25
+ * Prohibit `def_method` on marshal-loaded ERB instances
26
+
15
27
  ## 6.0.1
16
28
 
17
29
  * Freeze `ERB::Compiler::TrimScanner::ERB_STAG` for Ractor compatibility
@@ -55,9 +67,17 @@
55
67
  * Drop `cgi` from runtime dependencies [#59](https://github.com/ruby/erb/pull/59)
56
68
  * Make `ERB::VERSION` public
57
69
 
70
+ ## 4.0.4.1
71
+
72
+ * Prohibit `def_method` on marshal-loaded ERB instances
73
+
58
74
  ## 4.0.4
59
75
 
60
- * Skip building the C extension for JRuby [#52](https://github.com/ruby/erb/pull/52)
76
+ * Skip building the C extension for JRuby
77
+
78
+ ## 4.0.3.1
79
+
80
+ * Prohibit `def_method` on marshal-loaded ERB instances
61
81
 
62
82
  ## 4.0.3
63
83
 
data/README.md CHANGED
@@ -8,14 +8,14 @@ ERB is commonly used to produce:
8
8
  - Customized or personalized web pages.
9
9
  - Software code (in code-generating applications).
10
10
 
11
- Like method [sprintf][sprintf], ERB can format run-time data into a string.
12
- ERB, however, is *much more powerful*
11
+ Like method [`sprintf`][sprintf], ERB can format run-time data into a string.
12
+ ERB, however, is *much more powerful*.
13
13
 
14
14
  ## How ERB Works
15
15
 
16
16
  Using ERB, you can create a *template*: a plain-text string that has specially-formatted *tags*,
17
17
  then store it into an ERB object;
18
- when ERB produces _result_ string, it:
18
+ when ERB produces the _result_ string, it:
19
19
 
20
20
  - Inserts run-time-evaluated expressions into the result.
21
21
  - Executes snippets of Ruby code.
@@ -31,30 +31,32 @@ There are three types of tags:
31
31
 
32
32
  | Tag | Form | Action | Text in Result |
33
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. |
34
+ | Expression tag | `<%= ruby_expression %>` | Evaluates `ruby_expression`. | Value of expression. |
35
+ | Execution tag | `<% ruby_code %>` | Executes `ruby_code`. | None. |
36
+ | Comment tag | `<%# comment_text %>` | None. | None. |
37
37
 
38
38
  These examples use `erb`, the ERB command-line interface;
39
39
  each "echoes" a string template and pipes it to `erb` as input:
40
40
 
41
41
 
42
42
  - Expression tag:
43
+ ```bash
44
+ $ echo "<%= \$VERBOSE %>" | erb
45
+ false
43
46
 
44
- $ echo "<%= $VERBOSE %>" | erb
45
- "false"
46
- $ echo "<%= 2 + 2 %>" | erb
47
- "4"
48
-
47
+ $ echo "<%= 2 + 2 %>" | erb
48
+ 4
49
+ ```
49
50
  - Execution tag:
50
-
51
- echo "<% if $VERBOSE %> Long message. <% else %> Short message. <% end %>" | erb
52
- " Short message. "
53
-
51
+ ```bash
52
+ $ echo "<% if \$VERBOSE %> Long message. <% else %> Short message. <% end %>" | erb
53
+ Short message.
54
+ ```
54
55
  - Comment tag:
55
-
56
- echo "<%# TODO: Fix this nonsense. %> Nonsense." | erb
57
- " Nonsense."
56
+ ```bash
57
+ $ echo "<%# TODO: Fix this nonsense. %> Nonsense." | erb
58
+ Nonsense.
59
+ ```
58
60
 
59
61
  ## How to Use ERB
60
62
 
@@ -95,4 +97,4 @@ of the [2-Clause BSD License][2-clause bsd license].
95
97
  [ruby/erb]: https://github.com/ruby/erb
96
98
  [ruby toolbox]: https://www.ruby-toolbox.com/categories/template_engines
97
99
  [sprintf]: https://docs.ruby-lang.org/en/master/Kernel.html#method-i-sprintf
98
- [template processor]: https://en.wikipedia.org/wiki/Template_processor_
100
+ [template processor]: https://en.wikipedia.org/wiki/Template_processor
@@ -10,12 +10,10 @@ For a quick summary, type:
10
10
  $ erb --help
11
11
  ```
12
12
 
13
- The format of the command is
14
- `erb [_options_] [_filepaths_]`,
15
- where:
13
+ The format of the command is `erb [options] [filepaths]`, where:
16
14
 
17
15
  - _options_ are zero or more [options][options].
18
- - _filepaths_ are zero or more paths to files, each containing an plain text
16
+ - _filepaths_ are zero or more paths to files, each containing plain text
19
17
  that can include \ERB tags.
20
18
 
21
19
  ## Filepaths
@@ -27,10 +25,12 @@ that is, `erb` processes multiple files into a single result:
27
25
  $ cat t.erb
28
26
  <%= RUBY_VERSION %>
29
27
  <%= Time.now %>
28
+
30
29
  $ cat u.erb
31
30
  % Encoding.list.take(4).each do |encoding|
32
31
  * <%= encoding %>
33
32
  % end
33
+
34
34
  $ erb t.erb u.erb
35
35
  3.4.5
36
36
  2025-09-24 00:23:00 +0100
@@ -66,21 +66,22 @@ $ echo "<%= RUBY_VERSION %>" | erb # Prints the ERB version string.
66
66
  Use option `-d` or `--debug` to turn on debugging output:
67
67
 
68
68
  ```bash
69
- $ echo "<%= $DEBUG %>" | erb
70
- "false"
71
- $echo "<%= $DEBUG %>" | erb --debug
72
- "true"
69
+ $ echo "<%= \$DEBUG %>" | erb
70
+ false
71
+
72
+ $ echo "<%= \$DEBUG %>" | erb --debug
73
+ true
73
74
  ```
74
75
 
75
76
  ### `-E`, `--encoding`: Set Encodings
76
77
 
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_`.
78
+ Use option `-E ex[:in]` or `--encoding ex[:in]` to set the default external encoding to `ex` and,
79
+ if `in` is given, to set the default internal encoding to `in`.
79
80
 
80
81
  Each encoding, `ex` and `in`, must be the name of an Encoding:
81
82
 
82
- ```
83
- erb -E ASCII-8BIT:ASCII-8BIT t.erb
83
+ ```bash
84
+ $ erb -E ASCII-8BIT:ASCII-8BIT t.erb
84
85
  ```
85
86
 
86
87
  ### `-h`, `--help`: Print Help
@@ -100,6 +101,7 @@ with numbered lines:
100
101
  $ cat t.erb
101
102
  <%= RUBY_VERSION %>
102
103
  <%= Time.now %>
104
+
103
105
  $ erb -n -x t.erb
104
106
  1 #coding:UTF-8
105
107
  2 _erbout = +''; _erbout.<<(( RUBY_VERSION ).to_s); _erbout.<< "\n".freeze
@@ -119,11 +121,12 @@ $ erb -n t.erb
119
121
 
120
122
  By default, `erb` enables [execution tag shorthand][execution tag shorthand]:
121
123
 
122
- ```
124
+ ```bash
123
125
  $ cat u.erb
124
126
  % Encoding.list.take(4).each do |encoding|
125
127
  * <%= encoding %>
126
128
  % end
129
+
127
130
  $ erb u.erb
128
131
  * ASCII-8BIT
129
132
  * UTF-8
@@ -133,7 +136,7 @@ $ erb u.erb
133
136
 
134
137
  You can use option `-P` to disable the shorthand:
135
138
 
136
- ```
139
+ ```bash
137
140
  $ erb -P u.erb # Raises NameError: "undefined local variable or method 'encoding'"
138
141
  ```
139
142
 
@@ -142,7 +145,7 @@ $ erb -P u.erb # Raises NameError: "undefined local variable or method 'encoding
142
145
  You can use option `-r` to load a library;
143
146
  the option may be given multiple times, to load multiple libraries:
144
147
 
145
- ```
148
+ ```bash
146
149
  $ erb -r csv -r bigdecimal t.erb
147
150
  ```
148
151
 
@@ -182,13 +185,14 @@ $ erb -U t.erb
182
185
  Use option `-v` to turn on verbose output:
183
186
 
184
187
  ```bash
185
- $ $ "<%= $VERBOSE %>" | erb
186
- "false"
187
- $ echo "<%= $VERBOSE %>" | erb -v
188
- "true"
188
+ $ echo "<%= \$VERBOSE %>" | erb
189
+ false
190
+
191
+ $ echo "<%= \$VERBOSE %>" | erb -v
192
+ true
189
193
  ```
190
194
 
191
- ### `-v`: Print \ERB Version
195
+ ### `--version`: Print \ERB Version
192
196
 
193
197
  Use option `--version` to print the \ERB version string:
194
198
 
@@ -205,6 +209,7 @@ which is the Ruby code that is to be run when ERB#result is called:
205
209
  $ cat t.erb
206
210
  <%= RUBY_VERSION %>
207
211
  <%= Time.now %>
212
+
208
213
  $ erb -x t.erb
209
214
  #coding:UTF-8
210
215
  _erbout = +''; _erbout.<<(( RUBY_VERSION ).to_s); _erbout.<< "\n".freeze
@@ -230,11 +235,11 @@ The option may be given multiple times to set multiple variables:
230
235
 
231
236
  ```bash
232
237
  $ echo "<%= foo %> <%= bar %>" | erb foo=1 bar=2
233
- "1 2"
238
+ 1 2
234
239
  ```
235
240
 
236
241
  [erb.new]: https://docs.ruby-lang.org/en/master/ERB.html#method-c-new.
237
242
  [execution tag shorthand]: rdoc-ref:ERB@Shorthand+Format+for+Execution+Tags
238
243
  [options]: rdoc-ref:erb_executable.md@Options
239
244
  [suppressing unwanted blank lines]: rdoc-ref:ERB@Suppressing+Unwanted+Blank+Lines
240
- [suppressing unwanted newlines]: rdoc-ref:ERB@Suppressing+Unwanted+Newlines
245
+ [suppressing unwanted newlines]: rdoc-ref:ERB@Suppressing+Unwanted+Newlines
data/lib/erb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  class ERB
3
3
  # The string \ERB version.
4
- VERSION = '6.0.4'
4
+ VERSION = '6.0.6'
5
5
  end
data/lib/erb.rb CHANGED
@@ -53,7 +53,7 @@ require 'erb/util'
53
53
  #
54
54
  # Here's how \ERB works:
55
55
  #
56
- # - You can create a *template*: a plain-text string that includes specially formatted *tags*..
56
+ # - You can create a *template*: a plain-text string that includes specially formatted *tags*.
57
57
  # - You can create an \ERB object to store the template.
58
58
  # - You can call instance method ERB#result to get the *result*.
59
59
  #
@@ -63,10 +63,12 @@ require 'erb/util'
63
63
  # each begins with `'<%='`, ends with `'%>'`; contains a Ruby expression;
64
64
  # in the result, the value of the expression replaces the entire tag:
65
65
  #
66
- # template = 'The magic word is <%= magic_word %>.'
67
- # erb = ERB.new(template)
68
- # magic_word = 'xyzzy'
69
- # erb.result(binding) # => "The magic word is xyzzy."
66
+ # ```
67
+ # template = 'The magic word is <%= magic_word %>.'
68
+ # erb = ERB.new(template)
69
+ # magic_word = 'xyzzy'
70
+ # erb.result(binding) # => "The magic word is xyzzy."
71
+ # ```
70
72
  #
71
73
  # The above call to #result passes argument `binding`,
72
74
  # which contains the binding of variable `magic_word` to its string value `'xyzzy'`.
@@ -74,21 +76,27 @@ require 'erb/util'
74
76
  # The below call to #result need not pass a binding,
75
77
  # because its expression `Date::DAYNAMES` is globally defined.
76
78
  #
77
- # ERB.new('Today is <%= Date::DAYNAMES[Date.today.wday] %>.').result # => "Today is Monday."
79
+ # ```
80
+ # ERB.new('Today is <%= Date::DAYNAMES[Date.today.wday] %>.').result # => "Today is Monday."
81
+ # ```
78
82
  #
79
83
  # - [Execution tags][execution tags]:
80
84
  # each begins with `'<%'`, ends with `'%>'`; contains Ruby code to be executed:
81
85
  #
82
- # template = '<% File.write("t.txt", "Some stuff.") %>'
83
- # ERB.new(template).result
84
- # File.read('t.txt') # => "Some stuff."
86
+ # ```
87
+ # template = '<% File.write("t.txt", "Some stuff.") %>'
88
+ # ERB.new(template).result
89
+ # File.read('t.txt') # => "Some stuff."
90
+ # ```
85
91
  #
86
92
  # - [Comment tags][comment tags]:
87
93
  # each begins with `'<%#'`, ends with `'%>'`; contains comment text;
88
94
  # in the result, the entire tag is omitted.
89
95
  #
90
- # template = 'Some stuff;<%# Note to self: figure out what the stuff is. %> more stuff.'
91
- # ERB.new(template).result # => "Some stuff; more stuff."
96
+ # ```
97
+ # template = 'Some stuff;<%# Note to self: figure out what the stuff is. %> more stuff.'
98
+ # ERB.new(template).result # => "Some stuff; more stuff."
99
+ # ```
92
100
  #
93
101
  # ## Some Simple Examples
94
102
  #
@@ -106,11 +114,10 @@ require 'erb/util'
106
114
  # 1. A plain-text string is assigned to variable `template`.
107
115
  # Its embedded [expression tag][expression tags] `'<%= Time.now %>'` includes a Ruby expression, `Time.now`.
108
116
  # 2. The string is put into a new \ERB object, and stored in variable `erb`.
109
- # 4. Method call `erb.result` generates a string that contains the run-time value of `Time.now`,
117
+ # 3. Method call `erb.result` generates a string that contains the run-time value of `Time.now`,
110
118
  # as computed at the time of the call.
111
119
  #
112
- # The
113
- # \ERB object may be re-used:
120
+ # The \ERB object may be re-used:
114
121
  #
115
122
  # ```
116
123
  # erb.result
@@ -148,14 +155,14 @@ require 'erb/util'
148
155
  # ## Bindings
149
156
  #
150
157
  # A call to method #result, which produces the formatted result string,
151
- # requires a [Binding object][binding object] as its argument.
158
+ # requires a [`Binding` object][binding object] as its argument.
152
159
  #
153
160
  # The binding object provides the bindings for expressions in [expression tags][expression tags].
154
161
  #
155
162
  # There are three ways to provide the required binding:
156
163
  #
157
- # - [Default binding][default binding].
158
- # - [Local binding][local binding].
164
+ # - [Default binding][default binding]
165
+ # - [Local binding][local binding]
159
166
  # - [Augmented binding][augmented binding]
160
167
  #
161
168
  # ### Default Binding
@@ -174,6 +181,9 @@ require 'erb/util'
174
181
  # The current process is <%= $0 %>.
175
182
  # TEMPLATE
176
183
  # puts ERB.new(template).result
184
+ # ```
185
+ #
186
+ # ```
177
187
  # The Ruby copyright is "ruby - Copyright (C) 1993-2025 Yukihiro Matsumoto".
178
188
  # The current process is irb.
179
189
  # ```
@@ -183,7 +193,7 @@ require 'erb/util'
183
193
  # ### Local Binding
184
194
  #
185
195
  # The default binding is *not* sufficient for an expression
186
- # that refers to a a constant or variable that is not defined there:
196
+ # that refers to a constant or variable that is not defined there:
187
197
  #
188
198
  # ```
189
199
  # Foo = 1 # Defines local constant Foo.
@@ -209,6 +219,9 @@ require 'erb/util'
209
219
  #
210
220
  # ```
211
221
  # puts erb.result(binding)
222
+ # ```
223
+ #
224
+ # ```
212
225
  # The current value of constant Foo is 1.
213
226
  # The current value of variable foo is 2.
214
227
  # The Ruby copyright is "ruby - Copyright (C) 1993-2025 Yukihiro Matsumoto".
@@ -246,6 +259,9 @@ require 'erb/util'
246
259
  # ```
247
260
  # hash = {bar: 3, baz: 4}
248
261
  # puts erb.result_with_hash(hash)
262
+ # ```
263
+ #
264
+ # ```
249
265
  # The current value of variable bar is 3.
250
266
  # The current value of variable baz is 4.
251
267
  # The Ruby copyright is "ruby - Copyright (C) 1993-2025 Yukihiro Matsumoto".
@@ -268,7 +284,7 @@ require 'erb/util'
268
284
  #
269
285
  # You can embed a Ruby expression in a template using an *expression tag*.
270
286
  #
271
- # Its syntax is `<%= _expression_ %>`,
287
+ # Its syntax is `<%= expression %>`,
272
288
  # where *expression* is any valid Ruby expression.
273
289
  #
274
290
  # When you call method #result,
@@ -298,7 +314,7 @@ require 'erb/util'
298
314
  #
299
315
  # You can embed Ruby executable code in template using an *execution tag*.
300
316
  #
301
- # Its syntax is `<% _code_ %>`,
317
+ # Its syntax is `<% code %>`,
302
318
  # where *code* is any valid Ruby code.
303
319
  #
304
320
  # When you call method #result,
@@ -306,17 +322,17 @@ require 'erb/util'
306
322
  # (generating no text in the result):
307
323
  #
308
324
  # ```
309
- # ERB.new('foo <% Dir.chdir("C:/") %> bar').result # => "foo bar"
325
+ # ERB.new('foo <% Dir.chdir(Dir.pwd) %> bar').result # => "foo bar"
310
326
  # ```
311
327
  #
312
328
  # Whitespace before and after the embedded code is optional:
313
329
  #
314
330
  # ```
315
- # ERB.new('foo <%Dir.chdir("C:/")%> bar').result # => "foo bar"
331
+ # ERB.new('foo <%Dir.chdir(Dir.pwd)%> bar').result # => "foo bar"
316
332
  # ```
317
333
  #
318
334
  # You can interleave text with execution tags to form a control structure
319
- # such as a conditional, a loop, or a `case` statements.
335
+ # such as a conditional, a loop, or a `case` statement.
320
336
  #
321
337
  # Conditional:
322
338
  #
@@ -386,7 +402,7 @@ require 'erb/util'
386
402
  # #### Shorthand Format for Execution Tags
387
403
  #
388
404
  # You can use keyword argument `trim_mode: '%'` to enable a shorthand format for execution tags;
389
- # this example uses the shorthand format `% _code_` instead of `<% _code_ %>`:
405
+ # this example uses the shorthand format `% code` instead of `<% code %>`:
390
406
  #
391
407
  # ```
392
408
  # template = <<TEMPLATE
@@ -399,6 +415,9 @@ require 'erb/util'
399
415
  # 'Document Modules',
400
416
  # 'Answer Questions on Ruby Talk' ]
401
417
  # puts erb.result(binding)
418
+ # ```
419
+ #
420
+ # ```
402
421
  # * Run Ruby Quiz
403
422
  # * Document Modules
404
423
  # * Answer Questions on Ruby Talk
@@ -419,12 +438,15 @@ require 'erb/util'
419
438
  # <% end %>
420
439
  # TEMPLATE
421
440
  # ERB.new(template).result.lines.each {|line| puts line.inspect }
441
+ # ```
442
+ #
443
+ # ```
422
444
  # "\n"
423
445
  # "3.4.5\n"
424
446
  # "\n"
425
447
  # ```
426
448
  #
427
- # You can give `trim_mode: '-'`, you can suppress each blank line
449
+ # If you give `trim_mode: '-'`, you can suppress each blank line
428
450
  # whose source line ends with `-%>` (instead of `%>`):
429
451
  #
430
452
  # ```
@@ -434,6 +456,9 @@ require 'erb/util'
434
456
  # <% end -%>
435
457
  # TEMPLATE
436
458
  # ERB.new(template, trim_mode: '-').result.lines.each {|line| puts line.inspect }
459
+ # ```
460
+ #
461
+ # ```
437
462
  # "3.4.5\n"
438
463
  # ```
439
464
  #
@@ -460,6 +485,9 @@ require 'erb/util'
460
485
  #
461
486
  # ```
462
487
  # ERB.new(template).result.lines.each {|line| puts line.inspect }
488
+ # ```
489
+ #
490
+ # ```
463
491
  # "\n"
464
492
  # "3.4.5\n"
465
493
  # "foo \n"
@@ -471,6 +499,9 @@ require 'erb/util'
471
499
  #
472
500
  # ```
473
501
  # ERB.new(template, trim_mode: '>').result.lines.each {|line| puts line.inspect }
502
+ # ```
503
+ #
504
+ # ```
474
505
  # "3.4.5foo foo 3.4.5"
475
506
  # ```
476
507
  #
@@ -479,6 +510,9 @@ require 'erb/util'
479
510
  #
480
511
  # ```
481
512
  # ERB.new(template, trim_mode: '<>').result.lines.each {|line| puts line.inspect }
513
+ # ```
514
+ #
515
+ # ```
482
516
  # "3.4.5foo \n"
483
517
  # "foo 3.4.5\n"
484
518
  # ```
@@ -494,7 +528,7 @@ require 'erb/util'
494
528
  # ### Comment Tags
495
529
  #
496
530
  # You can embed a comment in a template using a *comment tag*;
497
- # its syntax is `<%# _text_ %>`,
531
+ # its syntax is `<%# text %>`,
498
532
  # where *text* is the text of the comment.
499
533
  #
500
534
  # When you call method #result,
@@ -570,7 +604,7 @@ require 'erb/util'
570
604
  # erb.filename # => nil
571
605
  # erb.lineno # => 0
572
606
  # erb.result
573
- # (erb):1:in '<main>': undefined local variable or method 'nosuch' for main (NameError)
607
+ # # => (erb):1:in '<main>': undefined local variable or method 'nosuch' for main (NameError)
574
608
  # ```
575
609
  #
576
610
  # You can use methods #filename= and #lineno= to assign values
@@ -580,7 +614,7 @@ require 'erb/util'
580
614
  # erb.filename = 't.txt'
581
615
  # erb.lineno = 555
582
616
  # erb.result
583
- # t.txt:556:in '<main>': undefined local variable or method 'nosuch' for main (NameError)
617
+ # # => t.txt:556:in '<main>': undefined local variable or method 'nosuch' for main (NameError)
584
618
  # ```
585
619
  #
586
620
  # You can use method #location= to set both values:
@@ -588,7 +622,7 @@ require 'erb/util'
588
622
  # ```
589
623
  # erb.location = ['u.txt', 999]
590
624
  # erb.result
591
- # u.txt:1000:in '<main>': undefined local variable or method 'nosuch' for main (NameError)
625
+ # # => u.txt:1000:in '<main>': undefined local variable or method 'nosuch' for main (NameError)
592
626
  # ```
593
627
  #
594
628
  # ## Plain Text with Embedded Ruby
@@ -632,12 +666,14 @@ require 'erb/util'
632
666
  # 'Answer Questions on Ruby Talk' ]
633
667
  # ```
634
668
  #
635
- # Finally, create the \ERB object and get the result
669
+ # Finally, create the \ERB object and get the result:
636
670
  #
637
671
  # ```
638
672
  # erb = ERB.new(template, trim_mode: '%<>')
639
673
  # puts erb.result(binding)
674
+ # ```
640
675
  #
676
+ # ```
641
677
  # From: James Edward Gray II <james@grayproductions.net>
642
678
  # To: Community Spokesman <spokesman@ruby_community.org>
643
679
  # Subject: Addressing Needs
@@ -683,7 +719,6 @@ require 'erb/util'
683
719
  # def get_binding
684
720
  # binding
685
721
  # end
686
- #
687
722
  # end
688
723
  # ```
689
724
  #
@@ -693,8 +728,7 @@ require 'erb/util'
693
728
  # toy = Product.new('TZ-1002',
694
729
  # 'Rubysapien',
695
730
  # "Geek's Best Friend! Responds to Ruby commands...",
696
- # 999.95
697
- # )
731
+ # 999.95)
698
732
  # toy.add_feature('Listens for verbal commands in the Ruby language!')
699
733
  # toy.add_feature('Ignores Perl, Java, and all C variants.')
700
734
  # toy.add_feature('Karate-Chop Action!!!')
@@ -733,6 +767,9 @@ require 'erb/util'
733
767
  # ```
734
768
  # erb = ERB.new(template)
735
769
  # puts erb.result(toy.get_binding)
770
+ # ```
771
+ #
772
+ # ```html
736
773
  # <html>
737
774
  # <head><title>Ruby Toys -- Rubysapien</title></head>
738
775
  # <body>
@@ -758,7 +795,7 @@ require 'erb/util'
758
795
  # Various Ruby projects have their own template processors.
759
796
  # The Ruby Processing System [RDoc][rdoc], for example, has one that can be used elsewhere.
760
797
  #
761
- # Other popular template processors may found in the [Template Engines][template engines] page
798
+ # Other popular template processors may be found in the [Template Engines][template engines] page
762
799
  # of the Ruby Toolbox.
763
800
  #
764
801
  # [%q literals]: https://docs.ruby-lang.org/en/master/syntax/literals_rdoc.html#label-25q-3A+Non-Interpolable+String+Literals
@@ -778,6 +815,9 @@ require 'erb/util'
778
815
  # [template processor]: https://en.wikipedia.org/wiki/Template_processor
779
816
  #
780
817
  class ERB
818
+ IDENTITY_METHOD = BasicObject.instance_method(:equal?) # :nodoc:
819
+ private_constant :IDENTITY_METHOD
820
+
781
821
  # :markup: markdown
782
822
  #
783
823
  # :call-seq:
@@ -793,7 +833,7 @@ class ERB
793
833
  # :call-seq:
794
834
  # ERB.new(template, trim_mode: nil, eoutvar: '_erbout')
795
835
  #
796
- # Returns a new \ERB object containing the given string +template+.
836
+ # Returns a new \ERB object containing the given string `template`.
797
837
  #
798
838
  # For details about `template`, its embedded tags, and generated results, see ERB.
799
839
  #
@@ -874,13 +914,16 @@ class ERB
874
914
  # In a more readable format:
875
915
  #
876
916
  # ```
877
- # # puts erb.src.split('; ')
878
- # # #coding:UTF-8
879
- # # _erbout = +''
880
- # # _erbout.<< "The time is ".freeze
881
- # # _erbout.<<(( Time.now ).to_s)
882
- # # _erbout.<< ".".freeze
883
- # # _erbout
917
+ # puts erb.src.split('; ')
918
+ # ```
919
+ #
920
+ # ```
921
+ # #coding:UTF-8
922
+ # _erbout = +''
923
+ # _erbout.<< "The time is ".freeze
924
+ # _erbout.<<(( Time.now ).to_s)
925
+ # _erbout.<< ".".freeze
926
+ # _erbout
884
927
  # ```
885
928
  #
886
929
  # Variable `_erbout` is used to store the intermediate results in the code;
@@ -889,7 +932,10 @@ class ERB
889
932
  #
890
933
  # ```
891
934
  # erb = ERB.new(template, eoutvar: '_foo')
892
- # puts template.src.split('; ')
935
+ # puts erb.src.split('; ')
936
+ # ```
937
+ #
938
+ # ```
893
939
  # #coding:UTF-8
894
940
  # _foo = +''
895
941
  # _foo.<< "The time is ".freeze
@@ -952,6 +998,9 @@ class ERB
952
998
  # template = ERB.new('')
953
999
  # compiler = template.make_compiler(nil)
954
1000
  # pp compiler
1001
+ # ```
1002
+ #
1003
+ # ```
955
1004
  # #<ERB::Compiler:0x000001cff8a9aa00
956
1005
  # @insert_cmd="print",
957
1006
  # @percent=false,
@@ -959,8 +1008,14 @@ class ERB
959
1008
  # @pre_cmd=[],
960
1009
  # @put_cmd="print",
961
1010
  # @trim_mode=nil>
1011
+ # ```
1012
+ #
1013
+ # ```
962
1014
  # template.set_eoutvar(compiler, '_foo') # => ["_foo"]
963
1015
  # pp compiler
1016
+ # ```
1017
+ #
1018
+ # ```
964
1019
  # #<ERB::Compiler:0x000001cff8a9aa00
965
1020
  # @insert_cmd="_foo.<<",
966
1021
  # @percent=false,
@@ -1007,7 +1062,7 @@ class ERB
1007
1062
  # [local binding]: rdoc-ref:ERB@Local+Binding
1008
1063
  #
1009
1064
  def result(b=new_toplevel)
1010
- unless @_init.equal?(self.class.singleton_class)
1065
+ unless initialized_by_new?
1011
1066
  raise ArgumentError, "not initialized"
1012
1067
  end
1013
1068
  eval(@src, b, (@filename || '(erb)'), @lineno)
@@ -1061,6 +1116,11 @@ class ERB
1061
1116
  end
1062
1117
  private :new_toplevel
1063
1118
 
1119
+ def initialized_by_new? # :nodoc:
1120
+ IDENTITY_METHOD.bind_call(@_init, self.class.singleton_class)
1121
+ end
1122
+ private :initialized_by_new?
1123
+
1064
1124
  # :markup: markdown
1065
1125
  #
1066
1126
  # :call-seq:
@@ -1083,11 +1143,12 @@ class ERB
1083
1143
  # MyModule = Module.new
1084
1144
  # erb.def_method(MyModule, 'render(arg1, arg2)') # => :render
1085
1145
  # class MyClass; include MyModule; end
1086
- # MyClass.new.render('foo', 123) # => "foo 123"
1146
+ # MyClass.new.render('foo', 123)
1147
+ # # => "foo 123"
1087
1148
  # ```
1088
1149
  #
1089
1150
  def def_method(mod, methodname, fname='(ERB)')
1090
- unless @_init.equal?(self.class.singleton_class)
1151
+ unless initialized_by_new?
1091
1152
  raise ArgumentError, "not initialized"
1092
1153
  end
1093
1154
  src = self.src.sub(/^(?!#|$)/) {"def #{methodname}\n"} << "\nend\n"
@@ -1106,7 +1167,7 @@ class ERB
1106
1167
  # ```
1107
1168
  # template = '<%= arg1 %> <%= arg2 %>'
1108
1169
  # erb = ERB.new(template)
1109
- # MyModule = template.def_module('render(arg1, arg2)')
1170
+ # MyModule = erb.def_module('render(arg1, arg2)')
1110
1171
  # class MyClass
1111
1172
  # include MyModule
1112
1173
  # end
@@ -1163,6 +1224,9 @@ class ERB
1163
1224
  #
1164
1225
  # ```
1165
1226
  # puts MySubClass.new('foo', 123).render
1227
+ # ```
1228
+ #
1229
+ # ```html
1166
1230
  # <html>
1167
1231
  # <body>
1168
1232
  # <p>foo</p>
data/libexec/erb CHANGED
@@ -89,7 +89,7 @@ class ERB
89
89
  set_encoding(Encoding::UTF_8, Encoding::UTF_8)
90
90
  when '-P'
91
91
  disable_percent = true
92
- when '--help'
92
+ when '-h', '--help'
93
93
  raise ''
94
94
  when /\A-/
95
95
  raise "Unknown switch: #{switch.dump}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.4
4
+ version: 6.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masatoshi SEKI
@@ -50,7 +50,7 @@ licenses:
50
50
  metadata:
51
51
  homepage_uri: https://github.com/ruby/erb
52
52
  source_code_uri: https://github.com/ruby/erb
53
- changelog_uri: https://github.com/ruby/erb/blob/v6.0.4/NEWS.md
53
+ changelog_uri: https://github.com/ruby/erb/blob/v6.0.6/NEWS.md
54
54
  rdoc_options: []
55
55
  require_paths:
56
56
  - lib