Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have had some issues. #2

Merged
merged 3 commits into from
Nov 24, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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 :)

script/plugin install git@github.com:skwp/PartialMap.git
script/rails plugin install git@github.com:skwp/PartialMap.git

Usage
=======
Expand Down
2 changes: 1 addition & 1 deletion lib/formatters/base_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 15 additions & 15 deletions lib/partial_map.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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}"

Expand All @@ -74,17 +74,17 @@ 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

# 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
Expand All @@ -96,7 +96,7 @@ def list_subpartials(file, level=0)
end

return output_heading
end
end

end # class
end # module
4 changes: 2 additions & 2 deletions lib/tasks/partial_map.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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