Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2 from rafaeldx7/PartialMap

* commit '37c60dae6f78840a274c18728a09b5a43d444d5f':
  plugin install command fixed
  partial_filename cannot be nil
  fix: DEPRECATION WARNING: RAILS_ROOT is deprecated. Please use ::Rails.root.to_s.
  • Loading branch information...
commit 3102bcd34cbdf3207f8ea7bf18991ebe35b718d5 2 parents c038960 + 37c60da
$GIT_USER authored
View
8 README.md
@@ -1,9 +1,15 @@
PartialMap
==========
-Too many partials in your project? Can't figure out if the hip bone
+Too many partials in your project? Can't figure out if the hip bone
connects to the thighbone or the cheekbone? Let PartialMap help :)
+rails 3
+
+ script/rails plugin install git@github.com:skwp/PartialMap.git
+
+rails 2
+
script/plugin install git@github.com:skwp/PartialMap.git
Usage
View
2  lib/formatters/base_formatter.rb
@@ -10,7 +10,7 @@ def list(list); raise NotImplementedError; end
def link_to_partial(file); raise NotImplementedError; end
def clean_path(path)
- base_path = File.join(RAILS_ROOT,'app/views/')
+ base_path = File.join(::Rails.root.to_s,'app/views/')
cleaned_path="#{path.gsub(base_path,"")}"
end
View
30 lib/partial_map.rb
@@ -1,4 +1,4 @@
-require 'pathname'
+require 'pathname'
Dir["#{File.dirname(__FILE__)}/formatters/**"].each {|f| require f; puts f}
# Parse a directory looking for top level files, then recurse
@@ -7,19 +7,19 @@
# every level, that are only closed once the recursion ends.
# Oh well.
#
-# TODO:
+# TODO:
# * make it more efficient by logging entries in a table and then revisiting them.
# * handle calls from the view to helpers that render partials (advanced)
#
class String; def titleize; self[0,1].upcase + self[1,self.size].downcase; end; end; #:nodoc:
-
-module PartialMap
+
+module PartialMap
class RailsViewTree
attr_reader :all_partials
def initialize(root_path, callback)
- @all_partials = Dir[File.join(RAILS_ROOT,'app','views','**','**')].select {|file| is_partial?(file)}
+ @all_partials = Dir[File.join(::Rails.root.to_s,'app','views','**','**')].select {|file| is_partial?(file)}
@callback = callback
find_views(root_path)
end
@@ -44,27 +44,27 @@ class Parser
def initialize(formatter)
@formatter = formatter
end
-
+
def draw_partial_map(starting_path)
puts @formatter.head
@tree = RailsViewTree.new(starting_path, self)
puts @formatter.foot
end
- def list_subpartials(file, level=0)
+ def list_subpartials(file, level=0)
# Find the partial matching the name we're looking for
# since it may end in .rhtml, .html.erb, etc
- output_heading = @formatter.partial(file, level)
+ output_heading = @formatter.partial(file, level)
output=""
subpartials_found=0
-
+
tracked_partials={}
File.open(file).each do |line|
if line =~ /render\s+:partial\s+=>\s+['"]([\w\d\/]+)/
# if partial has a slash, we want to underscore the last part of it
- #
+ #
partial_reference = $1
# debug "Parsed partial path #{partial_reference}"
@@ -74,7 +74,7 @@ def list_subpartials(file, level=0)
components = partial_reference.split('/')
partial_name, partial_path = components.pop, components.join('/')
# debug "Path includes a slash so we're going to look at the relative path #{partial_path} name #{partial_name}"
- partial_path = File.join(RAILS_ROOT, "app/views", partial_path, "_#{partial_name}")
+ partial_path = File.join(::Rails.root.to_s, "app/views", partial_path, "_#{partial_name}")
else
partial_path = File.join(File.dirname(file), "_#{partial_reference}")
end
@@ -82,9 +82,9 @@ def list_subpartials(file, level=0)
# debug "Searching #{partial_path}"
partial_filename = Dir[partial_path + "*"].first # find the actual fileame
- unless tracked_partials[partial_filename]
+ unless partial_filename.nil? || tracked_partials[partial_filename]
subpartials_found += 1
- output << list_subpartials(partial_filename,level+1)
+ output << list_subpartials(partial_filename,level+1)
tracked_partials[partial_filename] = true
end
end
@@ -96,7 +96,7 @@ def list_subpartials(file, level=0)
end
return output_heading
- end
-
+ end
+
end # class
end # module
View
4 lib/tasks/partial_map.rake
@@ -3,11 +3,11 @@ namespace(:partialmap) do
desc "Show a tree of all the view partials."
task(:text) do
- PartialMap::Parser.new(PartialMap::PlainFormatter.new).draw_partial_map(File.join(RAILS_ROOT,'app/views'))
+ PartialMap::Parser.new(PartialMap::PlainFormatter.new).draw_partial_map(File.join(::Rails.root.to_s,'app/views'))
end
desc "Show a tree of all the view partials."
task(:html) do
- PartialMap::Parser.new(PartialMap::HtmlFormatter.new).draw_partial_map(File.join(RAILS_ROOT,'app/views'))
+ PartialMap::Parser.new(PartialMap::HtmlFormatter.new).draw_partial_map(File.join(::Rails.root.to_s,'app/views'))
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.