erb 5.0.2 → 6.0.1

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: fd7e6b214a06aba5808f5137a14e9c79edc9d4b903e6a2c2bced832d1c30aaf7
4
- data.tar.gz: 45213b43da5c2ee0dc330a6514d43b8a9192d5c404ef57ae72cdedba55ae94e5
3
+ metadata.gz: 5ab026054417af85a9a1ed3b4c13baf164c372ad658eca2e3268b9a2274ac7bc
4
+ data.tar.gz: fa4a74443e4fc60595fe1866156bd9f1cafe8af1af87855d4cd0ff26d505152a
5
5
  SHA512:
6
- metadata.gz: 8617e29b0c2ddb43483ec2b1c31d0edd2f84da054507a0a4216c9a1ef389ac924e8416e214103f98d6e36e9cc7e1e840867e569c4dec07a26180e7d51290b5d2
7
- data.tar.gz: ba3620ef2aeb6932f31b3f2dadc95d942c66a2ad3bd5d02307ad62ee80770d10479ce0485d19798f6f71a6ec9d40fee95e3bdb3a8bf24ae78d4e6a4c40256778
6
+ metadata.gz: 88e13e5d324d17e53d22aa6e2ca8aeb40499d91b43d5773e3717442dff92555d0af8feb17ea3010f299f11e738bacd1f110db3e5020a3fc90b3cdf593681722c
7
+ data.tar.gz: 3873dec50bbb24b9701a7f0728e7b82680dc3971252a8b35216d17a75d8c8887d4747acdf914a8707897824d2e6eb9efaaf2ecd970cd5162e846755d4dfb22fe
@@ -3,4 +3,4 @@ updates:
3
3
  - package-ecosystem: 'github-actions'
4
4
  directory: '/'
5
5
  schedule:
6
- interval: 'weekly'
6
+ interval: 'monthly'
@@ -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,51 @@
1
+ name: Publish gem to rubygems.org
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ push:
13
+ if: github.repository_owner == 'ruby'
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ ruby: [ruby, jruby]
18
+ fail-fast: false
19
+
20
+ environment:
21
+ name: rubygems.org
22
+ url: https://rubygems.org/gems/erb
23
+
24
+ permissions:
25
+ contents: write
26
+ id-token: write
27
+
28
+ steps:
29
+ - name: Harden Runner
30
+ uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2
31
+ with:
32
+ egress-policy: audit
33
+
34
+ - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
35
+
36
+ - name: Set up Ruby
37
+ uses: ruby/setup-ruby@d5126b9b3579e429dd52e51e68624dda2e05be25 # v1.267.0
38
+ with:
39
+ bundler-cache: true
40
+ ruby-version: ${{ matrix.ruby }}
41
+
42
+ - name: Publish to RubyGems
43
+ uses: rubygems/release-gem@1c162a739e8b4cb21a676e97b087e8268d8fc40b # v1.1.2
44
+
45
+ - name: Create GitHub release
46
+ run: |
47
+ tag_name="$(git describe --tags --abbrev=0)"
48
+ gh release create "${tag_name}" --verify-tag --generate-notes
49
+ env:
50
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51
+ if: ${{ matrix.ruby == 'ruby' }}
@@ -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_owner == 'ruby' }}
10
+ steps:
11
+ - uses: actions/checkout@v6
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":"${{ github.event.repository.name }}","before":"${{ github.event.before }}","after":"${{ github.event.after }}"}
32
+ propagate_failure: true
33
+ wait_interval: 10
@@ -23,7 +23,7 @@ jobs:
23
23
  fail-fast: false
24
24
  runs-on: ${{ matrix.os }}
25
25
  steps:
26
- - uses: actions/checkout@v4
26
+ - uses: actions/checkout@v6
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 --visibility=private .
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gemspec
5
5
  group :development do
6
6
  gem 'rake'
7
7
  gem 'rake-compiler'
8
+ gem 'rdoc'
8
9
  gem 'test-unit'
9
10
  gem "test-unit-ruby-core"
10
11
  end
