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 CHANGED
@@ -55,9 +55,11 @@ task :gemspec do
55
55
  puts "Created gemspec: #{file}"
56
56
  end
57
57
 
58
- require 'cucumber'
59
- require 'cucumber/rake/task'
60
-
61
- Cucumber::Rake::Task.new(:features) do |t|
62
- t.cucumber_opts = "test/features --format pretty"
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, type, options={})
56
- view_node = SiteMap::ViewNode.new(*view_node_params(new_index, type, options))
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 type == :group
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
@@ -37,8 +37,8 @@ module SiteMap
37
37
 
38
38
  protected
39
39
 
40
- def view_node_params(index, type, options)
41
- [index, self, type, options]
40
+ def view_node_params(index, node_type, options)
41
+ [index, self, node_type, options]
42
42
  end
43
43
 
44
44
  end
@@ -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
@@ -0,0 +1,3 @@
1
+ Dir[File.join(File.dirname(__FILE__), "tasks" ,"*.rake")].each do |file|
2
+ load File.join('site_map', 'tasks', File.basename(file))
3
+ end
@@ -2,8 +2,8 @@ module SiteMap
2
2
  module Version
3
3
 
4
4
  MAJOR = 0
5
- MINOR = 2
6
- TINY = 9
5
+ MINOR = 3
6
+ TINY = 0
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
@@ -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, :type ]
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, type, options={})
28
- raise(ArgumentError, "index, map and type arguements required") unless index && map && type
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
- @type = type
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 |type|
78
- self.send(:define_method, "#{type}?", lambda{ self.type == type })
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, :type, :label, :url, :visible].collect do |attribute|
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(@type)
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(@type)
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[@type])
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 @type == :collection
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.type)
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[@type])
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[@type])
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, type, options)
151
- [new_index, self.map, type, options.merge(:parent => self)]
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
- require File.join('site_map', File.basename(file, ".rb"))
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.2.9
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