Skip to content

Commit da9038e

Browse files
committed
Partial template name does no more have to be a valid Ruby identifier
because the partial renderer would not create an lvar per each template since c67005f
1 parent 4ca1dda commit da9038e

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

actionview/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
* Partial template name does no more have to be a valid Ruby identifier.
2+
3+
There used to be a naming rule that the partial name should start with
4+
underscore, and should be followed by any combination of letters, numbers
5+
and underscores.
6+
But now we can give our partials any name starting with underscore, such as
7+
_🍔.html.erb.
8+
9+
*Akira Matsuda*
10+
111
* Change the default template handler from `ERB` to `Raw`.
212

313
Files without a template handler in their extension will be rendered using the raw

actionview/lib/action_view/renderer/partial_renderer.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def retrieve_template_keys
519519
def retrieve_variable(path, as)
520520
variable = as || begin
521521
base = path[-1] == "/" ? "" : File.basename(path)
522-
raise_invalid_identifier(path) unless base =~ /\A_?([a-z]\w*)(\.\w+)*\z/
522+
raise_invalid_identifier(path) unless base =~ /\A_?(.*)(?:\.\w+)*\z/
523523
$1.to_sym
524524
end
525525
if @collection
@@ -530,8 +530,7 @@ def retrieve_variable(path, as)
530530
end
531531

532532
IDENTIFIER_ERROR_MESSAGE = "The partial name (%s) is not a valid Ruby identifier; " +
533-
"make sure your partial name starts with underscore, " +
534-
"and is followed by any combination of letters, numbers and underscores."
533+
"make sure your partial name starts with underscore."
535534

536535
OPTION_AS_ERROR_MESSAGE = "The value (%s) of the option `as` is not a valid Ruby identifier; " +
537536
"make sure it starts with lowercase letter, " +
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
🍣

actionview/test/fixtures/test/_a-in.html.erb

Whitespace-only changes.

actionview/test/template/render_test.rb

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,30 +171,25 @@ def test_render_partial_with_locals_from_default
171171
assert_equal "only partial", @view.render("test/partial_only", :counter_counter => 5)
172172
end
173173

174-
def test_render_partial_with_invalid_name
175-
e = assert_raises(ArgumentError) { @view.render(:partial => "test/200") }
176-
assert_equal "The partial name (test/200) is not a valid Ruby identifier; " +
177-
"make sure your partial name starts with underscore, " +
178-
"and is followed by any combination of letters, numbers and underscores.", e.message
174+
def test_render_partial_with_number
175+
assert_nothing_raised { @view.render(:partial => "test/200") }
179176
end
180177

181178
def test_render_partial_with_missing_filename
182-
e = assert_raises(ArgumentError) { @view.render(:partial => "test/") }
183-
assert_equal "The partial name (test/) is not a valid Ruby identifier; " +
184-
"make sure your partial name starts with underscore, " +
185-
"and is followed by any combination of letters, numbers and underscores.", e.message
179+
assert_raises(ActionView::MissingTemplate) { @view.render(:partial => "test/") }
186180
end
187181

188182
def test_render_partial_with_incompatible_object
189183
e = assert_raises(ArgumentError) { @view.render(:partial => nil) }
190184
assert_equal "'#{nil.inspect}' is not an ActiveModel-compatible object. It must implement :to_partial_path.", e.message
191185
end
192186

187+
def test_render_partial_starting_with_a_capital
188+
assert_nothing_raised { @view.render(:partial => 'test/FooBar') }
189+
end
190+
193191
def test_render_partial_with_hyphen
194-
e = assert_raises(ArgumentError) { @view.render(:partial => "test/a-in") }
195-
assert_equal "The partial name (test/a-in) is not a valid Ruby identifier; " +
196-
"make sure your partial name starts with underscore, " +
197-
"and is followed by any combination of letters, numbers and underscores.", e.message
192+
assert_nothing_raised { @view.render(:partial => "test/a-in") }
198193
end
199194

200195
def test_render_partial_with_invalid_option_as

0 commit comments

Comments
 (0)