From 21bad7445b26f62992b494804b29b74c9769e87d Mon Sep 17 00:00:00 2001 From: Christos Zisopoulos Date: Thu, 30 Aug 2012 13:01:25 +0200 Subject: `Digestor` ignores most whitespace when parsing `render` invocations --- actionpack/lib/action_view/digestor.rb | 4 ++-- .../test/fixtures/digestor/messages/_form.html.erb | 0 .../test/fixtures/digestor/messages/edit.html.erb | 4 ++++ actionpack/test/template/digestor_test.rb | 23 ++++++++++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 actionpack/test/fixtures/digestor/messages/_form.html.erb create mode 100644 actionpack/test/fixtures/digestor/messages/edit.html.erb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/digestor.rb b/actionpack/lib/action_view/digestor.rb index cfa864cdd4..58920e1e59 100644 --- a/actionpack/lib/action_view/digestor.rb +++ b/actionpack/lib/action_view/digestor.rb @@ -15,9 +15,9 @@ module ActionView # render(topics) => render("topics/topic") # render(message.topics) => render("topics/topic") RENDER_DEPENDENCY = / - render\s? # render, followed by an optional space + render\s* # render, followed by an optional space \(? # start a optional parenthesis for the render call - (partial:)?\s? # naming the partial, used with collection -- 1st capture + (partial:)?\s* # naming the partial, used with collection -- 1st capture ([@a-z"'][@a-z_\/\."']+) # the template name itself -- 2nd capture /x diff --git a/actionpack/test/fixtures/digestor/messages/_form.html.erb b/actionpack/test/fixtures/digestor/messages/_form.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/actionpack/test/fixtures/digestor/messages/edit.html.erb b/actionpack/test/fixtures/digestor/messages/edit.html.erb new file mode 100644 index 0000000000..791654ffc9 --- /dev/null +++ b/actionpack/test/fixtures/digestor/messages/edit.html.erb @@ -0,0 +1,4 @@ +<%= render "header" %> +<%= render partial: "form" %> +<%= render @message %> +<%= render ( @message.events ) %> diff --git a/actionpack/test/template/digestor_test.rb b/actionpack/test/template/digestor_test.rb index 067ab500f5..dd9bfbca05 100644 --- a/actionpack/test/template/digestor_test.rb +++ b/actionpack/test/template/digestor_test.rb @@ -92,6 +92,29 @@ class TemplateDigestorTest < ActionView::TestCase end end + def test_extra_whitespace_in_render_partial + assert_digest_difference("messages/edit") do + change_template("messages/_form") + end + end + + def test_extra_whitespace_in_render_named_partial + assert_digest_difference("messages/edit") do + change_template("messages/_header") + end + end + + def test_extra_whitespace_in_render_record + assert_digest_difference("messages/edit") do + change_template("messages/_message") + end + end + + def test_extra_whitespace_in_render_with_parenthesis + assert_digest_difference("messages/edit") do + change_template("events/_event") + end + end private def assert_logged(message) -- cgit v1.2.3 From 17f2499f04ff154ddd673f5522158fd01e9e054e Mon Sep 17 00:00:00 2001 From: Christos Zisopoulos Date: Thu, 30 Aug 2012 13:13:47 +0200 Subject: `Digestor` can now parse old style hash syntax for `render` --- actionpack/lib/action_view/digestor.rb | 8 ++++---- actionpack/test/fixtures/digestor/messages/edit.html.erb | 1 + actionpack/test/template/digestor_test.rb | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/digestor.rb b/actionpack/lib/action_view/digestor.rb index 58920e1e59..01074c0687 100644 --- a/actionpack/lib/action_view/digestor.rb +++ b/actionpack/lib/action_view/digestor.rb @@ -15,10 +15,10 @@ module ActionView # render(topics) => render("topics/topic") # render(message.topics) => render("topics/topic") RENDER_DEPENDENCY = / - render\s* # render, followed by an optional space - \(? # start a optional parenthesis for the render call - (partial:)?\s* # naming the partial, used with collection -- 1st capture - ([@a-z"'][@a-z_\/\."']+) # the template name itself -- 2nd capture + render\s* # render, followed by an optional space + \(? # start a optional parenthesis for the render call + (partial:|:partial\s+=>)?\s* # naming the partial, used with collection -- 1st capture + ([@a-z"'][@a-z_\/\."']+) # the template name itself -- 2nd capture /x cattr_accessor(:cache) { Hash.new } diff --git a/actionpack/test/fixtures/digestor/messages/edit.html.erb b/actionpack/test/fixtures/digestor/messages/edit.html.erb index 791654ffc9..a9e0a88e32 100644 --- a/actionpack/test/fixtures/digestor/messages/edit.html.erb +++ b/actionpack/test/fixtures/digestor/messages/edit.html.erb @@ -2,3 +2,4 @@ <%= render partial: "form" %> <%= render @message %> <%= render ( @message.events ) %> +<%= render :partial => "comments/comment", :collection => @message.comments %> diff --git a/actionpack/test/template/digestor_test.rb b/actionpack/test/template/digestor_test.rb index dd9bfbca05..a53e335bb3 100644 --- a/actionpack/test/template/digestor_test.rb +++ b/actionpack/test/template/digestor_test.rb @@ -116,6 +116,12 @@ class TemplateDigestorTest < ActionView::TestCase end end + def test_old_style_hash_in_render_invocation + assert_digest_difference("messages/edit") do + change_template("comments/_comment") + end + end + private def assert_logged(message) log = StringIO.new -- cgit v1.2.3 From 979d327e1e0da9f0e990d5b5edcef752ffce5d54 Mon Sep 17 00:00:00 2001 From: Christos Zisopoulos Date: Thu, 30 Aug 2012 14:17:03 +0200 Subject: Improve RENDER_DEPENDENCY regexp comment to keep the doc editor happy. --- actionpack/lib/action_view/digestor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/digestor.rb b/actionpack/lib/action_view/digestor.rb index 01074c0687..f2c37f5613 100644 --- a/actionpack/lib/action_view/digestor.rb +++ b/actionpack/lib/action_view/digestor.rb @@ -15,7 +15,7 @@ module ActionView # render(topics) => render("topics/topic") # render(message.topics) => render("topics/topic") RENDER_DEPENDENCY = / - render\s* # render, followed by an optional space + render\s* # render, followed by optional whitespace \(? # start a optional parenthesis for the render call (partial:|:partial\s+=>)?\s* # naming the partial, used with collection -- 1st capture ([@a-z"'][@a-z_\/\."']+) # the template name itself -- 2nd capture -- cgit v1.2.3 From e7c23a4a7a0a576231b9d77f4ec47f7f10eb7d42 Mon Sep 17 00:00:00 2001 From: Christos Zisopoulos Date: Thu, 30 Aug 2012 14:27:07 +0200 Subject: Further improve RENDER_DEPENDENCY regexp comments --- actionpack/lib/action_view/digestor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/digestor.rb b/actionpack/lib/action_view/digestor.rb index f2c37f5613..899100d06c 100644 --- a/actionpack/lib/action_view/digestor.rb +++ b/actionpack/lib/action_view/digestor.rb @@ -16,7 +16,7 @@ module ActionView # render(message.topics) => render("topics/topic") RENDER_DEPENDENCY = / render\s* # render, followed by optional whitespace - \(? # start a optional parenthesis for the render call + \(? # start an optional parenthesis for the render call (partial:|:partial\s+=>)?\s* # naming the partial, used with collection -- 1st capture ([@a-z"'][@a-z_\/\."']+) # the template name itself -- 2nd capture /x -- cgit v1.2.3