Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4189

Show
Ignore:
Timestamp:
04/06/06 18:08:31 (2 years ago)
Author:
david
Message:

Fixed that template extensions would be cached development mode #4624 [Stefan Kaes]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r4183 r4189  
    11*1.12.1* (April 6th, 2005) 
     2 
     3* Fixed that template extensions would be cached development mode #4624 [Stefan Kaes] 
    24 
    35* Update to Prototype 1.5.0_rc0 [Sam Stephenson] 
  • trunk/actionpack/lib/action_view/base.rb

    r4079 r4189  
    158158    cattr_accessor :cache_template_loading 
    159159 
     160    # Specify whether file extension lookup should be cached. 
     161    # Should be +false+ for development environments. Defaults to +true+. 
     162    @@cache_template_extensions = true 
     163    cattr_accessor :cache_template_extensions 
     164 
    160165    # Specify whether local_assigns should be able to use string keys. 
    161166    # Defaults to +true+. String keys are deprecated and will be removed 
     
    313318 
    314319    def pick_template_extension(template_path)#:nodoc: 
    315       @@cached_template_extension[template_path] ||= 
     320      if @@cache_template_extensions 
     321        @@cached_template_extension[template_path] ||= find_template_extension_for(template_path) 
     322      else 
     323        find_template_extension_for(template_path) 
     324      end 
     325    end 
     326 
     327    def delegate_template_exists?(template_path)#:nodoc: 
     328      @@template_handlers.find { |k,| template_exists?(template_path, k) } 
     329    end 
     330 
     331    def erb_template_exists?(template_path)#:nodoc: 
     332      template_exists?(template_path, :rhtml) 
     333    end 
     334 
     335    def builder_template_exists?(template_path)#:nodoc: 
     336      template_exists?(template_path, :rxml) 
     337    end 
     338     
     339    def javascript_template_exists?(template_path)#:nodoc: 
     340      template_exists?(template_path, :rjs) 
     341    end 
     342 
     343    def file_exists?(template_path)#:nodoc: 
     344      template_file_name, template_file_extension = path_and_extension(template_path) 
     345       
     346      if template_file_extension 
     347        template_exists?(template_file_name, template_file_extension) 
     348      else 
     349        cached_template_extension(template_path) || 
     350           %w(erb builder javascript delegate).any? do |template_type|  
     351             send("#{template_type}_template_exists?", template_path) 
     352           end 
     353      end 
     354    end 
     355 
     356    # Returns true is the file may be rendered implicitly. 
     357    def file_public?(template_path)#:nodoc: 
     358      template_path.split('/').last[0,1] != '_' 
     359    end 
     360 
     361    private 
     362      def full_template_path(template_path, extension) 
     363        "#{@base_path}/#{template_path}.#{extension}" 
     364      end 
     365 
     366      def template_exists?(template_path, extension) 
     367        file_path = full_template_path(template_path, extension) 
     368        @@method_names.has_key?(file_path) || FileTest.exists?(file_path) 
     369      end 
     370 
     371      def path_and_extension(template_path) 
     372        template_path_without_extension = template_path.sub(/\.(\w+)$/, '') 
     373        [ template_path_without_extension, $1 ] 
     374      end 
     375       
     376      def cached_template_extension(template_path) 
     377        @@cache_template_extensions && @@cached_template_extension[template_path] 
     378      end       
     379           
     380      def find_template_extension_for(template_path) 
    316381        if match = delegate_template_exists?(template_path) 
    317382          match.first.to_sym 
     
    322387          raise ActionViewError, "No rhtml, rxml, rjs or delegate template found for #{template_path}" 
    323388        end 
    324     end 
    325  
    326     def delegate_template_exists?(template_path)#:nodoc: 
    327       @@template_handlers.find { |k,| template_exists?(template_path, k) } 
    328     end 
    329  
    330     def erb_template_exists?(template_path)#:nodoc: 
    331       template_exists?(template_path, :rhtml) 
    332     end 
    333  
    334     def builder_template_exists?(template_path)#:nodoc: 
    335       template_exists?(template_path, :rxml) 
    336     end 
    337      
    338     def javascript_template_exists?(template_path)#:nodoc: 
    339       template_exists?(template_path, :rjs) 
    340     end 
    341  
    342     def file_exists?(template_path)#:nodoc: 
    343       template_file_name, template_file_extension = path_and_extension(template_path) 
    344        
    345       if template_file_extension 
    346         template_exists?(template_file_name, template_file_extension) 
    347       else 
    348         @@cached_template_extension[template_path] || 
    349            %w(erb builder javascript delegate).any? do |template_type|  
    350              send("#{template_type}_template_exists?", template_path) 
    351            end 
    352       end 
    353     end 
    354  
    355     # Returns true is the file may be rendered implicitly. 
    356     def file_public?(template_path)#:nodoc: 
    357       template_path.split('/').last[0,1] != '_' 
    358     end 
    359  
    360     private 
    361       def full_template_path(template_path, extension) 
    362         "#{@base_path}/#{template_path}.#{extension}" 
    363       end 
    364  
    365       def template_exists?(template_path, extension) 
    366         file_path = full_template_path(template_path, extension) 
    367         @@method_names.has_key?(file_path) || FileTest.exists?(file_path) 
    368       end 
    369  
    370       def path_and_extension(template_path) 
    371         template_path_without_extension = template_path.sub(/\.(\w+)$/, '') 
    372         [ template_path_without_extension, $1 ] 
    373389      end 
    374390 
  • trunk/railties/environments/development.rb

    r4003 r4189  
    1515config.action_controller.consider_all_requests_local = true 
    1616config.action_controller.perform_caching             = false 
     17config.action_view.cache_template_extensions         = false 
    1718config.action_view.debug_rjs                         = true 
    1819