Changeset 412
- Timestamp:
- 08/13/07 16:25:53 (1 year ago)
- Files:
-
- trunk/lib/merb.rb (modified) (1 diff)
- trunk/lib/merb/abstract_controller.rb (modified) (2 diffs)
- trunk/lib/merb/dispatcher.rb (modified) (1 diff)
- trunk/lib/merb/exceptions.rb (modified) (2 diffs)
- trunk/lib/merb/mail_controller.rb (modified) (1 diff)
- trunk/lib/merb/mixins/erubis_capture.rb (modified) (3 diffs)
- trunk/lib/merb/mixins/render.rb (modified) (3 diffs)
- trunk/lib/merb/part_controller.rb (modified) (1 diff)
- trunk/lib/merb/template/markaby.rb (modified) (1 diff)
- trunk/lib/merb/view_context.rb (modified) (1 diff)
- trunk/specs/fixtures/views/examples/_throw_content.herb (added)
- trunk/specs/fixtures/views/examples/template_catch_content.herb (added)
- trunk/specs/fixtures/views/examples/template_catch_content_from_partial.herb (added)
- trunk/specs/fixtures/views/examples/template_throw_content.herb (added)
- trunk/specs/merb/merb_mail_controller_spec.rb (modified) (1 diff)
- trunk/specs/merb/merb_view_context_spec.rb (modified) (1 diff)
- trunk/specs/spec_helper.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/merb.rb
r410 r412 14 14 require 'json' 15 15 require 'set' 16 16 17 autoload :MerbUploadHandler, 'merb/upload_handler' 17 18 autoload :MerbHandler, 'merb/mongrel_handler' trunk/lib/merb/abstract_controller.rb
r401 r412 9 9 # Holds internal execution times. Prefaced with an underscore to not 10 10 # conflict with user-defined controller instance variables. 11 attr_accessor :_benchmarks 11 attr_accessor :_benchmarks, :thrown_content 12 12 13 13 def initialize(*args) 14 14 @_benchmarks = {} 15 @thrown_content = AbstractController.default_thrown_content 15 16 end 16 17 … … 187 188 return opts 188 189 end 190 191 def self.default_thrown_content 192 Hash.new{ |hash, key| hash[key] = "" } 193 end 194 195 189 196 end 190 197 trunk/lib/merb/dispatcher.rb
r399 r412 78 78 if !File.exist?(path) 79 79 raise ControllerExceptions::NotFound, "Bad controller! #{cnt}" 80 end #unless $TESTING80 end unless $TESTING 81 81 82 82 begin 83 if MERB_ENV == 'development'84 Object.send(:remove_const, cnt)85 load(path)86 end87 83 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 91 86 end 92 87 end trunk/lib/merb/exceptions.rb
r399 r412 51 51 include Merb::ControllerMixin 52 52 include Merb::ResponderMixin 53 attr_accessor :thrown_content 54 53 55 54 56 def set_env(request, response, controller = nil) … … 56 58 @response = response 57 59 @controller = controller 60 @thrown_content = ::Merb::AbstractController.default_thrown_content 58 61 end 59 62 trunk/lib/merb/mail_controller.rb
r411 r412 18 18 @base_controller = controller 19 19 @session = (controller && controller.session) || {} 20 super 20 21 end 21 22 trunk/lib/merb/mixins/erubis_capture.rb
r401 r412 1 1 module Merb 2 3 2 4 3 5 module ErubisCaptureMixin … … 40 42 # <%= catch_content :header %> 41 43 def throw_content(name, content = nil, &block) 42 eval "@_#{name}_content = (@_#{name}_content || '') + capture(&block)"44 controller.thrown_content[name] << ( content || "" ) << capture( &block ) 43 45 end 44 46 … … 67 69 68 70 def erb_content_for(name, &block) 69 eval "@_#{name}_content = (@_#{name}_content|| '') + capture_erb(&block)"71 controller.thrown_content[name] << capture_erb( &block ) 70 72 end 71 73 72 74 def block_content_for(name, &block) 73 eval "@_#{name}_content = (@_#{name}_content|| '') + capture_block(&block)"75 controller.thrown_content[name] << capture_block( &block ) 74 76 end 75 77 end trunk/lib/merb/mixins/render.rb
r401 r412 92 92 # 93 93 def render(opts={}, &blk) 94 94 95 95 action = if kind_of?(Merb::ControllerExceptions::Base) 96 96 self.class.name.snake_case.split('::').last … … 200 200 # in another view or the layout. 201 201 def catch_content(name) 202 cached_view_context.instance_variable_get("@_#{name}_content")202 thrown_content[name] 203 203 end 204 204 … … 226 226 end 227 227 end 228 229 cached_view_context.instance_variable_set('@_layout_content', content)228 229 thrown_content[:layout] = content 230 230 engine = engine_for(layout_choice) 231 231 options = { trunk/lib/merb/part_controller.rb
r399 r412 4 4 5 5 def initialize(web_controller) 6 @_benchmarks = {}7 6 @web_controller = web_controller 7 super 8 8 end 9 9 trunk/lib/merb/template/markaby.rb
r364 r412 9 9 class Builder 10 10 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 end15 11 end 16 12 end trunk/lib/merb/view_context.rb
r401 r412 15 15 @_view_context_cache 16 16 @_response 17 @_params] 17 @_params 18 @thrown_content] 18 19 19 20 module GlobalHelper trunk/specs/merb/merb_mail_controller_spec.rb
r360 r412 123 123 @res = StringIO.new 124 124 call_action :one 125 puts @delivery.inspect 125 126 @delivery.text.should == "BASIC\nONE_CONTROLLER\nLAYOUT" 126 127 end trunk/specs/merb/merb_view_context_spec.rb
r405 r412 57 57 end 58 58 end 59 60 describe "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 91 end 92 93 describe "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 124 end trunk/specs/spec_helper.rb
r401 r412 18 18 res = StringIO.new 19 19 request = Merb::Test::FakeRequest.with( path, :request_method => (verb.to_s.upcase rescue 'GET')) 20 route = Merb::Dispatcher.route_path path21 Merb::Dispatcher.stub!(:resolve_controller).and_return {22 Object.const_get( route[:controller].camel_case )23 }24 20 Merb::Dispatcher.handle request, res 25 21 end