data/NEWS.md CHANGED
@@ -1,4 +1,33 @@
1
- # Change Log
1
+ # Changelog
2
+
3
+ ## 6.0.1
4
+
5
+ * Freeze `ERB::Compiler::TrimScanner::ERB_STAG` for Ractor compatibility
6
+
7
+ ## 6.0.0
8
+
9
+ * Remove `safe_level` and further positional arguments from `ERB.new`
10
+ * Remove deprecated constant `ERB::Revision`
11
+
12
+ ## 5.1.3
13
+
14
+ * Release v5.1.2 with trusted publishing for JRuby
15
+
16
+ ## 5.1.2
17
+
18
+ * Add `changelog_uri` to spec metadata https://github.com/ruby/erb/pull/89
19
+
20
+ ## 5.1.1
21
+
22
+ * Fix integer overflow that is introduced at v5.1.0
23
+
24
+ ## 5.1.0
25
+
26
+ * html_escape: Avoid buffer allocation for strings with no escapable character https://github.com/ruby/erb/pull/87
27
+
28
+ ## 5.0.3
29
+
30
+ * Update help of erb(1) [#85](https://github.com/ruby/erb/pull/85)
2
31
 
3
32
  ## 5.0.2
4
33
 
data/README.md CHANGED
@@ -1,255 +1,98 @@
1
- # ERB
1
+ # ERB (Embedded Ruby)
2
2
 
3
- An easy to use but powerful templating system for Ruby.
3
+ ERB is an easy-to-use, but also very powerful, [template processor][template processor].
4
4
 
5
- ## Introduction
5
+ ERB is commonly used to produce:
6
6
 
7
- ERB provides an easy to use but powerful templating system for Ruby. Using
8
- ERB, actual Ruby code can be added to any plain text document for the
9
- purposes of generating document information details and/or flow control.
7
+ - Customized or personalized email messages.
8
+ - Customized or personalized web pages.
9
+ - Software code (in code-generating applications).
10
10
 
11
- A very simple example is this:
11
+ Like method [sprintf][sprintf], ERB can format run-time data into a string.
12
+ ERB, however, is *much more powerful*
12
13
 
13
- ```rb
14
- require 'erb'
14
+ ## How ERB Works
15
15
 
16
- x = 42
17
- template = ERB.new <<-EOF
18
- The value of x is: <%= x %>
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
- Prints: `The value of x is: 42`
20
+ - Inserts run-time-evaluated expressions into the result.
21
+ - Executes snippets of Ruby code.
22
+ - Omits comments from the results.
24
23
 
25
- More complex examples are given below.
24
+ In the result:
26
25
 
27
- ## Recognized Tags
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
- ERB recognizes certain tags in the provided template and converts them based
30
- on the rules below:
30
+ There are three types of tags:
31
31
 
32
- ```erb
33
- <% Ruby code -- inline with output %>
34
- <%= Ruby expression -- replace with result %>
35
- <%# comment -- ignored -- useful in testing %> (`<% #` doesn't work. Don't use Ruby comments.)
36
- % a line of Ruby code -- treated as <% line %> (optional -- see ERB.new)
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
- All other text is passed through ERB filtering unchanged.
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
- There are several settings you can change when you use ERB:
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
- See the ERB.new and ERB#result methods for more detail.
44
+ $ echo "<%= $VERBOSE %>" | erb
45
+ "false"
46
+ $ echo "<%= 2 + 2 %>" | erb
47
+ "4"
50
48
 
51
- ## Character encodings
49
+ - Execution tag:
52
50
 
53
- ERB (or Ruby code generated by ERB) returns a string in the same
54
- character encoding as the input string. When the input string has
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
- ```rb
59
- # -*- coding: utf-8 -*-
60
- require 'erb'
54
+ - Comment tag:
61
55
 
62
- template = ERB.new <<EOF
63
- <%#-*- coding: Big5 -*-%>
64
- __ENCODING__ is <%= __ENCODING__ %>.
65
- EOF
66
- puts template.result
67
- ```
56
+ echo "<%# TODO: Fix this nonsense. %> Nonsense." | erb
57
+ " Nonsense."
68
58
 
69
- Prints: `__ENCODING__ is Big5.`
59
+ ## How to Use ERB
70
60
 
71
- ## Examples
61
+ You can use ERB either:
72
62
 
73
- ### Plain Text
63
+ - In a program: see class ERB.
64
+ - From the command line: see [ERB Executable][erb executable].
74
65
 
75
- ERB is useful for any generic templating situation. Note that in this example, we use the
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
- ```rb
80
- require "erb"
68
+ ERB is installed with Ruby, and so there's no further installation needed.
81
69
 
82
- # Create template.
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
- <%= to[/\w+/] %>:
89
-
90
- Just wanted to send a quick note assuring that your needs are being
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
- # Set up template data.
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
- # Produce result.
214
- rhtml.run(toy.get_binding)
215
- ```
78
+ ## Code
216
79
 
217
- Generates (some blank lines removed):
80
+ The ERB source code is in GitHub project [ruby/erb][ruby/erb].
218
81
 
219
- ```html
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
- Other popular engines could be found in the corresponding
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
- The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
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_