mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix dependency tracker bug
This commit is contained in:
parent
5a6868b617
commit
4640c346ea
3 changed files with 20 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
|||
* Fixed a dependency tracker bug that caused template dependencies not
|
||||
count layouts as dependencies for partials.
|
||||
|
||||
*Juho Leinonen*
|
||||
|
||||
* Extracted `ActionView::Helpers::RecordTagHelper` to external gem
|
||||
(`record_tag_helper`) and added removal notices.
|
||||
|
||||
|
|
|
@ -76,6 +76,12 @@ module ActionView
|
|||
(?:#{STRING}|#{VARIABLE_OR_METHOD_CHAIN}) # finally, the dependency name of interest
|
||||
/xm
|
||||
|
||||
LAYOUT_DEPENDENCY = /\A
|
||||
(?:\s*\(?\s*) # optional opening paren surrounded by spaces
|
||||
(?:.*?#{LAYOUT_HASH_KEY}) # check if the line has layout key declaration
|
||||
(?:#{STRING}|#{VARIABLE_OR_METHOD_CHAIN}) # finally, the dependency name of interest
|
||||
/xm
|
||||
|
||||
def self.call(name, template)
|
||||
new(name, template).dependencies
|
||||
end
|
||||
|
@ -106,15 +112,20 @@ module ActionView
|
|||
render_calls = source.split(/\brender\b/).drop(1)
|
||||
|
||||
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
|
||||
add_dependencies(render_dependencies, arguments, LAYOUT_DEPENDENCY)
|
||||
add_dependencies(render_dependencies, arguments, RENDER_ARGUMENTS)
|
||||
end
|
||||
|
||||
render_dependencies.uniq
|
||||
end
|
||||
|
||||
def add_dependencies(render_dependencies, arguments, pattern)
|
||||
arguments.scan(pattern) do
|
||||
add_dynamic_dependency(render_dependencies, Regexp.last_match[:dynamic])
|
||||
add_static_dependency(render_dependencies, Regexp.last_match[:static])
|
||||
end
|
||||
end
|
||||
|
||||
def add_dynamic_dependency(dependencies, dependency)
|
||||
if dependency
|
||||
dependencies << "#{dependency.pluralize}/#{dependency.singularize}"
|
||||
|
|
|
@ -60,7 +60,6 @@ class ERBTrackerTest < Minitest::Test
|
|||
end
|
||||
|
||||
def test_dependency_of_template_partial_with_layout
|
||||
skip # FIXME: Needs to be fixed properly, right now we can only match one dependency per line. Need multiple!
|
||||
template = FakeTemplate.new("<%# render partial: 'messages/show', layout: 'messages/layout' %>", :erb)
|
||||
tracker = make_tracker("multiple/_dependencies", template)
|
||||
|
||||
|
|
Loading…
Reference in a new issue