提交 da9038ea 编写于 作者: A Akira Matsuda

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 c67005f2
上级 4ca1dda0
* Partial template name does no more have to be a valid Ruby identifier.
There used to be a naming rule that the partial name should start with
underscore, and should be followed by any combination of letters, numbers
and underscores.
But now we can give our partials any name starting with underscore, such as
_🍔.html.erb.
*Akira Matsuda*
* Change the default template handler from `ERB` to `Raw`. * Change the default template handler from `ERB` to `Raw`.
Files without a template handler in their extension will be rendered using the raw Files without a template handler in their extension will be rendered using the raw
......
...@@ -519,7 +519,7 @@ def retrieve_template_keys ...@@ -519,7 +519,7 @@ def retrieve_template_keys
def retrieve_variable(path, as) def retrieve_variable(path, as)
variable = as || begin variable = as || begin
base = path[-1] == "/" ? "" : File.basename(path) base = path[-1] == "/" ? "" : File.basename(path)
raise_invalid_identifier(path) unless base =~ /\A_?([a-z]\w*)(\.\w+)*\z/ raise_invalid_identifier(path) unless base =~ /\A_?(.*)(?:\.\w+)*\z/
$1.to_sym $1.to_sym
end end
if @collection if @collection
...@@ -530,8 +530,7 @@ def retrieve_variable(path, as) ...@@ -530,8 +530,7 @@ def retrieve_variable(path, as)
end end
IDENTIFIER_ERROR_MESSAGE = "The partial name (%s) is not a valid Ruby identifier; " + IDENTIFIER_ERROR_MESSAGE = "The partial name (%s) is not a valid Ruby identifier; " +
"make sure your partial name starts with underscore, " + "make sure your partial name starts with underscore."
"and is followed by any combination of letters, numbers and underscores."
OPTION_AS_ERROR_MESSAGE = "The value (%s) of the option `as` is not a valid Ruby identifier; " + OPTION_AS_ERROR_MESSAGE = "The value (%s) of the option `as` is not a valid Ruby identifier; " +
"make sure it starts with lowercase letter, " + "make sure it starts with lowercase letter, " +
......
...@@ -171,18 +171,12 @@ def test_render_partial_with_locals_from_default ...@@ -171,18 +171,12 @@ def test_render_partial_with_locals_from_default
assert_equal "only partial", @view.render("test/partial_only", :counter_counter => 5) assert_equal "only partial", @view.render("test/partial_only", :counter_counter => 5)
end end
def test_render_partial_with_invalid_name def test_render_partial_with_number
e = assert_raises(ArgumentError) { @view.render(:partial => "test/200") } assert_nothing_raised { @view.render(:partial => "test/200") }
assert_equal "The partial name (test/200) is not a valid Ruby identifier; " +
"make sure your partial name starts with underscore, " +
"and is followed by any combination of letters, numbers and underscores.", e.message
end end
def test_render_partial_with_missing_filename def test_render_partial_with_missing_filename
e = assert_raises(ArgumentError) { @view.render(:partial => "test/") } assert_raises(ActionView::MissingTemplate) { @view.render(:partial => "test/") }
assert_equal "The partial name (test/) is not a valid Ruby identifier; " +
"make sure your partial name starts with underscore, " +
"and is followed by any combination of letters, numbers and underscores.", e.message
end end
def test_render_partial_with_incompatible_object def test_render_partial_with_incompatible_object
...@@ -190,11 +184,12 @@ def test_render_partial_with_incompatible_object ...@@ -190,11 +184,12 @@ def test_render_partial_with_incompatible_object
assert_equal "'#{nil.inspect}' is not an ActiveModel-compatible object. It must implement :to_partial_path.", e.message assert_equal "'#{nil.inspect}' is not an ActiveModel-compatible object. It must implement :to_partial_path.", e.message
end end
def test_render_partial_starting_with_a_capital
assert_nothing_raised { @view.render(:partial => 'test/FooBar') }
end
def test_render_partial_with_hyphen def test_render_partial_with_hyphen
e = assert_raises(ArgumentError) { @view.render(:partial => "test/a-in") } assert_nothing_raised { @view.render(:partial => "test/a-in") }
assert_equal "The partial name (test/a-in) is not a valid Ruby identifier; " +
"make sure your partial name starts with underscore, " +
"and is followed by any combination of letters, numbers and underscores.", e.message
end end
def test_render_partial_with_invalid_option_as def test_render_partial_with_invalid_option_as
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册