site_map 0.2.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +7 -5
- data/lib/site_map/helpers/mapping.rb +3 -3
- data/lib/site_map/map.rb +2 -2
- data/lib/site_map/tasks/view_nodes.rake +54 -0
- data/lib/site_map/tasks.rb +3 -0
- data/lib/site_map/version.rb +2 -2
- data/lib/site_map/view_node.rb +22 -16
- data/lib/site_map.rb +3 -1
- metadata +3 -1
data/Rakefile
CHANGED
@@ -55,9 +55,11 @@ task :gemspec do
|
|
55
55
|
puts "Created gemspec: #{file}"
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
require '
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
task :environment do
|
59
|
+
require File.join(File.dirname(__FILE__), 'test', 'test_helper.rb')
|
60
|
+
files_path = File.expand_path(File.join(File.dirname(__FILE__), 'test', 'support', 'config', 'site_map', '*.rb'))
|
61
|
+
files = Dir[files_path].sort
|
62
|
+
SiteMap.setup(files)
|
63
63
|
end
|
64
|
+
|
65
|
+
load File.join(File.dirname(__FILE__), 'lib', 'site_map', 'tasks', 'view_nodes.rake')
|
@@ -52,10 +52,10 @@ module SiteMap
|
|
52
52
|
|
53
53
|
protected
|
54
54
|
|
55
|
-
def add_node(new_index,
|
56
|
-
view_node = SiteMap::ViewNode.new(*view_node_params(new_index,
|
55
|
+
def add_node(new_index, node_type, options={})
|
56
|
+
view_node = SiteMap::ViewNode.new(*view_node_params(new_index, node_type, options))
|
57
57
|
self.add_to_children(view_node)
|
58
|
-
self.map.add_to_index(new_index, view_node) unless
|
58
|
+
self.map.add_to_index(new_index, view_node) unless node_type == :group
|
59
59
|
view_node
|
60
60
|
end
|
61
61
|
|
data/lib/site_map/map.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
namespace :site_map do
|
2
|
+
|
3
|
+
desc 'Print out all defined view nodes based on the current SiteMap configuration'
|
4
|
+
task :nodes => :environment do
|
5
|
+
index_length = SiteMap.map.index_of_nodes.collect{|key, value| key.inspect.length}.max
|
6
|
+
index_length += (SiteMap.map.index_of_nodes.collect{|key, value| value.ancestors.size}.max * 2)
|
7
|
+
label_length = SiteMap.map.index_of_nodes.collect{|key, value| value.label.inspect.length}.max
|
8
|
+
url_length = SiteMap.map.index_of_nodes.collect{|key, value| value.url.inspect.length}.max
|
9
|
+
options = {
|
10
|
+
:spacing => 0,
|
11
|
+
:index_length => index_length,
|
12
|
+
:label_length => label_length,
|
13
|
+
:url_length => url_length
|
14
|
+
}
|
15
|
+
display_header(options)
|
16
|
+
display_view_nodes(SiteMap.view_nodes, options)
|
17
|
+
print "\n * - denotes an that this index is an alias of the previous node (that isn't an alias)"
|
18
|
+
print "\n indentation denotes children nodes"
|
19
|
+
print "\n\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
def display_view_nodes(view_nodes, options={})
|
23
|
+
view_nodes.each do |view_node|
|
24
|
+
display_view_node(view_node, view_node.index, options)
|
25
|
+
view_node.aliases.each do |alias_key|
|
26
|
+
display_view_node(view_node, alias_key, options)
|
27
|
+
end
|
28
|
+
display_view_nodes(view_node.children, options.merge(:spacing => (options[:spacing] + 2)))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def display_view_node(view_node, key=nil, options={})
|
33
|
+
key ||= view_node.index
|
34
|
+
print "#{(' ' * options[:spacing])}#{key.inspect}#{'*' if key != view_node.index}".ljust(options[:index_length])
|
35
|
+
print " | "
|
36
|
+
print "#{view_node.label.inspect.ljust(options[:label_length])}"
|
37
|
+
print " | "
|
38
|
+
print "#{view_node.url.inspect.ljust(options[:url_length])}"
|
39
|
+
print " | "
|
40
|
+
print "#{view_node.visible.inspect}"
|
41
|
+
print "\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
def display_header(options={})
|
45
|
+
print "Node Index".ljust(options[:index_length])
|
46
|
+
print " | "
|
47
|
+
print "Label".ljust(options[:label_length])
|
48
|
+
print " | "
|
49
|
+
print "URL".ljust(options[:url_length])
|
50
|
+
print " | "
|
51
|
+
print "Visible"
|
52
|
+
print "\n"
|
53
|
+
end
|
54
|
+
end
|
data/lib/site_map/version.rb
CHANGED
data/lib/site_map/view_node.rb
CHANGED
@@ -3,7 +3,7 @@ module SiteMap
|
|
3
3
|
|
4
4
|
class ViewNode
|
5
5
|
include SiteMap::Helpers::Mapping
|
6
|
-
ATTRIBUTES = [ :map, :index, :label, :url, :visible, :resource, :parent, :
|
6
|
+
ATTRIBUTES = [ :map, :index, :label, :url, :visible, :resource, :parent, :node_type ]
|
7
7
|
ATTRIBUTES.each{|attribute| attr_reader attribute }
|
8
8
|
|
9
9
|
TYPES = [ :view, :group, :member, :collection ]
|
@@ -24,11 +24,11 @@ module SiteMap
|
|
24
24
|
:show => BASE_URL_TEMPLATE[:member]
|
25
25
|
}
|
26
26
|
|
27
|
-
def initialize(index, map,
|
28
|
-
raise(ArgumentError, "index, map and
|
27
|
+
def initialize(index, map, node_type, options={})
|
28
|
+
raise(ArgumentError, "index, map and node_type arguements required") unless index && map && node_type
|
29
29
|
@index = index
|
30
30
|
@map = map
|
31
|
-
@
|
31
|
+
@node_type = node_type
|
32
32
|
options.each do |method, value|
|
33
33
|
instance_variable_set("@#{method}", value)
|
34
34
|
end
|
@@ -49,6 +49,12 @@ module SiteMap
|
|
49
49
|
@visible ? @visible : 'true'
|
50
50
|
end
|
51
51
|
|
52
|
+
def aliases
|
53
|
+
@aliases ||= self.map.index_of_nodes.collect do |key, view_node|
|
54
|
+
key if view_node.index == self.index && key != self.index
|
55
|
+
end.compact
|
56
|
+
end
|
57
|
+
|
52
58
|
def add_to_children(view_node)
|
53
59
|
@view_nodes.push(view_node)
|
54
60
|
end
|
@@ -74,12 +80,12 @@ module SiteMap
|
|
74
80
|
@with_siblings ||= self.parent.children
|
75
81
|
end
|
76
82
|
|
77
|
-
TYPES.each do |
|
78
|
-
self.send(:define_method, "#{
|
83
|
+
TYPES.each do |node_type|
|
84
|
+
self.send(:define_method, "#{node_type}?", lambda{ self.node_type == node_type })
|
79
85
|
end
|
80
86
|
|
81
87
|
def inspect
|
82
|
-
attributes_string = [:index, :
|
88
|
+
attributes_string = [:index, :node_type, :label, :url, :visible].collect do |attribute|
|
83
89
|
"#{attribute}: #{self.send(attribute).inspect}"
|
84
90
|
end.join(", ")
|
85
91
|
"#<#{self.class} #{attributes_string}>"
|
@@ -88,7 +94,7 @@ module SiteMap
|
|
88
94
|
protected
|
89
95
|
|
90
96
|
def default_label
|
91
|
-
case(@
|
97
|
+
case(@node_type)
|
92
98
|
when :group
|
93
99
|
self.title_string(@index)
|
94
100
|
when :collection
|
@@ -100,7 +106,7 @@ module SiteMap
|
|
100
106
|
end
|
101
107
|
end
|
102
108
|
def default_url
|
103
|
-
case(@
|
109
|
+
case(@node_type)
|
104
110
|
when :group
|
105
111
|
self.children.empty? ? @url : self.children.first.url
|
106
112
|
when :collection
|
@@ -113,18 +119,18 @@ module SiteMap
|
|
113
119
|
end
|
114
120
|
|
115
121
|
def resource_label(resource_text)
|
116
|
-
template = (LABEL_ACTION_TEMPLATES[@action] || BASE_LABEL_TEMPLATE[@
|
122
|
+
template = (LABEL_ACTION_TEMPLATES[@action] || BASE_LABEL_TEMPLATE[@node_type])
|
117
123
|
template.gsub(':action', self.title_string(@action.to_s)).gsub(':resource', resource_text)
|
118
124
|
end
|
119
125
|
def resource_url
|
120
|
-
resource_text = if @
|
126
|
+
resource_text = if @node_type == :collection
|
121
127
|
action_str = unless URL_ACTION_TEMPLATES[@action]
|
122
128
|
@action.to_s
|
123
129
|
end
|
124
|
-
parent_str = if [:member, :collection].include?(self.parent.
|
130
|
+
parent_str = if self.parent && [:member, :collection].include?(self.parent.node_type)
|
125
131
|
self.single_string(self.parent.resource)
|
126
132
|
end
|
127
|
-
template = (URL_ACTION_TEMPLATES[@action] || BASE_URL_TEMPLATE[@
|
133
|
+
template = (URL_ACTION_TEMPLATES[@action] || BASE_URL_TEMPLATE[@node_type])
|
128
134
|
resourced_url = [action_str, parent_str, template].flatten.compact.join('_')
|
129
135
|
resourced_url = [resourced_url, ("(@#{parent_str})" if parent_str)].compact.join
|
130
136
|
resourced_url.gsub(':resource', (@action == :new ? self.single_string : @resource.to_s))
|
@@ -132,7 +138,7 @@ module SiteMap
|
|
132
138
|
action_str = unless URL_ACTION_TEMPLATES[@action]
|
133
139
|
@action.to_s
|
134
140
|
end
|
135
|
-
template = (URL_ACTION_TEMPLATES[@action] || BASE_URL_TEMPLATE[@
|
141
|
+
template = (URL_ACTION_TEMPLATES[@action] || BASE_URL_TEMPLATE[@node_type])
|
136
142
|
resourced_url = [action_str, template].flatten.compact.join('_')
|
137
143
|
resourced_url.gsub(':resource', self.single_string)
|
138
144
|
end
|
@@ -147,8 +153,8 @@ module SiteMap
|
|
147
153
|
string.to_s.respond_to?(:titleize) ? string.to_s.titleize : string.to_s
|
148
154
|
end
|
149
155
|
|
150
|
-
def view_node_params(new_index,
|
151
|
-
[new_index, self.map,
|
156
|
+
def view_node_params(new_index, node_type, options)
|
157
|
+
[new_index, self.map, node_type, options.merge(:parent => self)]
|
152
158
|
end
|
153
159
|
|
154
160
|
end
|
data/lib/site_map.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
Dir[File.join(File.dirname(__FILE__), "site_map" ,"*.rb")].each do |file|
|
2
|
-
|
2
|
+
unless ['tasks', 'version'].include?(File.basename(file, ".rb"))
|
3
|
+
require File.join('site_map', File.basename(file, ".rb"))
|
4
|
+
end
|
3
5
|
end
|
4
6
|
|
5
7
|
module SiteMap
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Collin Redding
|
@@ -29,6 +29,8 @@ files:
|
|
29
29
|
- lib/site_map/helpers/mapping.rb
|
30
30
|
- lib/site_map/helpers.rb
|
31
31
|
- lib/site_map/map.rb
|
32
|
+
- lib/site_map/tasks/view_nodes.rake
|
33
|
+
- lib/site_map/tasks.rb
|
32
34
|
- lib/site_map/version.rb
|
33
35
|
- lib/site_map/view_helpers.rb
|
34
36
|
- lib/site_map/view_node.rb
|