lib/spiderfw/controller/mixins/visual.rb in spiderfw-0.6.27 vs lib/spiderfw/controller/mixins/visual.rb in spiderfw-0.6.28

- old
+ new

@@ -27,13 +27,14 @@ @layout ||= @dispatcher_layout 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?) set_layout = @layout + layout_params = self.class.layout_params[@layout] if set_layout set_layout = [set_layout] unless set_layout.is_a?(Array) - set_layout.map{ |l| self.class.load_layout(l) } + set_layout.map{ |l| self.class.load_layout(l, layout_params) } obj.dispatcher_layout = set_layout end end end return super unless action_target? @@ -204,12 +205,12 @@ template._action = template_action.join('/') end return template end - def init_layout(layout) - l = layout.is_a?(Layout) ? layout : self.class.load_layout(layout) + def init_layout(layout, params={}) + l = layout.is_a?(Layout) ? layout : self.class.load_layout(layout, params) prepare_template(l) return l end def render(path=nil, options={}) @@ -224,16 +225,18 @@ template = get_template(path, scene, options) end layout = nil unless options.key?(:layout) && !options[:layout] chosen_layouts = options[:layout] || @layout + layout_params = self.class.layout_params[chosen_layouts] chosen_layouts = [chosen_layouts] if chosen_layouts && !chosen_layouts.is_a?(Array) if (chosen_layouts) t = template layout = nil (chosen_layouts.length-1).downto(0) do |i| - layout = init_layout(chosen_layouts[i]) + l_params = layout_params if layout_params && i == 0 + layout = init_layout(chosen_layouts[i], layout_params) layout.template = t t = layout end end layout.init(scene) if layout @@ -585,15 +588,15 @@ return true if File.exist?(full) end return false end - def load_layout(path) + def load_layout(path, params={}) unless respond_to?(:layout_path) raise NotImplementedError, "The layout_path class method must be implemented by object using the Visual mixin, but #{self} does not" end - params = self.layout_params[path] || {} + params ||= self.layout_params[path] || {} if (path.is_a?(Symbol)) path = Spider::Layout.named_layouts[path] end resource = Spider::Template.find_resource(path+'.layout', layout_path, self) raise "Layout #{path} not found" unless resource && resource.path @@ -602,11 +605,10 @@ layout.asset_set = params[:assets] if params[:assets] layout.no_asset_profiles(*params[:no_asset_profiles]) if params[:no_asset_profiles] layout.only_asset_profiles(params[:only_asset_profiles]) if params[:only_asset_profiles] layout end - - + def current_default_template Spider::Inflector.underscore(self.to_s.split('::')[-1]) end def assets