Module: SiteMap::Helpers::Mapping
Constant Summary collapse
- DEFAULT_ALIAS =
{ :index => [:new, :create], :new => [:create], :show => [:edit, :update, :destroy], :edit => [:update] }
Instance Method Summary collapse
- #alias(new_index, existing_index) ⇒ Object
- #collection(resource, options = {}) {|view_node| ... } ⇒ Object
- #collection_view(resource, action, options = {}) ⇒ Object
- #group(new_index, options = {}) {|view_node| ... } ⇒ Object
- #member(resource, options = {}) {|view_node| ... } ⇒ Object
- #member_view(resource, action, options = {}) ⇒ Object
- #view(new_index, options = {}) {|view_node| ... } ⇒ Object
Instance Method Details
#alias(new_index, existing_index) ⇒ Object
22 23 24 25 26 |
# File 'lib/site_map/helpers/mapping.rb', line 22 def alias(new_index, existing_index) view_node = SiteMap[existing_index] raise(SiteMap::Exceptions::NonExistantViewNode, "view node with index #{existing_index} does not exist for aliasing") unless view_node self.map.add_to_index(new_index, view_node) end |
#collection(resource, options = {}) {|view_node| ... } ⇒ Object
28 29 30 31 |
# File 'lib/site_map/helpers/mapping.rb', line 28 def collection(resource, ={}) view_node = self.collection_view(resource, :index, ) yield view_node if block_given? end |
#collection_view(resource, action, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/site_map/helpers/mapping.rb', line 32 def collection_view(resource, action, ={}) .merge!({:resource => resource.to_sym, :action => action.to_sym}) view_node = self.add_node(self.index_for(resource, action), :collection, ) (DEFAULT_ALIAS[action] || []).each do |action| view_node.alias(self.index_for(resource, action), view_node.index) end block_given? ? (yield view_node) : view_node end |
#group(new_index, options = {}) {|view_node| ... } ⇒ Object
13 14 15 16 |
# File 'lib/site_map/helpers/mapping.rb', line 13 def group(new_index, ={}) view_node = self.add_node(new_index, :group, ) yield view_node if block_given? end |
#member(resource, options = {}) {|view_node| ... } ⇒ Object
40 41 42 43 |
# File 'lib/site_map/helpers/mapping.rb', line 40 def member(resource, ={}) view_node = self.member_view(resource, :show, ) yield view_node if block_given? end |
#member_view(resource, action, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/site_map/helpers/mapping.rb', line 44 def member_view(resource, action, ={}) .merge!({:resource => resource.to_sym, :action => action.to_sym}) view_node = self.add_node(self.index_for(resource, action), :member, ) (DEFAULT_ALIAS[action] || []).each do |action| view_node.alias(self.index_for(resource, action), view_node.index) end block_given? ? (yield view_node) : view_node end |
#view(new_index, options = {}) {|view_node| ... } ⇒ Object
17 18 19 20 |
# File 'lib/site_map/helpers/mapping.rb', line 17 def view(new_index, ={}) view_node = self.add_node(new_index, :view, ) yield view_node if block_given? end |