site_map 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/site_map/helpers/action_controller.rb +15 -0
- data/lib/site_map/helpers/mapping.rb +2 -2
- data/lib/site_map/version.rb +1 -1
- data/lib/site_map/view_helpers.rb +1 -1
- data/lib/site_map/view_node.rb +29 -15
- data/lib/site_map.rb +4 -1
- metadata +3 -2
@@ -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
|
data/lib/site_map/version.rb
CHANGED
data/lib/site_map/view_node.rb
CHANGED
@@ -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 =>
|
12
|
-
:
|
13
|
-
|
14
|
-
|
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 =>
|
18
|
-
:
|
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]
|
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
|
-
|
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
|
-
|
122
|
-
resourced_url =
|
123
|
-
[resourced_url, ("(@#{
|
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]
|
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.
|
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-
|
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
|