erb 2.2.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f3996670474a52bba08a0a8cdeba934a01d09fb7a45047ad14de049823cea90
4
- data.tar.gz: e23035811fc69fb375930eb155ecbf47b67e7991ba7c96fd3c95d6f823e58b6b
3
+ metadata.gz: 853983c0a4e1b81c59b0fee415b27383d0f12c372ea6b534e27f39d1f1ce4022
4
+ data.tar.gz: 568d2f27aa45623fd24e8d65325edf092b9c63154992800589da605e46256869
5
5
  SHA512:
6
- metadata.gz: '09a2991c267e42f6b46f9c629db1596c3238a711e409099c1b50874ded8752d1dd64a9828b6eaec79796b06dab92d402d408c97b24a06eda3e4b12bb8c9e49ac'
7
- data.tar.gz: 4341ca9b16e9e646121dd7e2da710156c6ce71a15983b6c12daaad6fc43fec918b4c57b15b933ff7e6a94a32894e8a458f580f3371300253cb36aaf955b2e07c
6
+ metadata.gz: f7e82ab6f0359e0185529481b05267c6837b9574af77a7fe5d01678fb10a61c8e51677c52a347d178c0c7c8a8f3b93f59e56846a9476020c4230a0a0081ddad7
7
+ data.tar.gz: 3914c61780fc17624f3e6d8848b9c0dcbf6a7ebfbadb1d6b8daecf3ebfc75d12e5ab54ba182fb5d8f1a3e51a00410fd1bf355b4f6c3a0c9a3dccf77c3b5ede51
@@ -3,20 +3,25 @@ name: test
3
3
  on: [push, pull_request]
4
4
 
5
5
  jobs:
6
- build:
6
+ ruby-versions:
7
+ runs-on: ubuntu-latest
8
+ outputs:
9
+ versions: ${{ steps.versions.outputs.value }}
10
+ steps:
11
+ - id: versions
12
+ run: |
13
+ versions=$(curl -s 'https://cache.ruby-lang.org/pub/misc/ci_versions/cruby.json')
14
+ echo "::set-output name=value::${versions}"
15
+ test:
16
+ needs: ruby-versions
7
17
  name: build (${{ matrix.ruby }} / ${{ matrix.os }})
8
18
  strategy:
9
19
  matrix:
10
- ruby:
11
- - '2.5'
12
- - '2.6'
13
- - '2.7'
14
- - '3.0'
15
- - head
20
+ ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
16
21
  os: [ubuntu-latest]
17
22
  runs-on: ${{ matrix.os }}
18
23
  steps:
19
- - uses: actions/checkout@master
24
+ - uses: actions/checkout@v2
20
25
  - name: Set up Ruby
21
26
  uses: ruby/setup-ruby@v1
22
27
  with:
