lib/spiderfw/controller/mixins/visual.rb in spiderfw-0.6.22 vs lib/spiderfw/controller/mixins/visual.rb in spiderfw-0.6.23

- old
+ new

@@ -22,10 +22,11 @@ end def before(action='', *params) @layout ||= self.class.get_layout(action) @layout ||= @dispatcher_layout + return super unless action_target? format = nil req_format = self.is_a?(Widget) && @is_target && @request.params['_wf'] ? @request.params['_wf'].to_sym : @request.format if (req_format && self.class.output_formats[@executed_method]) format = req_format if self.class.output_format?(@executed_method, req_format) if (format) @@ -43,11 +44,11 @@ if Spider.runmode != 'devel' && File.exists?(File.join(Spider.paths[:tmp], 'maintenance.txt')) raise Spider::Controller::Maintenance end n_route = dispatch_next(action) obj = n_route.obj if n_route - if obj.is_a?(Visual) && !(obj.respond_to?(:serving_static?) && obj.serving_static?(n_route.path)) + if obj.is_a?(Visual) && !(obj.respond_to?(:serving_static?) && obj.serving_static?) set_layout = @layout || @dispatcher_layout if set_layout set_layout = [set_layout] unless set_layout.is_a?(Array) set_layout.map{ |l| self.class.load_layout(l) } obj.dispatcher_layout = set_layout @@ -226,10 +227,19 @@ else template.render(scene) end return template end + + def render_to_string(*args) + res = StringIO.new + $out.output_to(res) do + render(*args) + end + res.rewind + res.read + end def render_error(path, options) options[:no_prepare_scene] = true render(path, options) end @@ -247,11 +257,11 @@ def try_rescue(exc) if exc.respond_to?(:uuid=) return super if exc.uuid # Error page already outputted - exc.uuid = UUIDTools::UUID.random_create.to_s + exc.uuid = SecureRandom.hex(12) end format = self.class.output_format(:error) || :html unless exc.is_a?(Spider::Controller::Maintenance) || exc.is_a?(Spider::Controller::NotFound) return super unless @executed_format == :html return super unless action_target? @@ -353,16 +363,21 @@ bt << {:text => str, :path => file_path, :line => line, :method => method} end return bt end context = exc.__debug_context + seen_obj = {} 0.upto(Debugger.current_context.stack_size - 2) do |i| begin file = context.frame_file(i) line = context.frame_line(i) klass = context.frame_class(i) method = context.frame_method(i) + #break if File.basename(file) == 'controller.rb' && locals.key?("spider_main_controller_send") + unless Spider.conf.get('devel.trace.show_framework') + next if file.index($SPIDER_PATH) == 0 + end args = context.frame_args(i) locals = context.frame_locals(i) frame_self = context.frame_self(i) dest = context.frame_self(i-1) unless i == 0 ex_method = context.frame_method(i-1) unless i == 0 @@ -377,49 +392,51 @@ dest_str = dest.is_a?(Class) ? dest.inspect : "#<#{dest.class}:#{dest.object_id}>" else dest_str = "" end self_str = frame_self.is_a?(Class) ? frame_self.inspect : "#<#{frame_self.class}:#{frame_self.object_id}>" - if (i == -1) - info = "" - else - # if (frame_self == dest) - # info = "#{dest_str}" - # else - # info = "#{self_str}: #{dest_str}" - # end - info = "#{self_str}: #{dest_str}" - info += ".#{ex_method}(" - info += args.map{ |arg| - val = locals[arg] - arg_str = "#{arg}##{val.class}" - val_str = nil - if (val.is_a?(String)) - if (val.length > 20) - val_str = (val[0..20]+'...').inspect - else - val_str = val.inspect - end - elsif (val.is_a?(Symbol) || val.is_a?(Fixnum) || val.is_a?(Float) || val.is_a?(BigDecimal) || val.is_a?(Date) || val.is_a?(Time)) + + # if (frame_self == dest) + # info = "#{dest_str}" + # else + # info = "#{self_str}: #{dest_str}" + # end + info = "#{self_str}: #{dest_str}" + info += ".#{ex_method}(" + info += args.map{ |arg| + val = locals[arg] + arg_str = "#{arg}##{val.class}" + val_str = nil + if (val.is_a?(String)) + if (val.length > 20) + val_str = (val[0..20]+'...').inspect + else val_str = val.inspect end - arg_str += "=#{val_str}" if val_str - arg_str - }.join(', ') - info += ")" - end - if (Spider.conf.get('devel.trace.show_instance_variables')) + elsif (val.is_a?(Symbol) || val.is_a?(Fixnum) || val.is_a?(Float) || val.is_a?(BigDecimal) || val.is_a?(Date) || val.is_a?(Time)) + val_str = val.inspect + end + arg_str += "=#{val_str}" if val_str + arg_str + }.join(', ') + info += ")" + + iv = nil + if !seen_obj[frame_self.object_id] && Spider.conf.get('devel.trace.show_instance_variables') iv = {} frame_self.instance_variables.each{ |var| iv[var] = frame_self.instance_variable_get(var) } iv.reject{ |k, v| v.nil? } end locals = nil unless Spider.conf.get('devel.trace.show_locals') bt << { :text => str, :info => info, :path => File.expand_path(file), :line => line, :method => method, :klass => klass, :locals => locals, - :instance_variables => iv + :self => frame_self.object_id, + :instance_variables => iv, + :first_seen => !seen_obj[frame_self.object_id] } + seen_obj[frame_self.object_id] = true rescue => exc2 end end return bt end @@ -491,10 +508,10 @@ if (@no_layout) @no_layout.each do |check| return nil if check_action(action, check) end end - action = (action && !action.empty?) ? action.to_sym : self.default_action + action = (action && !action.empty?) ? action.to_s.split('/').first.to_sym : self.default_action layouts.each do |name| params = @layout_params[name] if (params[:for]) next unless check_action(action, params[:for]) end