Changeset 195

Show
Ignore:
Timestamp:
02/25/07 14:34:10 (2 years ago)
Author:
e.@brainspl.at
Message:

fix up rendering slightly. fixed layout bug, thanks atmos. Haml templates have caching enabled now. REST routes can be nested arbitrary levels of nestedness without complaining. Improved rest compatability. More to come

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Rakefile

    r193 r195  
    1111 
    1212require __DIR__+'/tools/rakehelp' 
     13require __DIR__+'/tools/annotation_extract' 
    1314include FileUtils 
    1415 
  • trunk/lib/merb/mixins/controller_mixin.rb

    r193 r195  
    6767    # http://wiki.codemongers.com/NginxXSendfile 
    6868    def nginx_send_file(file) 
    69       headers['X-Accel-Redirect'] = file 
     69      headers['X-Accel-Redirect'] = File.expand_path(file) 
    7070      return 
    7171    end   
  • trunk/lib/merb/mixins/form_control_mixin.rb

    r142 r195  
    2020    # <%= control_for @post, :published_at, :date %> 
    2121    # 
     22    # TODO : is this useful enough? Needs some love 
    2223    def control_for(obj, meth, type, opts={}) 
    2324      instance = obj 
  • trunk/lib/merb/mixins/render_mixin.rb

    r194 r195  
    5050    def render(opts={}, &blk) 
    5151      action = opts[:action] || params[:action] 
     52      opts[:layout] ||= ancestral_trait[:layout]  
    5253       
    5354      case 
     
    8283      } 
    8384      content = engine.transform(options) 
    84       return engine.exempt_from_layout? ? content : wrap_layout(content, opts) 
     85      if engine.exempt_from_layout? || opts[:layout] == :none 
     86        content  
     87      else 
     88        wrap_layout(content, opts) 
     89      end 
    8590    end 
    8691 
     
    107112      return " " 
    108113    end 
    109      
    110     # renders the action without wrapping it in a layout. 
    111     # call it without arguments if your template matches 
    112     # the name of the running action. Otherwise you can  
    113     # explicitely set the template name excluding the file 
    114     # extension 
     114 
    115115    def render_no_layout(opts={}) 
    116116      render opts.update({:layout => :none}) 
     
    118118     
    119119    # This is merb's partial render method. You name your  
    120     # partials _partialname.herb, and then call it like 
     120    # partials _partialname.* , and then call it like 
    121121    # partial(:partialname). If there is no '/' character 
    122122    # in the argument passed in it will look for the partial  
     
    133133     
    134134      def wrap_layout(content, opts={}) 
    135         return content if ((opts[:layout] == :none) || (ancestral_trait[:layout] == :none)) 
    136                
    137         if ancestral_trait[:layout] != :application 
    138           layout_choice = find_template(:layout => ancestral_trait[:layout]) 
     135        if opts[:layout] != :application 
     136          layout_choice = find_template(:layout => opts[:layout]) 
    139137        else 
    140138          if name = find_template(:layout => self.class.name.snake_case) 
     
    155153      end 
    156154       
    157        
     155      # OPTIMIZE : combine find_template and find_partial ? 
    158156      def find_template(opts={}) 
    159157        if action = opts[:action] 
  • trunk/lib/merb/mixins/responder_mixin.rb

    r193 r195  
    1010  # end   
    1111   
     12  # TODO : revisit this whole patern. Can we improve on this? 
    1213  module ResponderMixin 
    1314    def respond_to 
  • trunk/lib/merb/template.rb

    r194 r195  
    11module Merb 
    22  module Template 
     3    # TODO : pull up common methods from template engines. 
    34  end   
    45end   
  • trunk/lib/merb/template/haml.rb

    r194 r195  
    77end 
    88module ActionView 
    9  
    109  # stub, in case the requires for that active_* stuff of Haml doesn't fail 
    1110  # but we are not running Rails ;) 
    12  
    1311  class Base 
    14  
    1512    # stub 
    16  
    1713    def concat 
    1814    end 
    19  
    2015    # stub 
    21  
    2216    def form_tag 
    2317    end 
     
    3933     
    4034      class << self 
     35        @@hamls ||= {} 
     36        @@mtimes ||= {} 
    4137        def exempt_from_layout? 
    4238          false     
    4339        end 
    44      
     40         
     41        # OPTIMIZE :  add haml template caching 
    4542        def transform(options = {}) 
    4643          opts, file, view_context = options.values_at(:opts, :file, :view_context) 
    47           haml = ::Haml::Engine.new(IO.read(file), ancestral_trait[:haml_options].update(opts)) 
     44          opts = ancestral_trait[:haml_options].merge(opts) 
     45          if precompiled = get_precompiled(file) 
     46            opts[:precompiled] ||= precompiled 
     47            haml = ::Haml::Engine.new("", opts) 
     48          else 
     49            haml = ::Haml::Engine.new(IO.read(file), opts) 
     50            set_precompiled(file, haml.precompiled) 
     51          end 
    4852          haml.to_html(view_context) 
    4953        end 
     54       
     55        private 
     56         
     57        def get_precompiled(path, opts={}) 
     58          if @@hamls[path] && !cache_template?(path) 
     59            return @@hamls[path] 
     60          end    
     61        end 
     62         
     63       def set_precompiled(path, precompiled) 
     64         @@hamls[path], @@mtimes[path] = precompiled, Time.now  
     65       end 
     66         
     67        def cache_template?(path) 
     68          return false unless ::Merb::Server.config[:cache_templates] 
     69          return true unless @@hamls[path] 
     70          @@mtimes[path] < File.mtime(path) || 
     71            (File.symlink?(path) && (@@mtimes[path] < File.lstat(path).mtime)) 
     72        end 
     73         
    5074      end 
    5175       
  • trunk/lib/merb/template/markaby.rb

    r193 r195  
    3030        end 
    3131         
     32        # OPTIMIZE :  add mab template caching. what does this mean for mab?  
     33        # mab is just ruby, there's no two phase compile and run 
    3234        def transform(options = {}) 
    3335          opts, file, view_context = options.values_at(:opts, :file, :view_context)