Module: SiteMap::Helpers::Mapping

Included in:
Map, ViewNode
Defined in:
lib/site_map/helpers/mapping.rb

Constant Summary collapse

DEFAULT_ALIAS =
{
  :index => [:new, :create],
  :new => [:create],
  :show => [:edit, :update, :destroy],
  :edit => [:update]
}

Instance Method Summary collapse

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

Yields:

  • (view_node)


28
29
30
31
# File 'lib/site_map/helpers/mapping.rb', line 28

def collection(resource, options={})
  view_node = self.collection_view(resource, :index, options)
  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, options={})
  options.merge!({:resource => resource.to_sym, :action => action.to_sym})
  view_node = self.add_node(self.index_for(resource, action), :collection, options)
  (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

Yields:

  • (view_node)


13
14
15
16
# File 'lib/site_map/helpers/mapping.rb', line 13

def group(new_index, options={})
  view_node = self.add_node(new_index, :group, options)
  yield view_node if block_given?
end

#member(resource, options = {}) {|view_node| ... } ⇒ Object

Yields:

  • (view_node)


40
41
42
43
# File 'lib/site_map/helpers/mapping.rb', line 40

def member(resource, options={})
  view_node = self.member_view(resource, :show, options)
  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, options={})
  options.merge!({:resource => resource.to_sym, :action => action.to_sym})
  view_node = self.add_node(self.index_for(resource, action), :member, options)
  (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

Yields:

  • (view_node)


17
18
19
20
# File 'lib/site_map/helpers/mapping.rb', line 17

def view(new_index, options={})
  view_node = self.add_node(new_index, :view, options)
  yield view_node if block_given?
end