diff options
author | João Britto <jabcalves@gmail.com> | 2013-12-21 22:14:07 -0200 |
---|---|---|
committer | João Britto <jabcalves@gmail.com> | 2014-01-09 20:37:00 -0200 |
commit | ccbba3ff50a7c2d6523f55f7821aabdb89fc5d45 (patch) | |
tree | ad9eb5a6d62d3b551b0f7fbb804412958cbdabc9 /actionview/lib | |
parent | c2afa055614f15edfbd2f4c97f9254425286fc6e (diff) | |
download | rails-ccbba3ff50a7c2d6523f55f7821aabdb89fc5d45.tar.gz rails-ccbba3ff50a7c2d6523f55f7821aabdb89fc5d45.tar.bz2 rails-ccbba3ff50a7c2d6523f55f7821aabdb89fc5d45.zip |
Avoid scanning multiple render calls as a single match.
Each chunk of text coming after `render` is now handled individually as a possible list of arguments.
Diffstat (limited to 'actionview/lib')
-rw-r--r-- | actionview/lib/action_view/dependency_tracker.rb | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/actionview/lib/action_view/dependency_tracker.rb b/actionview/lib/action_view/dependency_tracker.rb index 748fa81221..0ccf2515c5 100644 --- a/actionview/lib/action_view/dependency_tracker.rb +++ b/actionview/lib/action_view/dependency_tracker.rb @@ -54,21 +54,20 @@ module ActionView /x # Matches: - # render partial: "comments/comment", collection: commentable.comments - # render "comments/comments" - # render 'comments/comments' - # render('comments/comments') + # partial: "comments/comment", collection: @all_comments => "comments/comment" + # (object: @single_comment, partial: "comments/comment") => "comments/comment" # - # render(@topic) => render("topics/topic") - # render(topics) => render("topics/topic") - # render(message.topics) => render("topics/topic") - RENDER_DEPENDENCY = / - \brender\b # render, the whole word - \s*\(?\s* # optional opening paren surrounded by spaces - (?: - (?:.*?#{PARTIAL_HASH_KEY})? # optional hash, up to the partial key declaration - (?:#{STRING}|#{VARIABLE_OR_METHOD_CHAIN}) # finally, the dependency name of interest - ) + # "comments/comments" + # 'comments/comments' + # ('comments/comments') + # + # (@topic) => "topics/topic" + # topics => "topics/topic" + # (message.topics) => "topics/topic" + RENDER_ARGUMENTS = /\A + (?:\s*\(?\s*) # optional opening paren surrounded by spaces + (?:.*?#{PARTIAL_HASH_KEY})? # optional hash, up to the partial key declaration + (?:#{STRING}|#{VARIABLE_OR_METHOD_CHAIN}) # finally, the dependency name of interest /xm def self.call(name, template) @@ -98,10 +97,13 @@ module ActionView def render_dependencies render_dependencies = [] + render_calls = source.split(/\brender\b/).drop(1) - source.scan(RENDER_DEPENDENCY) do - add_dynamic_dependency(render_dependencies, Regexp.last_match[:dynamic]) - add_static_dependency(render_dependencies, Regexp.last_match[:static]) + render_calls.each do |arguments| + arguments.scan(RENDER_ARGUMENTS) do + add_dynamic_dependency(render_dependencies, Regexp.last_match[:dynamic]) + add_static_dependency(render_dependencies, Regexp.last_match[:static]) + end end render_dependencies.uniq |