From da9038eaa5d19c77c734a044c6b35d7bfac01104 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 6 Feb 2015 00:18:05 +0900 Subject: 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 c67005f221f102fe2caca231027d9b11cf630484 --- actionview/CHANGELOG.md | 10 ++++++++++ .../lib/action_view/renderer/partial_renderer.rb | 5 ++--- actionview/test/fixtures/test/_FooBar.html.erb | 1 + actionview/test/fixtures/test/_a-in.html.erb | 0 actionview/test/template/render_test.rb | 21 ++++++++------------- 5 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 actionview/test/fixtures/test/_FooBar.html.erb create mode 100644 actionview/test/fixtures/test/_a-in.html.erb (limited to 'actionview') diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 743c01e393..7fc32a3b5c 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,13 @@ +* 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`. Files without a template handler in their extension will be rendered using the raw diff --git a/actionview/lib/action_view/renderer/partial_renderer.rb b/actionview/lib/action_view/renderer/partial_renderer.rb index 6c3015180a..5ff15411cf 100644 --- a/actionview/lib/action_view/renderer/partial_renderer.rb +++ b/actionview/lib/action_view/renderer/partial_renderer.rb @@ -519,7 +519,7 @@ module ActionView def retrieve_variable(path, as) variable = as || begin 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 end if @collection @@ -530,8 +530,7 @@ module ActionView end IDENTIFIER_ERROR_MESSAGE = "The partial name (%s) 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." + "make sure your partial name starts with underscore." OPTION_AS_ERROR_MESSAGE = "The value (%s) of the option `as` is not a valid Ruby identifier; " + "make sure it starts with lowercase letter, " + diff --git a/actionview/test/fixtures/test/_FooBar.html.erb b/actionview/test/fixtures/test/_FooBar.html.erb new file mode 100644 index 0000000000..4bbe59410a --- /dev/null +++ b/actionview/test/fixtures/test/_FooBar.html.erb @@ -0,0 +1 @@ +🍣 diff --git a/actionview/test/fixtures/test/_a-in.html.erb b/actionview/test/fixtures/test/_a-in.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index 66667e0474..f77b81f0ee 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -171,18 +171,12 @@ module RenderTestCases assert_equal "only partial", @view.render("test/partial_only", :counter_counter => 5) end - def test_render_partial_with_invalid_name - e = assert_raises(ArgumentError) { @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 + def test_render_partial_with_number + assert_nothing_raised { @view.render(:partial => "test/200") } end def test_render_partial_with_missing_filename - e = assert_raises(ArgumentError) { @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 + assert_raises(ActionView::MissingTemplate) { @view.render(:partial => "test/") } end def test_render_partial_with_incompatible_object @@ -190,11 +184,12 @@ module RenderTestCases assert_equal "'#{nil.inspect}' is not an ActiveModel-compatible object. It must implement :to_partial_path.", e.message end + def test_render_partial_starting_with_a_capital + assert_nothing_raised { @view.render(:partial => 'test/FooBar') } + end + def test_render_partial_with_hyphen - e = assert_raises(ArgumentError) { @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 + assert_nothing_raised { @view.render(:partial => "test/a-in") } end def test_render_partial_with_invalid_option_as -- cgit v1.2.3