Changeset 986

Show
Ignore:
Timestamp:
11/12/07 22:58:17 (1 year ago)
Author:
wyca..@gmail.com
Message:

Checking in new code to speed up partials

Files:

Legend:

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

    r981 r986  
    297297      end 
    298298       
     299      def load_erubis_inline_helpers 
     300        partials = Merb::AbstractController._abstract_subclasses.map {|x|  
     301          Dir.glob("#{Object.full_const_get(x)._template_root}/**/_*") }.flatten 
     302 
     303        partials.each do |partial| 
     304          eruby = Erubis::Eruby.new(File.read(partial)) 
     305          eruby.def_method(Merb::GlobalHelper, partial.gsub("/", "__").gsub(".", "_"), partial) 
     306        end         
     307      end 
     308       
    299309      def load_application 
    300310        MERB_PATHS.each do |glob| 
     
    303313        load_action_arguments 
    304314        load_controller_template_path_cache 
     315        load_erubis_inline_helpers 
    305316        @app_loaded = true 
    306317        (@after_app_blocks || []).each { |b| b.call } 
     
    348359              load_action_arguments(loaded_classes) 
    349360              load_controller_template_path_cache 
     361              load_erubis_inline_helpers               
    350362            rescue Exception => e 
    351363              puts "Error reloading file #{file}: #{e}" 
  • trunk/lib/merb/template/erubis.rb

    r905 r986  
    44    class ErubisViewContext < ViewContext 
    55      include ::Merb::ErubisCaptureMixin 
     6       
     7      def partial(template, opts={}) 
     8 
     9        unless @_template_format 
     10          @web_controller.choose_template_format(Merb.available_mime_types, {}) 
     11        end 
     12 
     13        template = @web_controller._cached_partials["#{template}.#{@_template_format}"] ||= 
     14          @web_controller.send(:find_partial, template) 
     15 
     16        template_method = template.gsub(/\//, "__").gsub(/\./, "_") 
     17 
     18        if with = opts.delete(:with) 
     19          as = opts.delete(:as) || template.match(/(.*\/_)([^\.]*)/)[2] 
     20          @_merb_partial_locals = opts         
     21          sent_template = [with].flatten.map do |temp| 
     22            @_merb_partial_locals[as.to_sym] = temp 
     23            send(template_method) rescue raise Merb::ControllerExceptions::TemplateNotFound,  
     24              "No template matched at #{template}" 
     25          end.join 
     26        else 
     27          @_merb_partial_locals = opts         
     28          sent_template = send(template_method) rescue nil 
     29        end 
     30 
     31        return sent_template if sent_template 
     32 
     33        raise Merb::ControllerExceptions::TemplateNotFound, "No template matched at #{template}" 
     34      end 
     35 
     36      def method_missing(sym, *args, &blk) 
     37        @_merb_partial_locals[sym] || @web_controller.send(sym, *args, &blk) rescue super 
     38      end 
     39       
    640    end 
    741     
  • trunk/lib/merb/view_context.rb

    r807 r986  
    2323                       @_content_type 
    2424                       @_merb_unmatched 
    25                        @_template_format 
    2625                       @_provided_formats 
    2726                       @template] 
     
    7069    # and delegate them back to the controller. 
    7170    def method_missing(sym, *args, &blk) 
    72       if @web_controller.respond_to? sym 
    73         @web_controller.send(sym, *args, &blk) 
    74       elsif @_merb_partial_locals.key? sym 
    75         @_merb_partial_locals[sym] 
    76       else 
    77         super 
    78       end     
     71      @_merb_partial_locals[sym] || @web_controller.send(sym, *args, &blk) rescue super 
    7972    end 
    8073     
  • trunk/spec/fixtures/controllers/render_spec_controllers.rb

    r964 r986  
    114114Merb::Server.load_action_arguments 
    115115Merb::Server.load_controller_template_path_cache 
     116Merb::Server.load_erubis_inline_helpers 
  • trunk/spec/merb/abstract_controller_spec.rb

    r964 r986  
    1515  after(:all) do 
    1616    Merb::Server.load_controller_template_path_cache 
     17    Merb::Server.load_erubis_inline_helpers     
    1718  end 
    1819   
  • trunk/spec/merb/mail_controller_spec.rb

    r964 r986  
    77end 
    88Merb::Server.load_controller_template_path_cache 
     9Merb::Server.load_erubis_inline_helpers 
    910 
    1011class Merb::Mailer 
  • trunk/spec/merb/responder_spec.rb

    r964 r986  
    245245Merb::Server.load_action_arguments 
    246246Merb::Server.load_controller_template_path_cache 
     247Merb::Server.load_erubis_inline_helpers 
    247248 
    248249describe "A Merb Responder's Content Negotiation" do