Skip to content
This repository
Browse code

Makes rails-dev-boost work again

  • Loading branch information...
commit 3c1187699a80e0c4a003f5693389595cd644390f 1 parent 109a387
Yehuda Katz authored April 14, 2009
2  actionmailer/lib/action_mailer/base.rb
@@ -497,7 +497,7 @@ def create!(method_name, *parameters) #:nodoc:
497 497
         # normal template exists (or if there were no implicit parts) we render
498 498
         # it.
499 499
         template_exists = @parts.empty?
500  
-        template_exists ||= template_root.find_template("#{mailer_name}/#{@template}")
  500
+        template_exists ||= template_root.find_by_parts("#{mailer_name}/#{@template}")
501 501
         @body = render_message(@template, @body) if template_exists
502 502
 
503 503
         # Finally, if there are other message parts and a textual body exists,
4  actionpack/lib/action_controller/dispatch/rescue.rb
@@ -38,7 +38,7 @@ module Rescue
38 38
       'ActionView::TemplateError'         => 'template_error'
39 39
     }
40 40
 
41  
-    RESCUES_TEMPLATE_PATH = ActionView::Template::EagerPath.new(
  41
+    RESCUES_TEMPLATE_PATH = ActionView::Template::FileSystemPath.new(
42 42
       File.join(File.dirname(__FILE__), "templates"))
43 43
 
44 44
     def self.included(base) #:nodoc:
@@ -165,7 +165,7 @@ def perform_action_with_rescue #:nodoc:
165 165
       end
166 166
 
167 167
       def rescues_path(template_name)
168  
-        RESCUES_TEMPLATE_PATH.find_template("rescues/#{template_name}.erb")
  168
+        RESCUES_TEMPLATE_PATH.find_by_parts("rescues/#{template_name}.erb")
169 169
       end
170 170
 
171 171
       def template_path_for_local_rescue(exception)
4  actionpack/lib/action_controller/dispatch/templates/rescues/diagnostics.erb
@@ -6,5 +6,5 @@
6 6
 </h1>
7 7
 <pre><%=h @exception.clean_message %></pre>
8 8
 
9  
-<%= @template._render_template(@rescues_path.find_template("rescues/_trace.erb")) %>
10  
-<%= @template._render_template(@rescues_path.find_template("rescues/_request_and_response.erb")) %>
  9
+<%= @template._render_template(@rescues_path.find_by_parts("rescues/_trace.erb")) %>
  10
+<%= @template._render_template(@rescues_path.find_by_parts("rescues/_request_and_response.erb")) %>
1  actionpack/lib/action_view.rb
@@ -42,6 +42,7 @@ def self.load_all!
42 42
   autoload :Helpers, 'action_view/helpers'
43 43
   autoload :InlineTemplate, 'action_view/template/inline'
44 44
   autoload :Partials, 'action_view/render/partials'
  45
+  autoload :Path, 'action_view/template/path'
45 46
   autoload :PathSet, 'action_view/paths'
46 47
   autoload :Rendering, 'action_view/render/rendering'
47 48
   autoload :Renderable, 'action_view/template/renderable'
7  actionpack/lib/action_view/paths.rb
@@ -2,11 +2,8 @@ module ActionView #:nodoc:
2 2
   class PathSet < Array #:nodoc:
3 3
     def self.type_cast(obj)
4 4
       if obj.is_a?(String)
5  
-        if !Object.const_defined?(:Rails) || Rails.configuration.cache_classes
6  
-          Template::EagerPath.new(obj)
7  
-        else
8  
-          Template::Path.new(obj)
9  
-        end
  5
+        cache = !Object.const_defined?(:Rails) || Rails.configuration.cache_classes
  6
+        Template::FileSystemPath.new(obj, :cache => cache)
10 7
       else
11 8
         obj
12 9
       end
87  actionpack/lib/action_view/template/path.rb
... ...
@@ -0,0 +1,87 @@
  1
+module ActionView
  2
+  class Template
  3
+    class Path
  4
+      attr_reader :path, :paths
  5
+      delegate :hash, :inspect, :to => :path
  6
+      
  7
+      def initialize(options)
  8
+        @cache = options[:cache]
  9
+      end
  10
+
  11
+      def to_s
  12
+        if defined?(RAILS_ROOT)
  13
+          path.to_s.sub(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '')
  14
+        else
  15
+          path.to_s
  16
+        end
  17
+      end
  18
+
  19
+      def to_str
  20
+        path.to_str
  21
+      end
  22
+
  23
+      def ==(path)
  24
+        to_str == path.to_str
  25
+      end
  26
+
  27
+      def eql?(path)
  28
+        to_str == path.to_str
  29
+      end
  30
+
  31
+      def find_by_parts(name, extensions = nil, prefix = nil, partial = nil)
  32
+        path = prefix ? "#{prefix}/" : ""
  33
+    
  34
+        name = name.to_s.split("/")
  35
+        name[-1] = "_#{name[-1]}" if partial
  36
+    
  37
+        path << name.join("/")
  38
+
  39
+        template = nil
  40
+
  41
+        Array(extensions).each do |extension|
  42
+          extensioned_path = extension ? "#{path}.#{extension}" : path
  43
+          break if (template = find_template(extensioned_path))
  44
+        end
  45
+        template || find_template(path)
  46
+      end
  47
+  
  48
+    private
  49
+      def create_template(file)
  50
+        Template.new(file.split("#{self}/").last, self)
  51
+      end
  52
+    end
  53
+
  54
+    class FileSystemPath < Path
  55
+      def initialize(path, options = {})
  56
+        raise ArgumentError, "path already is a Path class" if path.is_a?(Path)        
  57
+        
  58
+        super(options)
  59
+        @path, @paths = path, {}
  60
+        
  61
+        # **/*/** is a hax for symlinked directories
  62
+        load_templates("#{@path}/{**/*,**}/**") if @cache
  63
+      end
  64
+
  65
+    private
  66
+    
  67
+      def load_template(template)
  68
+        template.load!
  69
+        template.accessible_paths.each do |path|
  70
+          @paths[path] = template
  71
+        end
  72
+      end
  73
+    
  74
+      def find_template(path)
  75
+        load_templates("#{@path}/#{path}{,.*}") unless @cache
  76
+        @paths[path]
  77
+      end    
  78
+    
  79
+      def load_templates(glob)
  80
+        Dir[glob].each do |file|
  81
+          load_template(create_template(file)) unless File.directory?(file)
  82
+        end
  83
+      end
  84
+      
  85
+    end
  86
+  end
  87
+end
10  actionpack/lib/action_view/template/renderable.rb
@@ -11,6 +11,16 @@ def render(view, locals)
11 11
       view.send(method_name(locals), locals) {|*args| yield(*args) }
12 12
     end
13 13
     
  14
+    def load!
  15
+      names = Base::CompiledTemplates.instance_methods.grep(/#{method_name_without_locals}/)
  16
+      names.each do |name|
  17
+        Base::CompiledTemplates.class_eval do
  18
+          remove_method(name)
  19
+        end
  20
+      end
  21
+      super
  22
+    end
  23
+    
14 24
   private
15 25
   
16 26
     def filename
112  actionpack/lib/action_view/template/template.rb
... ...
@@ -1,103 +1,18 @@
  1
+require "action_view/template/path"
  2
+
1 3
 module ActionView #:nodoc:
2 4
   class Template
3  
-    class Path
4  
-      attr_reader :path, :paths
5  
-      delegate :hash, :inspect, :to => :path
6  
-
7  
-      def initialize(path)
8  
-        raise ArgumentError, "path already is a Path class" if path.is_a?(Path)
9  
-        @path = path.freeze
10  
-      end
11  
-
12  
-      def to_s
13  
-        if defined?(RAILS_ROOT)
14  
-          path.to_s.sub(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '')
15  
-        else
16  
-          path.to_s
17  
-        end
18  
-      end
19  
-
20  
-      def to_str
21  
-        path.to_str
22  
-      end
23  
-
24  
-      def ==(path)
25  
-        to_str == path.to_str
26  
-      end
27  
-
28  
-      def eql?(path)
29  
-        to_str == path.to_str
30  
-      end
31  
-
32  
-      # Returns a ActionView::Template object for the given path string. The
33  
-      # input path should be relative to the view path directory,
34  
-      # +hello/index.html.erb+. This method also has a special exception to
35  
-      # match partial file names without a handler extension. So
36  
-      # +hello/index.html+ will match the first template it finds with a
37  
-      # known template extension, +hello/index.html.erb+. Template extensions
38  
-      # should not be confused with format extensions +html+, +js+, +xml+,
39  
-      # etc. A format must be supplied to match a formated file. +hello/index+
40  
-      # will never match +hello/index.html.erb+.
41  
-      def find_template(path)
42  
-        templates_in_path do |template|
43  
-          if template.accessible_paths.include?(path)
44  
-            return template
45  
-          end
46  
-        end
47  
-        nil
48  
-      end
49  
-
50  
-      def find_by_parts(name, extensions = nil, prefix = nil, partial = nil)
51  
-        path = prefix ? "#{prefix}/" : ""
52  
-        
53  
-        name = name.to_s.split("/")
54  
-        name[-1] = "_#{name[-1]}" if partial
55  
-        
56  
-        path << name.join("/")
57  
-
58  
-        template = nil
59  
-
60  
-        Array(extensions).each do |extension|
61  
-          extensioned_path = extension ? "#{path}.#{extension}" : path
62  
-          template = find_template(extensioned_path) || find_template(path)
63  
-          break if template
64  
-        end
65  
-        template || find_template(path)
66  
-      end
67  
-      
68  
-      private
69  
-        def templates_in_path
70  
-          (Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")).each do |file|
71  
-            yield create_template(file) unless File.directory?(file)
72  
-          end
73  
-        end
74  
-
75  
-        def create_template(file)
76  
-          Template.new(file.split("#{self}/").last, self)
77  
-        end
78  
-    end
79  
-
80  
-    class EagerPath < Path
81  
-      def initialize(path)
82  
-        super
83  
-
84  
-        @paths = {}
85  
-        templates_in_path do |template|
86  
-          template.load!
87  
-          template.accessible_paths.each do |path|
88  
-            @paths[path] = template
89  
-          end
90  
-        end
91  
-        @paths.freeze
92  
-      end
93  
-
94  
-      def find_template(path)
95  
-        @paths[path]
96  
-      end
97  
-    end
98  
-
99 5
     extend TemplateHandlers
100 6
     extend ActiveSupport::Memoizable
  7
+    
  8
+    module Loading
  9
+      def load!
  10
+        @cached = true
  11
+        # freeze
  12
+      end    
  13
+    end
  14
+    include Loading    
  15
+    
101 16
     include Renderable
102 17
 
103 18
     # Templates that are exempt from layouts
@@ -125,11 +40,6 @@ def initialize(template_path, load_paths = [])
125 40
       extend RenderablePartial if @name =~ /^_/
126 41
     end
127 42
     
128  
-    def load!
129  
-      @cached = true
130  
-      # freeze
131  
-    end    
132  
-    
133 43
     def accessible_paths
134 44
       paths = []
135 45
 
5  actionpack/test/controller/session/cookie_store_test.rb
@@ -221,8 +221,9 @@ def test_session_store_with_expire_after
6  actionpack/test/template/compiled_templates_test.rb
@@ -61,14 +61,14 @@ def render(*args)
61 61
 
62 62
     def render_with_cache(*args)
63 63
       view_paths = ActionController::Base.view_paths
64  
-      assert_equal ActionView::Template::EagerPath, view_paths.first.class
  64
+      assert_equal ActionView::Template::FileSystemPath, view_paths.first.class
65 65
       ActionView::Base.new(view_paths, {}).render(*args)
66 66
     end
67 67
 
68 68
     def render_without_cache(*args)
69  
-      path = ActionView::Template::Path.new(FIXTURE_LOAD_PATH)
  69
+      path = ActionView::Template::FileSystemPath.new(FIXTURE_LOAD_PATH)
70 70
       view_paths = ActionView::Base.process_view_paths(path)
71  
-      assert_equal ActionView::Template::Path, view_paths.first.class
  71
+      assert_equal ActionView::Template::FileSystemPath, view_paths.first.class
72 72
       ActionView::Base.new(view_paths, {}).render(*args)
73 73
     end
74 74
 
6  actionpack/test/template/render_test.rb
@@ -273,7 +273,7 @@ class CachedViewRenderTest < ActiveSupport::TestCase
273 273
   # Ensure view path cache is primed
274 274
   def setup
275 275
     view_paths = ActionController::Base.view_paths
276  
-    assert_equal ActionView::Template::EagerPath, view_paths.first.class
  276
+    assert_equal ActionView::Template::FileSystemPath, view_paths.first.class
277 277
     setup_view(view_paths)
278 278
   end
279 279
 end
@@ -284,9 +284,9 @@ class LazyViewRenderTest < ActiveSupport::TestCase
284 284
   # Test the same thing as above, but make sure the view path
285 285
   # is not eager loaded
286 286
   def setup
287  
-    path = ActionView::Template::Path.new(FIXTURE_LOAD_PATH)
  287
+    path = ActionView::Template::FileSystemPath.new(FIXTURE_LOAD_PATH)
288 288
     view_paths = ActionView::Base.process_view_paths(path)
289  
-    assert_equal ActionView::Template::Path, view_paths.first.class
  289
+    assert_equal ActionView::Template::FileSystemPath, view_paths.first.class
290 290
     setup_view(view_paths)
291 291
   end
292 292
 end
2  railties/lib/initializer.rb
@@ -379,7 +379,7 @@ def load_observers
379 379
     def load_view_paths
380 380
       if configuration.frameworks.include?(:action_view)
381 381
         if configuration.cache_classes
382  
-          view_path = ActionView::Template::EagerPath.new(configuration.view_path)
  382
+          view_path = ActionView::Template::FileSystemPath.new(configuration.view_path)
383 383
           ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller)
384 384
           ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer)
385 385
         end

1 note on commit 3c11876

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2498

Please sign in to comment.
Something went wrong with that request. Please try again.