data/NEWS.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.0.0
4
+
5
+ - Bump `required_ruby_version` to Ruby 2.7+ [#23](https://github.com/ruby/erb/pull/23)
6
+ - `ERB::Util.url_encode` uses a native implementation [#23](https://github.com/ruby/erb/pull/23)
7
+ - Fix a bug that a magic comment with a wrong format could be detected [#6](https://github.com/ruby/erb/pull/6)
8
+
9
+ ## 2.2.3
10
+
11
+ - Bump `required_ruby_version` from 2.3 to 2.5 as it has never been supported [#3](https://github.com/ruby/erb/pull/3)
12
+
13
+ ## 2.2.2
14
+
15
+ - `ERB.version` returns just a version number
16
+ - `ERB::Revision` is deprecated
17
+
3
18
  ## 2.2.1
4
19
 
5
20
  - `ERB#initialize` warns `safe_level` and later arguments even without -w
data/README.md CHANGED
@@ -2,31 +2,253 @@
2
2
 
3
3
  An easy to use but powerful templating system for Ruby.
4
4
 
5
- ## Installation
5
+ ## Introduction
6
6
 
7
- Add this line to your application's Gemfile:
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.
8
10
 
9
- ```ruby
10
- gem 'erb'
11
+ A very simple example is this:
12
+
13
+ ```rb
14
+ require 'erb'
15
+
16
+ x = 42
17
+ template = ERB.new <<-EOF
18
+ The value of x is: <%= x %>
19
+ EOF
20
+ puts template.result(binding)
21
+ ```
22
+
23
+ Prints: `The value of x is: 42`
24
+
25
+ More complex examples are given below.
26
+
27
+ ## Recognized Tags
28
+
29
+ ERB recognizes certain tags in the provided template and converts them based
30
+ on the rules below:
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
11
39
  ```
12
40
 
13
- And then execute:
41
+ All other text is passed through ERB filtering unchanged.
42
+
43
+ ## Options
44
+
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.
48
+
49
+ See the ERB.new and ERB#result methods for more detail.
50
+
51
+ ## Character encodings
52
+
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.
57
+
58
+ ```rb
59
+ # -*- coding: utf-8 -*-
60
+ require 'erb'
61
+
62
+ template = ERB.new <<EOF
63
+ <%#-*- coding: Big5 -*-%>
64
+ __ENCODING__ is <%= __ENCODING__ %>.
65
+ EOF
66
+ puts template.result
67
+ ```
14
68
 
15
- $ bundle install
69
+ Prints: `__ENCODING__ is Big5.`
16
70
 
17
- Or install it yourself as:
71
+ ## Examples
18
72
 
19
- $ gem install erb
73
+ ### Plain Text
20
74
 
21
- ## Development
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.
78
+
79
+ ```rb
80
+ require "erb"
81
+
82
+ # Create template.
83
+ template = %q{
84
+ From: James Edward Gray II <james@grayproductions.net>
85
+ To: <%= to %>
86
+ Subject: Addressing Needs
87
+
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
22
125
 
23
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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)
201
+
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!")
212
+
213
+ # Produce result.
214
+ rhtml.run(toy.get_binding)
215
+ ```
216
+
217
+ Generates (some blank lines removed):
218
+
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
+ ```
24
242
 
25
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
243
+ ## Notes
26
244
 
27
- ## Contributing
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.
28
248
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/erb.
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.
30
252
 
31
253
  ## License
32
254
 
data/Rakefile CHANGED
@@ -7,4 +7,11 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList['test/**/test_*.rb']
8
8
  end
9
9
 
10
+ task :sync_tool do
11
+ require 'fileutils'
12
+ FileUtils.cp '../ruby/tool/lib/core_assertions.rb', './test/lib'
13
+ FileUtils.cp '../ruby/tool/lib/envutil.rb', './test/lib'
14
+ FileUtils.cp '../ruby/tool/lib/find_executable.rb', './test/lib'
15
+ end
16
+
10
17
  task default: :test
data/erb.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.summary = %q{An easy to use but powerful templating system for Ruby.}
15
15
  spec.description = %q{An easy to use but powerful templating system for Ruby.}
16
16
  spec.homepage = 'https://github.com/ruby/erb'
17
- spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
17
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
18
18
  spec.licenses = ['Ruby', 'BSD-2-Clause']
19
19
 
20
20
  spec.metadata['homepage_uri'] = spec.homepage
@@ -27,5 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = ['erb']
28
28
  spec.require_paths = ['lib']
29
29
 
30
- spec.add_dependency 'cgi'
30
+ spec.required_ruby_version = ">= 2.7.0"
31
+
32
+ spec.add_dependency 'cgi', '>= 0.3.3'
31
33
  end
data/lib/erb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  class ERB
3
- VERSION = '2.2.2'
3
+ VERSION = '3.0.0'
4
4
  private_constant :VERSION
5
5
  end
data/lib/erb.rb CHANGED
@@ -46,7 +46,7 @@ require 'erb/version'
46
46
  #
47
47
  # <% Ruby code -- inline with output %>
48
48
  # <%= Ruby expression -- replace with result %>
49
- # <%# comment -- ignored -- useful in testing %>
49
+ # <%# comment -- ignored -- useful in testing %> (`<% #` doesn't work. Don't use Ruby comments.)
50
50
  # % a line of Ruby code -- treated as <% line %> (optional -- see ERB.new)
51
51
  # %% replaced with % if first thing on a line and % processing is used
52
52
  # <%% or %%> -- replace with <% or %> respectively
@@ -724,7 +724,7 @@ class ERB
724
724
  frozen = nil
725
725
  s.scan(re) do
726
726
  comment = $+
727
- comment = $1 if comment[/-\*-\s*(.*?)\s*-*-$/]
727
+ comment = $1 if comment[/-\*-\s*([^\s].*?)\s*-\*-$/]
728
728
  case comment
729
729
  when %r"coding\s*[=:]\s*([[:alnum:]\-_]+)"
730
730
  enc = Encoding.find($1.sub(/-(?:mac|dos|unix)/i, ''))
@@ -1019,9 +1019,7 @@ class ERB
1019
1019
  # Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
1020
1020
  #
1021
1021
  def url_encode(s)
1022
- s.to_s.b.gsub(/[^a-zA-Z0-9_\-.~]/n) { |m|
1023
- sprintf("%%%02X", m.unpack1("C"))
1024
- }
1022
+ CGI.escapeURIComponent(s.to_s)
1025
1023
  end
1026
1024
  alias u url_encode
1027
1025
  module_function :u
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masatoshi SEKI
8
8
  autorequire:
9
9
  bindir: libexec
10
10
  cert_chain: []
11
- date: 2021-01-21 00:00:00.000000000 Z
11
+ date: 2022-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cgi
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.3.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.3.3
27
27
  description: An easy to use but powerful templating system for Ruby.
28
28
  email:
29
29
  - seki@ruby-lang.org
@@ -60,14 +60,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 2.3.0
63
+ version: 2.7.0
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.3.0.dev
70
+ rubygems_version: 3.3.7
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: An easy to use but powerful templating system for Ruby.