Skip to content

Commit

Permalink
Simplify path traversal logic
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Dec 9, 2011
1 parent 1d9de9d commit 2995134
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions actionpack/lib/action_view/renderer/partial_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,23 +375,23 @@ def partial_path(object = @object)
end
end

@partial_names[path] ||= path.dup.tap do |object_path|
merge_prefix_into_object_path(@context_prefix, object_path)
end
@partial_names[path] ||= merge_prefix_into_object_path(@context_prefix, path.dup)
end

def merge_prefix_into_object_path(prefix, object_path)
if prefix.include?(?/) && object_path.include?(?/)
overlap = []
prefixes = []
prefix_array = File.dirname(prefix).split('/')
object_path_array = object_path.split('/')[0..-3] # skip model dir & partial

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

object_path.gsub!(/^#{overlap.join('/')}\//,'')
object_path.insert(0, "#{File.dirname(prefix)}/")
(prefixes << object_path).join("/")
else
object_path
end
end

Expand Down

0 comments on commit 2995134

Please sign in to comment.