site_map 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ module SiteMap
2
+ module Helpers
3
+
4
+ module ActionController
5
+
6
+ protected
7
+
8
+ def view_node
9
+ @view_node ||= SiteMap[[self.controller_name, self.action_name].join('__').to_sym]
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+ end
@@ -32,7 +32,7 @@ module SiteMap
32
32
  def collection_view(resource, action, options={})
33
33
  options.merge!({:resource => resource.to_sym, :action => action.to_sym})
34
34
  view_node = self.add_node([resource, action].join('__').to_sym, :collection, options)
35
- DEFAULT_ALIAS[action].each do |action|
35
+ (DEFAULT_ALIAS[action] || []).each do |action|
36
36
  view_node.alias([resource, action].join('__').to_sym, view_node.index)
37
37
  end
38
38
  block_given? ? (yield view_node) : view_node
@@ -44,7 +44,7 @@ module SiteMap
44
44
  def member_view(resource, action, options={})
45
45
  options.merge!({:resource => resource.to_sym, :action => action.to_sym})
46
46
  view_node = self.add_node([resource, action].join('__').to_sym, :member, options)
47
- DEFAULT_ALIAS[action].each do |action|
47
+ (DEFAULT_ALIAS[action] || []).each do |action|
48
48
  view_node.alias([resource, action].join('__').to_sym, view_node.index)
49
49
  end
50
50
  block_given? ? (yield view_node) : view_node
@@ -3,7 +3,7 @@ module SiteMap
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 2
6
- TINY = 6
6
+ TINY = 7
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
@@ -23,4 +23,4 @@ module SiteMap
23
23
  alias :view_node_visible? :view_node_visible
24
24
 
25
25
  end
26
- end
26
+ end
@@ -7,17 +7,21 @@ module SiteMap
7
7
  ATTRIBUTES.each{|attribute| attr_reader attribute }
8
8
 
9
9
  TYPES = [ :view, :group, :member, :collection ]
10
+ BASE_LABEL_TEMPLATE = {
11
+ :collection => ":action :resource",
12
+ :member => ":action ::resource_name"
13
+ }
10
14
  LABEL_ACTION_TEMPLATES = {
11
- :index => ":resource List",
12
- :new => "New :resource",
13
- :show => "::resource_name",
14
- :edit => "Edit ::resource_name"
15
+ :index => BASE_LABEL_TEMPLATE[:collection].gsub(':action','').strip,
16
+ :show => BASE_LABEL_TEMPLATE[:member].gsub(':action','').strip
17
+ }
18
+ BASE_URL_TEMPLATE = {
19
+ :collection => [':resource', 'path'],
20
+ :member => [':resource', 'path(@:resource)']
15
21
  }
16
22
  URL_ACTION_TEMPLATES = {
17
- :index => ":resource_path",
18
- :new => "new_:resource_path",
19
- :show => ":resource_path(@:resource)",
20
- :edit => "edit_:resource_path(@:resource)"
23
+ :index => BASE_URL_TEMPLATE[:collection],
24
+ :show => BASE_URL_TEMPLATE[:member]
21
25
  }
22
26
 
23
27
  def initialize(index, map, type, options={})
@@ -109,20 +113,30 @@ module SiteMap
109
113
  end
110
114
 
111
115
  def resource_label(resource_text)
112
- LABEL_ACTION_TEMPLATES[@action].gsub(':resource', resource_text)
116
+ template = (LABEL_ACTION_TEMPLATES[@action] || BASE_LABEL_TEMPLATE[@type])
117
+ template.gsub(':action', self.title_string(@action.to_s)).gsub(':resource', resource_text)
113
118
  end
114
119
  def resource_url
115
120
  resource_text = if @type == :collection
116
- parent_sym = if [:member, :collection].include?(self.parent.type)
121
+ action_str = unless URL_ACTION_TEMPLATES[@action]
122
+ @action.to_s
123
+ end
124
+ parent_str = if [:member, :collection].include?(self.parent.type)
117
125
  self.single_string(self.parent.resource)
118
126
  elsif self.parent.type == :group
119
- self.parent.index
127
+ self.parent.index.to_s
120
128
  end
121
- resource_with_parent = [parent_sym, (@action == :new ? self.single_string : @resource.to_s)].compact.join('_')
122
- resourced_url = URL_ACTION_TEMPLATES[@action].gsub(':resource', resource_with_parent)
123
- [resourced_url, ("(@#{parent_sym})" if parent_sym)].compact.join
129
+ template = (URL_ACTION_TEMPLATES[@action] || BASE_URL_TEMPLATE[@type])
130
+ resourced_url = [action_str, parent_str, template].flatten.compact.join('_')
131
+ resourced_url = [resourced_url, ("(@#{parent_str})" if parent_str)].compact.join
132
+ resourced_url.gsub(':resource', (@action == :new ? self.single_string : @resource.to_s))
124
133
  else
125
- URL_ACTION_TEMPLATES[@action].gsub(':resource', self.single_string)
134
+ action_str = unless URL_ACTION_TEMPLATES[@action]
135
+ @action.to_s
136
+ end
137
+ template = (URL_ACTION_TEMPLATES[@action] || BASE_URL_TEMPLATE[@type])
138
+ resourced_url = [action_str, template].flatten.compact.join('_')
139
+ resourced_url.gsub(':resource', self.single_string)
126
140
  end
127
141
  end
128
142
 
data/lib/site_map.rb CHANGED
@@ -34,4 +34,7 @@ module SiteMap
34
34
  end
35
35
 
36
36
  end
37
- SiteMap.setup
37
+ SiteMap.setup
38
+
39
+ ActionView::Base.send(:include, SiteMap::ViewHelpers) if defined?(ActionView::Base)
40
+ ActionController::Base.send(:include, SiteMap::Helpers::ActionController) if defined?(ActionController::Base)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site_map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collin Redding
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-18 00:00:00 -06:00
12
+ date: 2010-01-19 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,6 +25,7 @@ files:
25
25
  - README.rdoc
26
26
  - Rakefile
27
27
  - lib/site_map/exceptions.rb
28
+ - lib/site_map/helpers/action_controller.rb
28
29
  - lib/site_map/helpers/mapping.rb
29
30
  - lib/site_map/helpers.rb
30
31
  - lib/site_map/map.rb