Changeset 34

Show
Ignore:
Timestamp:
02/15/08 21:56:21 (7 months ago)
Author:
tonttu
Message:

Fixed a bug with Erb layout rendering cached Erb partial after Malline partial. This commit will also fix many weird situations involved with mixing Erb, Malline and Caching or some specific helper methods.
Thanks to Andrew for reporting the bug.

Files:

Legend:

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

    r28 r34  
    7777                def render tpl = nil, local_assigns = {}, n = nil, &block 
    7878                        add_local_assigns local_assigns 
    79                         tmp = @view.malline.run tpl, &block 
    80                         tmp 
     79                        @view.malline_is_active = true 
     80                        @view.malline.run tpl, &block 
    8181                end 
    8282 
     
    8585                end 
    8686 
     87                # TODO: These should also be able to disable 
    8788                def definetags *tags 
    8889                        tags.each do |tag| 
  • trunk/malline/lib/malline/rails.rb

    r33 r34  
    2626                alias_method :orig_delegate_render, :delegate_render 
    2727                def delegate_render(handler, template, local_assigns) 
    28                         if handler == Malline::Bas
    29                                @malline_is_active = tru
     28                        old = @malline_is_activ
     29                        tmp = if handler == Malline::Bas
    3030                                h = handler.new(self) 
    3131                                h.set_path(@current_tpl_path) if @current_tpl_path 
     
    3535                                orig_delegate_render(handler, template, local_assigns) 
    3636                        end 
     37                        @malline_is_active = old 
     38                        tmp 
    3739                end 
    3840        end if const_defined?('Base') 
  • trunk/malline/lib/malline/view_wrapper.rb

    r28 r34  
    1818module Malline 
    1919        module ViewWrapper 
     20                attr_accessor :malline_is_active 
     21 
     22                # List of all methods that may override some custom view methods 
     23                # If is_malline?, then their _malline_ -prefix versions are called 
     24                @@malline_methods = %w{_erbout cache capture _ tag! << txt!} 
     25 
     26                def init_malline_methods 
     27                        @malline_methods_inited = true 
     28                        @@malline_methods.each do |m| 
     29                                mf = m.gsub('<', 'lt') 
     30                                eval %{def #{m}(*x, &b) is_malline? ? _malline_#{mf}(*x, &b) : super; end} 
     31                        end 
     32                end 
     33 
    2034                def malline opts = nil 
    2135                        if @malline 
     
    2438                                @malline = Template.new(self, opts) 
    2539                        end 
     40                        init_malline_methods unless @malline_methods_inited 
    2641                        @malline 
    2742                end 
    2843                 
    29                 def _erbout 
     44                def _malline__erbout 
    3045                        @_erbout ||= ErbOut.new(self) 
    31                         @_erbout 
    3246                end 
    3347 
    34                 def cache name = {}, options = {}, &block 
     48                def _malline_cache name = {}, options = {}, &block 
    3549                        return block.call unless @controller.perform_caching 
    3650                        cache = @controller.read_fragment(name, options) 
    3751 
    3852                        unless cache 
    39                                 cache = capture { block.call } 
     53                                cache = _malline_capture { block.call } 
    4054                                @controller.write_fragment(name, cache, options) 
    4155                        end 
     
    4357                end 
    4458 
    45                 def capture &block 
     59                def _malline_capture &block 
    4660                        @malline.run &block 
    4761                end 
    4862 
    49                 def _ *args 
     63                def _malline__ *args 
    5064                        @malline.add_text(*args) 
    5165                end 
    52                 alias_method :txt!, :
     66                alias_method :_malline_txt!, :_malline_
    5367 
    54                 def << *args 
     68                def _malline_ltlt *args 
    5569                        @malline.add_unescaped_text *args 
    5670                end 
    5771 
    5872                def method_missing s, *args, &block 
     73                        return super unless is_malline? 
    5974                        helper = (s.to_s[0].chr == '_') ? s.to_s[1..255].to_sym : s.to_sym 
    6075                        if respond_to?(helper) 
     
    6277                        else 
    6378                                return super if @malline.options[:strict] 
    64                                 tag! s, *args, &block 
     79                                _malline_tag! s, *args, &block 
    6580                        end 
    6681                end 
    6782 
    68                 def tag! *args, &block 
     83                def _malline_tag! *args, &block 
    6984                        @malline.tag *args, &block 
    7085                end