mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Simplify path traversal logic
This commit is contained in:
parent
1d9de9d758
commit
2995134cba
1 changed files with 7 additions and 7 deletions
|
@ -375,23 +375,23 @@ module ActionView
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@partial_names[path] ||= path.dup.tap do |object_path|
|
@partial_names[path] ||= merge_prefix_into_object_path(@context_prefix, path.dup)
|
||||||
merge_prefix_into_object_path(@context_prefix, object_path)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge_prefix_into_object_path(prefix, object_path)
|
def merge_prefix_into_object_path(prefix, object_path)
|
||||||
if prefix.include?(?/) && object_path.include?(?/)
|
if prefix.include?(?/) && object_path.include?(?/)
|
||||||
overlap = []
|
prefixes = []
|
||||||
prefix_array = File.dirname(prefix).split('/')
|
prefix_array = File.dirname(prefix).split('/')
|
||||||
object_path_array = object_path.split('/')[0..-3] # skip model dir & partial
|
object_path_array = object_path.split('/')[0..-3] # skip model dir & partial
|
||||||
|
|
||||||
prefix_array.each_with_index do |dir, index|
|
prefix_array.each_with_index do |dir, index|
|
||||||
overlap << dir if dir == object_path_array[index]
|
break if dir == object_path_array[index]
|
||||||
|
prefixes << dir
|
||||||
end
|
end
|
||||||
|
|
||||||
object_path.gsub!(/^#{overlap.join('/')}\//,'')
|
(prefixes << object_path).join("/")
|
||||||
object_path.insert(0, "#{File.dirname(prefix)}/")
|
else
|
||||||
|
object_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue