lib/lolita/controllers/internal_helpers.rb in lolita-3.1.17 vs lib/lolita/controllers/internal_helpers.rb in lolita-3.1.18

- old
+ new

@@ -3,11 +3,11 @@ module InternalHelpers extend ActiveSupport::Concern included do helper LolitaHelper #TODO pārnest helperus uz lolitu vai arī uz lolita app nevis likt iekš controllers iekš lolitas - helpers = %w(resource resource_name + helpers = %w(resource resource_name use_mapping resource_class lolita_mapping show_response tab_form tab_form=) hide_action *helpers helper_method *helpers prepend_before_filter :is_lolita_resource? @@ -19,18 +19,18 @@ def resource instance_variable_get(:"@#{resource_name}") end def resource_name - lolita_mapping.name + lolita_mapping.class_name.underscore.to_sym end def resource_class lolita_mapping.to end - def lolita_mapping + def lolita_mapping(new_mapping = nil) @lolita_mapping||=request.env["lolita.mapping"] end def tab_form=(form) @tab_form = form @@ -43,10 +43,23 @@ content = yield @tab_form = old_form end @tab_form end + + def use_mapping(new_mapping) + if block_given? + begin + @old_mapping = lolita_mapping + @lolita_mapping = new_mapping + yield + ensure + @lolita_mapping = @old_mapping + @old_mapping = nil + end + end + end protected def notice(msg) response.headers["Lolita-Notice"] = Base64.encode64(msg) @@ -60,10 +73,11 @@ response.headers["Lolita-Error"] = Base64.encode64(msg) end def is_lolita_resource? raise ActionController::UnknownAction unless lolita_mapping + true end def resource=(new_resource) instance_variable_set(:"@#{resource_name}",new_resource) end @@ -79,10 +93,10 @@ } current_resource end def get_resource(id=nil) - self.resource=resource_class.lolita.dbi.find_by_id(id||params[:id]) + self.resource = resource_class.lolita.dbi.find_by_id(id || params[:id]) end def build_resource(attributes=nil) self.run(:before_build_resource) attributes||=resource_attributes \ No newline at end of file