Changeset 964

Show
Ignore:
Timestamp:
11/12/07 08:18:38 (1 year ago)
Author:
has.s..@gmail.com
Message:

Included non-controller directories in the views directory in the template cache. Also added methods to add arbitrary templates to the cache, and reset the cache to empty.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/merb/abstract_controller.rb

    r907 r964  
    1010     
    1111    cattr_accessor :_abstract_subclasses 
    12     cattr_accessor :_globs 
     12    cattr_accessor :_template_path_cache 
    1313    self._abstract_subclasses = [] 
     14    self._template_path_cache 
    1415     
    1516    class << self 
     
    5455      call_filters(after_filters)  
    5556      @_benchmarks[:after_filters_time] = Time.now - start if after_filters 
     57    end 
     58     
     59     
     60    # Adds a path to the template path cache.  This is requried for  
     61    # any view templates or layouts to be found during renering. 
     62    # 
     63    # Example 
     64    #  
     65    # Merb::ActiveController.add_path_to_template_cache('/full/path/to/template.html.erb') 
     66    def self.add_path_to_template_cache(template) 
     67      arry = template.split("/").last.split(".") 
     68      return false if template == "" || arry.size != 3 
     69      key = template.split(".")[0..-2].join(".") 
     70      self._template_path_cache[key] = template 
     71    end 
     72     
     73    # Resets the template_path_cache to an empty hash 
     74    def self.reset_template_path_cache! 
     75      self._template_path_cache = {} 
    5676    end 
    5777     
  • trunk/lib/merb/mixins/render.rb

    r958 r964  
    402402      def glob_template(path, opts = {}) 
    403403        the_template = "#{path}.#{@_template_format}" 
    404         Merb::AbstractController._globs[the_template] || (@_merb_unmatched = (the_template + ".*"); nil) 
     404        Merb::AbstractController._template_path_cache[the_template] || (@_merb_unmatched = (the_template + ".*"); nil) 
    405405      end 
    406406       
  • trunk/lib/merb/server.rb

    r918 r964  
    271271      end 
    272272       
    273       def load_controller_globs 
     273      def load_controller_template_path_cache 
     274         
     275        # This gets all templates set in the controllers template roots 
    274276        template_paths = Merb::AbstractController._abstract_subclasses.map do |klass|  
    275277          Object.full_const_get(klass)._template_root 
    276278        end.uniq.map do |path|  
    277279          Dir["#{path}/**/*"]  
    278         end.flatten.compact.uniq 
    279            
    280         out = {} 
     280        end 
     281         
     282        # This gets the templates that might be created outside controllers 
     283        # template roots.  eg app/views/shared/* 
     284        template_paths << Dir["#{MERB_ROOT}/app/views/**/*"] 
     285         
     286        template_paths = template_paths.flatten.compact.uniq 
     287         
     288        Merb::AbstractController.reset_template_path_cache! 
     289 
    281290        template_paths.each do |template| 
    282           arry = template.split("/").last.split(".") 
    283           next if template == "" || arry.size != 3 
    284            
    285           key = template.split(".")[0..-2].join(".") 
    286           out[key] = template 
    287         end 
    288         Merb::AbstractController._globs = out 
     291          Merb::AbstractController.add_path_to_template_cache(template) 
     292        end 
    289293      end 
    290294       
     
    294298        end 
    295299        load_action_arguments 
    296         load_controller_globs 
     300        load_controller_template_path_cache 
    297301        @app_loaded = true 
    298302        (@after_app_blocks || []).each { |b| b.call } 
  • trunk/spec/fixtures/controllers/render_spec_controllers.rb

    r911 r964  
    113113 
    114114Merb::Server.load_action_arguments 
    115 Merb::Server.load_controller_globs 
     115Merb::Server.load_controller_template_path_cache 
  • trunk/spec/merb/mail_controller_spec.rb

    r913 r964  
    66  end 
    77end 
    8 Merb::Server.load_controller_globs 
     8Merb::Server.load_controller_template_path_cache 
    99 
    1010class Merb::Mailer 
  • trunk/spec/merb/responder_spec.rb

    r904 r964  
    244244 
    245245Merb::Server.load_action_arguments 
    246 Merb::Server.load_controller_globs 
     246Merb::Server.load_controller_template_path_cache 
    247247 
    248248describe "A Merb Responder's Content Negotiation" do