Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

I have had some issues. #2

Merged
merged 3 commits into from over 2 years ago

2 participants

rafaeldx7 Yan Pritzker
rafaeldx7

So I fixed them.

Yan Pritzker

this was designed for rails 2, I'll probably just leave both in there

nice!

Yan Pritzker skwp merged commit 37c60da into from
Yan Pritzker skwp closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4  README.md
Source Rendered
... ...
@@ -1,10 +1,10 @@
1 1
 PartialMap
2 2
 ==========
3 3
 
4  
-Too many partials in your project? Can't figure out if the hip bone 
  4
+Too many partials in your project? Can't figure out if the hip bone
5 5
 connects to the thighbone or the cheekbone? Let PartialMap help :)
6 6
 
7  
-    script/plugin install git@github.com:skwp/PartialMap.git
  7
+    script/rails plugin install git@github.com:skwp/PartialMap.git
8 8
 
9 9
 Usage
10 10
 =======
2  lib/formatters/base_formatter.rb
@@ -10,7 +10,7 @@ def list(list); raise NotImplementedError; end
10 10
     def link_to_partial(file); raise NotImplementedError; end
11 11
 
12 12
     def clean_path(path)
13  
-      base_path = File.join(RAILS_ROOT,'app/views/')
  13
+      base_path = File.join(::Rails.root.to_s,'app/views/')
14 14
       cleaned_path="#{path.gsub(base_path,"")}"
15 15
     end
16 16
 
30  lib/partial_map.rb
... ...
@@ -1,4 +1,4 @@
1  
-require 'pathname' 
  1
+require 'pathname'
2 2
 Dir["#{File.dirname(__FILE__)}/formatters/**"].each {|f| require f; puts f}
3 3
 
4 4
 # Parse a directory looking for top level files, then recurse
@@ -7,19 +7,19 @@
7 7
 # every level, that are only closed once the recursion ends.
8 8
 # Oh well.
9 9
 #
10  
-# TODO: 
  10
+# TODO:
11 11
 #  * make it more efficient by logging entries in a table and then revisiting them.
12 12
 #  * handle calls from the view to helpers that render partials (advanced)
13 13
 #
14 14
 class String; def titleize; self[0,1].upcase + self[1,self.size].downcase; end; end; #:nodoc:
15  
-  
16  
-module PartialMap 
  15
+
  16
+module PartialMap
17 17
 
18 18
   class RailsViewTree
19 19
     attr_reader :all_partials
20 20
 
21 21
     def initialize(root_path, callback)
22  
-      @all_partials = Dir[File.join(RAILS_ROOT,'app','views','**','**')].select {|file| is_partial?(file)}
  22
+      @all_partials = Dir[File.join(::Rails.root.to_s,'app','views','**','**')].select {|file| is_partial?(file)}
23 23
       @callback = callback
24 24
       find_views(root_path)
25 25
     end
@@ -44,27 +44,27 @@ class Parser
44 44
     def initialize(formatter)
45 45
       @formatter = formatter
46 46
     end
47  
-    
  47
+
48 48
     def draw_partial_map(starting_path)
49 49
       puts @formatter.head
50 50
       @tree = RailsViewTree.new(starting_path, self)
51 51
       puts @formatter.foot
52 52
     end
53 53
 
54  
-    def list_subpartials(file, level=0) 
  54
+    def list_subpartials(file, level=0)
55 55
       # Find the partial matching the name we're looking for
56 56
       # since it may end in .rhtml, .html.erb, etc
57  
-      output_heading = @formatter.partial(file, level)      
  57
+      output_heading = @formatter.partial(file, level)
58 58
       output=""
59 59
 
60 60
       subpartials_found=0
61  
-      
  61
+
62 62
       tracked_partials={}
63 63
 
64 64
       File.open(file).each do |line|
65 65
         if line =~ /render\s+:partial\s+=>\s+['"]([\w\d\/]+)/
66 66
           # if partial has a slash, we want to underscore the last part of it
67  
-          # 
  67
+          #
68 68
           partial_reference = $1
69 69
           # debug "Parsed partial path #{partial_reference}"
70 70
 
@@ -74,7 +74,7 @@ def list_subpartials(file, level=0)
74 74
             components = partial_reference.split('/')
75 75
             partial_name, partial_path = components.pop, components.join('/')
76 76
             # debug "Path includes a slash so we're going to look at the relative path #{partial_path} name #{partial_name}"
77  
-            partial_path = File.join(RAILS_ROOT, "app/views", partial_path, "_#{partial_name}")
  77
+            partial_path = File.join(::Rails.root.to_s, "app/views", partial_path, "_#{partial_name}")
78 78
           else
79 79
             partial_path = File.join(File.dirname(file), "_#{partial_reference}")
80 80
           end
@@ -82,9 +82,9 @@ def list_subpartials(file, level=0)
82 82
           # debug "Searching #{partial_path}"
83 83
           partial_filename = Dir[partial_path + "*"].first # find the actual fileame
84 84
 
85  
-          unless tracked_partials[partial_filename]
  85
+          unless partial_filename.nil? || tracked_partials[partial_filename]
86 86
             subpartials_found += 1
87  
-            output << list_subpartials(partial_filename,level+1)  
  87
+            output << list_subpartials(partial_filename,level+1)
88 88
             tracked_partials[partial_filename] = true
89 89
           end
90 90
         end
@@ -96,7 +96,7 @@ def list_subpartials(file, level=0)
96 96
       end
97 97
 
98 98
       return output_heading
99  
-    end  
100  
-  
  99
+    end
  100
+
101 101
   end # class
102 102
 end # module
4  lib/tasks/partial_map.rake
@@ -3,11 +3,11 @@ namespace(:partialmap) do
3 3
 
4 4
   desc "Show a tree of all the view partials."
5 5
   task(:text) do
6  
-    PartialMap::Parser.new(PartialMap::PlainFormatter.new).draw_partial_map(File.join(RAILS_ROOT,'app/views'))
  6
+    PartialMap::Parser.new(PartialMap::PlainFormatter.new).draw_partial_map(File.join(::Rails.root.to_s,'app/views'))
7 7
   end
8 8
 
9 9
   desc "Show a tree of all the view partials."
10 10
   task(:html) do
11  
-    PartialMap::Parser.new(PartialMap::HtmlFormatter.new).draw_partial_map(File.join(RAILS_ROOT,'app/views'))
  11
+    PartialMap::Parser.new(PartialMap::HtmlFormatter.new).draw_partial_map(File.join(::Rails.root.to_s,'app/views'))
12 12
   end
13 13
 end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.