0
class ApplicationController
0
include ApplicationHelper
0
attr_writer :layouts_conditions
0
+ @filters ||= {:before => [], :after => []}
0
+ def before_filter(method)
0
+ filters[:before] << [method, nil]
0
@layouts_conditions ||= []
0
@@ -32,24 +43,70 @@ class ApplicationController
0
- def with_layout(action = nil, &block)
0
- this_actions_layout = self.class.layout_for_action(action || params[:action])
0
- if this_actions_layout
0
- render this_actions_layout, &block
0
+ @output_buffer = StringIO.new
0
+ @output_buffer.puts(*args)
0
+ Object::STDOUT << @output_buffer.string
0
+ @output_buffer.string = ""
0
+ return if @layout_started
0
+ @layout_started = true
0
+ this_actions_layout = self.class.layout_for_action(params[:action])
0
+ return unless this_actions_layout
0
+ current_output = @output_buffer.string
0
+ @output_buffer.string = ""
0
+ @layout_thread_mutex = Mutex.new
0
+ @layout_thread = Thread.new do
0
+ @layout_thread_mutex.lock
0
+ render(this_actions_layout) { @layout_thread_mutex.unlock; Thread.stop; @layout_thread_mutex.lock }
0
+ @layout_thread_mutex.unlock
0
+ @layout_thread_mutex.wait_for_lock
0
+ @output_buffer << current_output
0
+ return unless @layout_started && @layout_thread
0
+ @layout_thread_mutex.wait_for_lock
0
+ @layout_thread = @layout_thread_mutex = nil
0
+ def with_filters(&block)
0
+ self.class.filters[:before].each do |method, options|
0
+ return false unless send(method)
0
+ self.class.filters[:after].each do |method, options|
0
+ return false unless send(method)
0
def call(action, _params = {})
0
params[:action] = action.to_s
0
- if params[:layout].to_s == "false"
0
- with_layout { send(action) }
0
+ @output_buffer = params.delete(:__output_buffer__) if params[:__output_buffer__]
0
+ with_filters { send(action) }
0
def self.call(action, params = {})
0
@@ -67,13 +124,13 @@ class ApplicationController
0
eval(__options__[:locals].keys * ", " + " = __v__.length == 1 ? __v__[0] : __v__")
0
- __erb__ = ERBStdout.new(___template___, nil, "-", "
STDOUT")
0
+ __erb__ = ERBStdout.new(___template___, nil, "-", "
@output_buffer")
0
__erb__.filename = __template_path__
0
def render_component(params = {})
0
+ dispatch(params
.merge(:layout => false, :__output_buffer__ => @output_buffer))
0
@@ -83,40 +140,32 @@ class ApplicationController
0
def content_for(name, &block)
0
var_name = "@content_for_#{name}"
0
content = instance_variable_get(var_name) || ""
0
- content << capture_output(&block)
0
+ previous_content = @output_buffer.string
0
+ @output_buffer.string = ""
0
+ content << @output_buffer.string
0
+ @output_buffer.string = ""
0
+ @output_buffer << previous_content
0
instance_variable_set(var_name, content)
0
- def set_constant_forced(klass, constant_name, constant)
0
- remove_const(constant_name) if const_defined?(constant_name)
0
- const_set(constant_name, constant)
0
- def capture_output(&block)
0
- old_stdout = Object::STDOUT
0
- io_stream = StringIO.new
0
- set_constant_forced(Object, "STDOUT", io_stream)
0
- [::Git, ::ApplicationController, ::Formatters].each do |klass|
0
- args.each{ |arg| Object::STDOUT.puts arg}
0
- set_constant_forced(Object, "STDOUT", old_stdout)