Changeset 412

Show
Ignore:
Timestamp:
08/13/07 16:25:53 (11 months ago)
Author:
e.@brainspl.at
Message:

apply patch from has.sox for throw_content in a partial. closes #127

Files:

Legend:

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

    r410 r412  
    1414require 'json' 
    1515require 'set' 
     16 
    1617autoload :MerbUploadHandler, 'merb/upload_handler' 
    1718autoload :MerbHandler, 'merb/mongrel_handler' 
  • trunk/lib/merb/abstract_controller.rb

    r401 r412  
    99    # Holds internal execution times. Prefaced with an underscore to not  
    1010    # conflict with user-defined controller instance variables. 
    11     attr_accessor :_benchmarks 
     11    attr_accessor :_benchmarks, :thrown_content 
    1212     
    1313    def initialize(*args) 
    1414      @_benchmarks = {} 
     15      @thrown_content = AbstractController.default_thrown_content 
    1516    end 
    1617     
     
    187188      return opts 
    188189    end 
     190     
     191    def self.default_thrown_content 
     192      Hash.new{ |hash, key| hash[key] = "" } 
     193    end 
     194     
     195     
    189196  end   
    190197   
  • trunk/lib/merb/dispatcher.rb

    r399 r412  
    7878        if !File.exist?(path) 
    7979          raise ControllerExceptions::NotFound, "Bad controller! #{cnt}" 
    80         end # unless $TESTING 
     80        end unless $TESTING 
    8181         
    8282        begin 
    83           if MERB_ENV == 'development' 
    84             Object.send(:remove_const, cnt) 
    85             load(path) 
    86           end 
    8783          return Object.full_const_get(cnt) 
    88         rescue RuntimeError 
    89           warn "Error getting instance of '#{controller_name.camel_case}': #{$!}" 
    90           raise $! 
     84        rescue NameError 
     85          raise ControllerExceptions::NotFound 
    9186        end 
    9287      end 
  • trunk/lib/merb/exceptions.rb

    r399 r412  
    5151      include Merb::ControllerMixin 
    5252      include Merb::ResponderMixin 
     53      attr_accessor :thrown_content 
     54       
    5355       
    5456      def set_env(request, response, controller = nil) 
     
    5658        @response = response 
    5759        @controller = controller 
     60        @thrown_content = ::Merb::AbstractController.default_thrown_content 
    5861      end 
    5962       
  • trunk/lib/merb/mail_controller.rb

    r411 r412  
    1818      @base_controller = controller 
    1919      @session = (controller && controller.session) || {} 
     20      super 
    2021    end 
    2122     
  • trunk/lib/merb/mixins/erubis_capture.rb

    r401 r412  
    11module Merb 
     2   
     3   
    24 
    35  module ErubisCaptureMixin 
     
    4042    #   <%= catch_content :header %> 
    4143    def throw_content(name, content = nil, &block) 
    42       eval "@_#{name}_content = (@_#{name}_content || '') + capture(&block)" 
     44      controller.thrown_content[name] << ( content || "" ) << capture( &block ) 
    4345    end 
    4446         
     
    6769     
    6870      def erb_content_for(name, &block) 
    69         eval "@_#{name}_content = (@_#{name}_content|| '') + capture_erb(&block)" 
     71        controller.thrown_content[name] << capture_erb( &block ) 
    7072      end 
    7173     
    7274      def block_content_for(name, &block) 
    73         eval "@_#{name}_content = (@_#{name}_content|| '') + capture_block(&block)" 
     75        controller.thrown_content[name] << capture_block( &block ) 
    7476      end 
    7577  end 
  • trunk/lib/merb/mixins/render.rb

    r401 r412  
    9292    # 
    9393    def render(opts={}, &blk) 
    94        
     94 
    9595      action = if kind_of?(Merb::ControllerExceptions::Base) 
    9696        self.class.name.snake_case.split('::').last 
     
    200200    # in another view or the layout. 
    201201    def catch_content(name) 
    202       cached_view_context.instance_variable_get("@_#{name}_content") 
     202      thrown_content[name]  
    203203    end 
    204204     
     
    226226          end   
    227227        end       
    228          
    229         cached_view_context.instance_variable_set('@_layout_content', content) 
     228 
     229        thrown_content[:layout] = content 
    230230        engine = engine_for(layout_choice) 
    231231        options = { 
  • trunk/lib/merb/part_controller.rb

    r399 r412  
    44     
    55    def initialize(web_controller) 
    6       @_benchmarks = {} 
    76      @web_controller = web_controller 
     7      super 
    88    end 
    99 
  • trunk/lib/merb/template/markaby.rb

    r364 r412  
    99  class Builder 
    1010    def _buf; self end 
    11     def throw_content(name, &block) 
    12       @helpers.instance_variable_set "@_#{name}_content", 
    13         eval("@_#{name}_content = (@_#{name}_content|| '') + capture(&block)") 
    14     end 
    1511  end 
    1612end 
  • trunk/lib/merb/view_context.rb

    r401 r412  
    1515                       @_view_context_cache 
    1616                       @_response 
    17                        @_params] 
     17                       @_params 
     18                       @thrown_content] 
    1819                        
    1920  module GlobalHelper 
  • trunk/specs/merb/merb_mail_controller_spec.rb

    r360 r412  
    123123    @res = StringIO.new     
    124124    call_action :one 
     125    puts @delivery.inspect 
    125126    @delivery.text.should == "BASIC\nONE_CONTROLLER\nLAYOUT"     
    126127  end 
  • trunk/specs/merb/merb_view_context_spec.rb

    r405 r412  
    5757  end 
    5858end 
     59 
     60describe "View Context", "throw_content, catch_content" do 
     61   
     62  before :each do 
     63    @in = Merb::Test::FakeRequest.new 
     64    @res = StringIO.new 
     65  end 
     66 
     67  after :each do 
     68    @in = nil 
     69    @res=nil 
     70  end 
     71   
     72  it "should throw content" do 
     73    c = Merb::Controller.build @in.req, @in.env, {}, @res 
     74    content = c.render :template => "examples/template_throw_content", :layout => :none 
     75    content.should match( /THROWN CONTENT/m ) 
     76  end 
     77 
     78  it "should throw content including a partial" do 
     79    c = Merb::Controller.build @in.req, @in.env, {}, @res 
     80    content = c.render :template => "examples/template_catch_content_from_partial", :layout => :none 
     81    content.should match( /CONTENT THROWN FROM PARTIAL/m ) 
     82  end 
     83 
     84  it "should catch content" do 
     85    c = Merb::Controller.build @in.req, @in.env, {}, @res 
     86    content = c.render :template => "examples/template_catch_content", :layout => :none 
     87    content.should match( /CAUGHT CONTENT/m) 
     88  end 
     89     
     90 
     91end 
     92 
     93describe "View Context", "throw_content, catch_content" do 
     94   
     95  before :each do 
     96    @in = Merb::Test::FakeRequest.new 
     97    @res = StringIO.new 
     98  end 
     99 
     100  after :each do 
     101    @in = nil 
     102    @res=nil 
     103  end 
     104   
     105  it "should throw content" do 
     106    c = Merb::Controller.build @in.req, @in.env, {}, @res 
     107    content = c.render :template => "examples/template_throw_content", :layout => :none 
     108    content.should match( /THROWN CONTENT/m ) 
     109  end 
     110 
     111  it "should throw content including a partial" do 
     112    c = Merb::Controller.build @in.req, @in.env, {}, @res 
     113    content = c.render :template => "examples/template_catch_content_from_partial", :layout => :none 
     114    content.should match( /CONTENT THROWN FROM PARTIAL/m ) 
     115  end 
     116 
     117  it "should catch content" do 
     118    c = Merb::Controller.build @in.req, @in.env, {}, @res 
     119    content = c.render :template => "examples/template_catch_content", :layout => :none 
     120    content.should match( /CAUGHT CONTENT/m) 
     121  end 
     122     
     123 
     124end 
  • trunk/specs/spec_helper.rb

    r401 r412  
    1818  res = StringIO.new 
    1919  request = Merb::Test::FakeRequest.with( path, :request_method => (verb.to_s.upcase rescue 'GET')) 
    20   route = Merb::Dispatcher.route_path path 
    21   Merb::Dispatcher.stub!(:resolve_controller).and_return {  
    22     Object.const_get( route[:controller].camel_case ) 
    23   } 
    2420  Merb::Dispatcher.handle request, res 
    2521end