navGATE 0.1.27 → 0.1.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest +3 -1
- data/Rakefile +1 -1
- data/lib/navgate.rb +40 -169
- data/lib/navgate/base.rb +28 -27
- data/lib/navgate/builder.rb +96 -0
- data/lib/navgate/main.rb +60 -0
- data/lib/navgate/modules/navgatehelpers.rb +26 -0
- data/navGATE.gemspec +4 -5
- data/readme.rdoc +11 -10
- metadata +9 -6
- data/lib/navgate/navgatehelpers.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ada5671816dee12818283700eab608eda32282f
|
4
|
+
data.tar.gz: e28d7ab056f6631082a2548f63ada796f3cbe518
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1623f128d731430174efac02e16a3d248bae214bee99803b35202f90f19ab440866adaf13d8876a0c0a810a24fb286f964f409ed593d9094218cd9cdb88ffb86
|
7
|
+
data.tar.gz: b3ebe60acba3ac04ca4170d3f6bba54a978d6c3f54cdc9714bd5e5333a8c0ecb83ce7c4c8c67fc574776165845385c1abc23e727584a09d5e399e3b370465ba8
|
data/Manifest
CHANGED
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rake'
|
|
3
3
|
require 'echoe'
|
4
4
|
|
5
5
|
|
6
|
-
Echoe.new('navGATE','0.1.
|
6
|
+
Echoe.new('navGATE','0.1.30') do |p|
|
7
7
|
p.summary = "Allows the easy creation of navigation with config files"
|
8
8
|
p.description = "Can create navigation from objects using the nav builder,from database tables or from a yaml file"
|
9
9
|
p.url = "https://github.com/Thermatix/navGATE"
|
data/lib/navgate.rb
CHANGED
@@ -1,187 +1,58 @@
|
|
1
|
+
Dir[File.dirname(__FILE__) + '/navgate/modules/*.rb'].each {|file| require file }
|
1
2
|
require 'navgate/base'
|
2
|
-
require 'navgate/
|
3
|
-
require '
|
4
|
-
class Navgate
|
5
|
-
class Builder < Base
|
3
|
+
require 'navgate/builder'
|
4
|
+
require 'navgate/main'
|
6
5
|
|
7
|
-
|
8
|
-
options_to_render = ""
|
9
|
-
if self.css_class
|
10
|
-
if options && options[:class]
|
11
|
-
options[:class] = self.css_class
|
12
|
-
else
|
13
|
-
options = { class: self.css_class}
|
14
|
-
end
|
15
|
-
end
|
16
|
-
if options
|
17
|
-
options.each do |key,value|
|
18
|
-
options_to_render += ("#{key}='#{value}'" + " ") unless ignoring key
|
19
|
-
end
|
20
|
-
end
|
21
|
-
style = styling(options)
|
22
|
-
@text_to_render = ""
|
23
|
-
selected.gsub!('/',"")
|
24
|
-
if !self.by_id
|
25
|
-
self.selection.each do |select|
|
26
|
-
@text_to_render += select_text_for(select,selected,options[:wrap],options_to_render,style)
|
27
|
-
end
|
28
|
-
else
|
29
|
-
self.selection.each_with_index do |select,i|
|
30
|
-
@text_to_render += select_text_for(select,selected,options[:wrap],options_to_render,style,i)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
@text_to_render
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
def select_text_for select, selected, wrap, options_to_render, style, id=nil
|
38
|
-
return_temp = ""
|
39
|
-
wrap_with(wrap) do
|
40
|
-
if select != id && select != selected
|
41
|
-
return_temp = generate_text(select,options_to_render,style,id)
|
42
|
-
else
|
43
|
-
if self.css_selected
|
44
|
-
if options_to_render =~ /class='.*'/
|
45
|
-
temp = options_to_render.gsub(/class='.*'/,"class='#{self.css_selected}'")
|
46
|
-
return_temp = generate_text(select,temp,style,id)
|
47
|
-
else
|
48
|
-
temp = options_to_render + "class='#{self.css_selected}'"
|
49
|
-
return_temp = generate_text(select,temp,style,id)
|
50
|
-
end#select which version to use
|
51
|
-
else
|
52
|
-
return_temp = ""
|
53
|
-
end #render nothing or css_selected
|
54
|
-
end #for select if
|
55
|
-
end #for wrap method
|
56
|
-
return_temp
|
57
|
-
end #for method
|
58
|
-
def generate_text(select,options_to_render,style,id = nil)
|
59
|
-
"<a href=\"#{path_for(id || select)}\" #{options_to_render}>#{select.gsub('_'," ")}</a>#{style}"
|
60
|
-
end
|
61
|
-
def wrap_with tag, &block
|
62
|
-
if tag.is_a?(Array)
|
63
|
-
tag_beggining = "#{tag[0]} class='#{tag[1]}'"
|
64
|
-
tag_end = tag[0]
|
65
|
-
else
|
66
|
-
tag_beggining = tag
|
67
|
-
tag_end = tag
|
68
|
-
end
|
69
|
-
if tag
|
70
|
-
@text_to_render += "<#{tag_beggining}>"
|
71
|
-
yield
|
72
|
-
@text_to_render += "</#{tag_end}>"
|
73
|
-
else
|
74
|
-
yield
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def path_for link_to
|
79
|
-
if self.prefix
|
80
|
-
return "/#{self.prefix}/#{link_to.downcase}"
|
81
|
-
else
|
82
|
-
return "/#{link_to.downcase}"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def styling options
|
87
|
-
if options
|
88
|
-
return "<br>" if options[:styling] == :vertical
|
89
|
-
return options[:styling] if options[:styling]
|
90
|
-
end
|
91
|
-
" "
|
92
|
-
end
|
93
|
-
|
94
|
-
def ignoring k
|
95
|
-
[:styling,:wrap].include?(k)
|
96
|
-
end
|
6
|
+
module NavGate
|
97
7
|
|
8
|
+
class << self
|
9
|
+
attr_accessor :configuration
|
98
10
|
end
|
99
11
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
self.
|
104
|
-
route.defaults[:controller]
|
105
|
-
end.uniq.compact
|
106
|
-
yield(self)
|
107
|
-
raise TypeError, "Expected Navgate:Builder or string" unless not_bad_type?(self.navs)
|
108
|
-
if self.navs.is_a?(String)
|
109
|
-
setup = YAML.load_file(self.navs)
|
110
|
-
temp = []
|
111
|
-
setup.each do |menu|
|
112
|
-
temp.push(Navgate::Builder.new do |options|
|
113
|
-
options[:selection] = menu[1]['selection'].split(" ")
|
114
|
-
options[:default] = menu[1]['default'] || nill
|
115
|
-
options[:prefix] = menu[1]['prefix'] || nil
|
116
|
-
options[:controller] = menu[1]['controller'] || nil
|
117
|
-
options[:by_id] = menu[1]['by_id'] || nil
|
118
|
-
options[:css_class] = menu[1]['css_class'] || nil
|
119
|
-
end
|
120
|
-
)
|
121
|
-
end
|
122
|
-
self.navs = temp
|
123
|
-
end
|
124
|
-
self.ignoring ||= [""]
|
12
|
+
def self.configure
|
13
|
+
self.configuration ||= Configuration.new
|
14
|
+
yield(configuration)
|
15
|
+
self.configuration.post_setup
|
125
16
|
end
|
126
17
|
|
18
|
+
class Configuration
|
19
|
+
attr_accessor :controllers, :navs, :ignoring
|
127
20
|
|
21
|
+
def initialize
|
22
|
+
self.controllers = Rails.application.routes.routes.map do |route|
|
23
|
+
route.defaults[:controller]
|
24
|
+
end.uniq.compact
|
128
25
|
|
129
|
-
|
130
|
-
|
131
|
-
def select selection, controller
|
132
|
-
split_controller = controller.split('/').last
|
133
|
-
if selection
|
134
|
-
selection
|
135
|
-
else
|
136
|
-
if ignoring.include?(split_controller)
|
137
|
-
nil
|
138
|
-
else
|
139
|
-
nav_cache(split_controller).default.to_s
|
140
|
-
end
|
141
26
|
end
|
142
|
-
end
|
143
27
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
28
|
+
def post_setup
|
29
|
+
raise TypeError, "Expected Navgate:Builder or string" unless not_bad_type?(self.navs)
|
30
|
+
if self.navs.is_a?(String)
|
31
|
+
setup = YAML.load_file(self.navs)
|
32
|
+
temp = []
|
33
|
+
setup.each do |menu|
|
34
|
+
temp.push(Navgate::Builder.new do |options|
|
35
|
+
options[:selection] = menu[1]['selection'].split(" ")
|
36
|
+
options[:default] = menu[1]['default'] || nill
|
37
|
+
options[:prefix] = menu[1]['prefix'] || nil
|
38
|
+
options[:controller] = menu[1]['controller'] || nil
|
39
|
+
options[:by_id] = menu[1]['by_id'] || nil
|
40
|
+
options[:css_class] = menu[1]['css_class'] || nil
|
41
|
+
end
|
42
|
+
)
|
43
|
+
end
|
44
|
+
self.navs = temp
|
45
|
+
end
|
46
|
+
self.ignoring ||= [""]
|
151
47
|
end
|
152
|
-
end
|
153
48
|
|
154
|
-
|
49
|
+
private
|
155
50
|
|
156
|
-
|
157
|
-
|
158
|
-
if @selected_nav.controller.is_a?(Array)
|
159
|
-
return @selected_nav if @selected_nav.controller.include?(controller)
|
160
|
-
else
|
161
|
-
return @selected_nav unless @selected_nav.controller != controller
|
162
|
-
end
|
163
|
-
@selected_nav = nil
|
164
|
-
nav_cache(controller)
|
165
|
-
else
|
166
|
-
@selected_nav ||= select_nav(controller)
|
51
|
+
def not_bad_type? navs
|
52
|
+
navs.is_a?(String) || navs.map{ |n| n.is_a?(NavGate::Builder)}.any?
|
167
53
|
end
|
168
|
-
end
|
169
54
|
|
170
|
-
|
171
|
-
|
172
|
-
self.navs.each do |nav|
|
173
|
-
if nav.controller.is_a?(String)
|
174
|
-
nav_to_return = nav if (nav.controller) == controller
|
175
|
-
elsif nav.controller.is_a?(Array)
|
176
|
-
nav_to_return = nav if nav.controller.include?(controller)
|
177
|
-
else
|
178
|
-
raise TypeError, "expecting nav.controller to be a String or an Array, got #{nav.controller.class} "
|
179
|
-
end
|
180
|
-
end
|
181
|
-
nav_to_return ? (return nav_to_return) : (raise ArgumentError, "No matching controllers for #{controller}")
|
182
|
-
end
|
55
|
+
end
|
56
|
+
|
183
57
|
|
184
|
-
def not_bad_type? navs
|
185
|
-
navs.is_a?(String) || navs.map{ |n| n.is_a?(Navgate::Builder)}.any?
|
186
|
-
end
|
187
58
|
end
|
data/lib/navgate/base.rb
CHANGED
@@ -1,32 +1,33 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module NavGate
|
2
|
+
class Base
|
3
|
+
attr_accessor :selection, :default, :prefix, :controller, :by_id, :css_class, :css_selected
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
5
|
+
def initialize(&block)
|
6
|
+
options = {selection: nil,default: nil, controller: nil, css_class: nil, css_selected: nil}
|
7
|
+
yield(options)
|
8
|
+
self.selection = pull_data(options[:selection])
|
9
|
+
self.default = options[:default] || self.selection.first
|
10
|
+
self.prefix = options[:prefix]
|
11
|
+
self.controller = options[:controller]
|
12
|
+
self.by_id = pull_data({options[:selection].to_a.first.first => :id }) if options[:by_id]
|
13
|
+
self.css_class = options[:css_class]
|
14
|
+
self.css_selected = options[:css_selected]
|
15
|
+
end
|
16
|
+
private
|
17
|
+
def pull_data selection
|
18
|
+
if selection.is_a?(Array)
|
19
|
+
output = selection
|
20
|
+
elsif selection.is_a?(Hash)
|
21
|
+
output = []
|
22
|
+
selection.each do |key,value|
|
23
|
+
key.to_s.singularize.classify.constantize.all.each do |item|
|
24
|
+
output.push(item.send(value))
|
25
|
+
end
|
24
26
|
end
|
27
|
+
else
|
28
|
+
raise TypeError, " Selection was a #{selection.class}, expecting a (Array,Hash)"
|
25
29
|
end
|
26
|
-
|
27
|
-
raise TypeError, " Selection was a #{selection.class}, expecting a (Array,Hash)"
|
30
|
+
output
|
28
31
|
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
+
end
|
32
33
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module NavGate
|
2
|
+
class Builder < Base
|
3
|
+
|
4
|
+
def render_it_with(options,selected)
|
5
|
+
options_to_render = ""
|
6
|
+
if self.css_class
|
7
|
+
if options && options[:class]
|
8
|
+
options[:class] = self.css_class
|
9
|
+
else
|
10
|
+
options = { class: self.css_class}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
if options
|
14
|
+
options.each do |key,value|
|
15
|
+
options_to_render += ("#{key}='#{value}'" + " ") unless ignoring key
|
16
|
+
end
|
17
|
+
end
|
18
|
+
style = styling(options)
|
19
|
+
@text_to_render = ""
|
20
|
+
selected.gsub!('/',"")
|
21
|
+
if !self.by_id
|
22
|
+
self.selection.each do |select|
|
23
|
+
@text_to_render += select_text_for(select,selected,options[:wrap],options_to_render,style)
|
24
|
+
end
|
25
|
+
else
|
26
|
+
self.selection.each_with_index do |select,i|
|
27
|
+
@text_to_render += select_text_for(select,selected,options[:wrap],options_to_render,style,i)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
@text_to_render
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def select_text_for select, selected, wrap, options_to_render, style, id=nil
|
35
|
+
return_temp = ""
|
36
|
+
wrap_with(wrap) do
|
37
|
+
if select != id && select != selected
|
38
|
+
return_temp = generate_text(select,options_to_render,style,id)
|
39
|
+
else
|
40
|
+
if self.css_selected
|
41
|
+
if options_to_render =~ /class='.*'/
|
42
|
+
temp = options_to_render.gsub(/class='.*'/,"class='#{self.css_selected}'")
|
43
|
+
return_temp = generate_text(select,temp,style,id)
|
44
|
+
else
|
45
|
+
temp = options_to_render + "class='#{self.css_selected}'"
|
46
|
+
return_temp = generate_text(select,temp,style,id)
|
47
|
+
end#select which version to use
|
48
|
+
else
|
49
|
+
return_temp = ""
|
50
|
+
end #render nothing or css_selected
|
51
|
+
end #for select if
|
52
|
+
end #for wrap method
|
53
|
+
return_temp
|
54
|
+
end #for method
|
55
|
+
def generate_text(select,options_to_render,style,id = nil)
|
56
|
+
"<a href=\"#{path_for(id || select)}\" #{options_to_render}>#{select.gsub('_'," ")}</a>#{style}"
|
57
|
+
end
|
58
|
+
def wrap_with tag, &block
|
59
|
+
if tag.is_a?(Array)
|
60
|
+
tag_beggining = "#{tag[0]} class='#{tag[1]}'"
|
61
|
+
tag_end = tag[0]
|
62
|
+
else
|
63
|
+
tag_beggining = tag
|
64
|
+
tag_end = tag
|
65
|
+
end
|
66
|
+
if tag
|
67
|
+
@text_to_render += "<#{tag_beggining}>"
|
68
|
+
yield
|
69
|
+
@text_to_render += "</#{tag_end}>"
|
70
|
+
else
|
71
|
+
yield
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def path_for link_to
|
76
|
+
if self.prefix
|
77
|
+
return "/#{self.prefix}/#{link_to.downcase}"
|
78
|
+
else
|
79
|
+
return "/#{link_to.downcase}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def styling options
|
84
|
+
if options
|
85
|
+
return "<br>" if options[:styling] == :vertical
|
86
|
+
return options[:styling] if options[:styling]
|
87
|
+
end
|
88
|
+
" "
|
89
|
+
end
|
90
|
+
|
91
|
+
def ignoring k
|
92
|
+
[:styling,:wrap].include?(k)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
data/lib/navgate/main.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module NavGate
|
2
|
+
class Navigation
|
3
|
+
def self.select selection, controller
|
4
|
+
split_controller = controller.split('/').last
|
5
|
+
if selection
|
6
|
+
selection
|
7
|
+
else
|
8
|
+
if config.ignoring.include?(split_controller)
|
9
|
+
nil
|
10
|
+
else
|
11
|
+
nav_cache(split_controller).default.to_s
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.render_nav selection, controller, options
|
17
|
+
split_controller = controller.split('/').last
|
18
|
+
if config.ignoring.include?(split_controller)
|
19
|
+
nil
|
20
|
+
else
|
21
|
+
nav = nav_cache(split_controller).render_it_with(options,selection).html_safe
|
22
|
+
nav
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def self.config
|
29
|
+
NavGate.configuration
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.nav_cache controller
|
33
|
+
if @selected_nav
|
34
|
+
if @selected_nav.controller.is_a?(Array)
|
35
|
+
return @selected_nav if @selected_nav.controller.include?(controller)
|
36
|
+
else
|
37
|
+
return @selected_nav unless @selected_nav.controller != controller
|
38
|
+
end
|
39
|
+
@selected_nav = nil
|
40
|
+
nav_cache(controller)
|
41
|
+
else
|
42
|
+
@selected_nav ||= select_nav(controller)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.select_nav controller
|
47
|
+
nav_to_return = nil
|
48
|
+
config.navs.each do |nav|
|
49
|
+
if nav.controller.is_a?(String)
|
50
|
+
nav_to_return = nav if (nav.controller) == controller
|
51
|
+
elsif nav.controller.is_a?(Array)
|
52
|
+
nav_to_return = nav if nav.controller.include?(controller)
|
53
|
+
else
|
54
|
+
raise TypeError, "expecting nav.controller to be a String or an Array, got #{nav.controller.class} "
|
55
|
+
end
|
56
|
+
end
|
57
|
+
nav_to_return ? (return nav_to_return) : (raise ArgumentError, "No matching controllers for #{controller}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module NavGate
|
2
|
+
module NavGateHelpers
|
3
|
+
def NavGateHelpers.included(mod)
|
4
|
+
if Module.const_get("Rails").is_a?(Module).inspect
|
5
|
+
#with rails
|
6
|
+
def make_menu
|
7
|
+
@navgate = NavGate::Navigation
|
8
|
+
@selected ||= @navgate.select(params[:selection], params[:controller])
|
9
|
+
end
|
10
|
+
def render_navigation options = nil
|
11
|
+
@navgate.render_nav((params[:selection]||request.fullpath), params[:controller], options )
|
12
|
+
end
|
13
|
+
else
|
14
|
+
#without rails
|
15
|
+
def make_menu selection, controller
|
16
|
+
@navgate = NavGate::Navigation
|
17
|
+
@selected ||= @navgate.select(selection, controller)
|
18
|
+
end
|
19
|
+
def render_navigation controller, options = nil
|
20
|
+
@navgate.render_nav( @selected , controller, options )
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/navGATE.gemspec
CHANGED
@@ -2,20 +2,19 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "navGATE"
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.30"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Martin Becker"]
|
9
|
-
s.date = "
|
9
|
+
s.date = "2014-01-13"
|
10
10
|
s.description = "Can create navigation from objects using the nav builder,from database tables or from a yaml file"
|
11
11
|
s.email = "mbeckerwork@gmail.com"
|
12
|
-
s.extra_rdoc_files = ["lib/navgate.rb", "lib/navgate/base.rb", "lib/navgate/navgatehelpers.rb", "lib/readme.rdoc"]
|
13
|
-
s.files = ["LICENCE/GPL-2", "Manifest", "Rakefile", "config/build_menu.yml", "config/initializers/build_menu.rb", "init.rb", "lib/navgate.rb", "lib/navgate/base.rb", "lib/navgate/navgatehelpers.rb", "lib/readme.rdoc", "navGATE.gemspec", "readme.rdoc"]
|
12
|
+
s.extra_rdoc_files = ["lib/navgate.rb", "lib/navgate/base.rb", "lib/navgate/builder.rb", "lib/navgate/main.rb", "lib/navgate/modules/navgatehelpers.rb", "lib/readme.rdoc"]
|
13
|
+
s.files = ["LICENCE/GPL-2", "Manifest", "Rakefile", "config/build_menu.yml", "config/initializers/build_menu.rb", "init.rb", "lib/navgate.rb", "lib/navgate/base.rb", "lib/navgate/builder.rb", "lib/navgate/main.rb", "lib/navgate/modules/navgatehelpers.rb", "lib/readme.rdoc", "navGATE.gemspec", "readme.rdoc"]
|
14
14
|
s.homepage = "https://github.com/Thermatix/navGATE"
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "navGATE", "--main", "readme.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = "navgate"
|
18
18
|
s.rubygems_version = "2.0.6"
|
19
19
|
s.summary = "Allows the easy creation of navigation with config files"
|
20
|
-
s.license = 'GLP-2'
|
21
20
|
end
|
data/readme.rdoc
CHANGED
@@ -12,7 +12,7 @@ This gem was built with Rails in mind.
|
|
12
12
|
lastly the gem is up on rubygems.org
|
13
13
|
|
14
14
|
==Setup
|
15
|
-
in the Application controller you have to <tt> include NavGateHelpers </tt> first.
|
15
|
+
in the Application controller you have to <tt> include NavGate::NavGateHelpers </tt> first.
|
16
16
|
|
17
17
|
===For Rails
|
18
18
|
You next have to add a before_filter and helper method to the application controller
|
@@ -38,7 +38,7 @@ When building the menu there are multiple options available, building the menu i
|
|
38
38
|
|
39
39
|
There are several options you can pass through, if you are building the menu with the object builder directly then two options must be present, those being 'selection' and 'controller', the rest are optional.
|
40
40
|
|
41
|
-
Also note, you can pass multiple
|
41
|
+
Also note, you can pass multiple <tt> NavGate::builders </tt> as you need, just match them to there controllers and they should render properly.
|
42
42
|
===Options
|
43
43
|
|
44
44
|
<b>selection</b>: This is used to build the menu options.
|
@@ -60,8 +60,8 @@ examples:
|
|
60
60
|
|
61
61
|
===Building menu object from scratch
|
62
62
|
The default option doesn't have to be the first in the selection list.
|
63
|
-
|
64
|
-
build.navs = [
|
63
|
+
NavGate.configure do |build|
|
64
|
+
build.navs = [ NavGate::Builder.new do |options|
|
65
65
|
options[:selection] = %w(selection site_settings users images misc)
|
66
66
|
options[:default] = 'users'
|
67
67
|
options[:prefix] = = 'admin'
|
@@ -75,8 +75,8 @@ The default option doesn't have to be the first in the selection list.
|
|
75
75
|
Be sure to pass it as {model_name: :field}.
|
76
76
|
Also note you can pass an array of controllers as well as just a string of one controller which in this case is done via a split command, %w() also works
|
77
77
|
|
78
|
-
|
79
|
-
build.navs = [
|
78
|
+
NavGate.configure do |build|
|
79
|
+
build.navs = [ NavGate::Builder.new do |options|
|
80
80
|
options[:selection] = {categories: :title }
|
81
81
|
options[:prefix] = 'shop_category'
|
82
82
|
options[:controller] = "front_page side_page about_page".split(" ")
|
@@ -86,16 +86,16 @@ Also note you can pass an array of controllers as well as just a string of one c
|
|
86
86
|
end
|
87
87
|
===Building multiple menus
|
88
88
|
|
89
|
-
|
89
|
+
NavGate.configure do |build|
|
90
90
|
build.navs = [
|
91
|
-
|
91
|
+
NavGate::Builder.new do |options|
|
92
92
|
options[:selection] = %w(selection site_settings users images misc)
|
93
93
|
options[:default] = 'users'
|
94
94
|
options[:prefix] = = 'admin'
|
95
95
|
options[:controller] = 'admin_panel'
|
96
96
|
options[:css_class] = 'nav button'
|
97
97
|
end,
|
98
|
-
|
98
|
+
NavGate::Builder.new do |options|
|
99
99
|
options[:selection] = %w(welcome about_us gallery news)
|
100
100
|
options[:default] = 'news'
|
101
101
|
options[:controller] = 'front_page'
|
@@ -110,9 +110,10 @@ when using this method you are unable to use a database model to create the menu
|
|
110
110
|
|
111
111
|
===Building from yaml file,
|
112
112
|
Initializing the object:
|
113
|
-
|
113
|
+
NavGate.configure do |build|
|
114
114
|
build.navs = "#{Rails.root}/config/build_menu.yml"
|
115
115
|
end
|
116
|
+
|
116
117
|
The yaml file:
|
117
118
|
nav_1:
|
118
119
|
selection: welcome about_us gallery
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: navGATE
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.30
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Becker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Can create navigation from objects using the nav builder,from database
|
14
14
|
tables or from a yaml file
|
@@ -18,7 +18,9 @@ extensions: []
|
|
18
18
|
extra_rdoc_files:
|
19
19
|
- lib/navgate.rb
|
20
20
|
- lib/navgate/base.rb
|
21
|
-
- lib/navgate/
|
21
|
+
- lib/navgate/builder.rb
|
22
|
+
- lib/navgate/main.rb
|
23
|
+
- lib/navgate/modules/navgatehelpers.rb
|
22
24
|
- lib/readme.rdoc
|
23
25
|
files:
|
24
26
|
- LICENCE/GPL-2
|
@@ -29,13 +31,14 @@ files:
|
|
29
31
|
- init.rb
|
30
32
|
- lib/navgate.rb
|
31
33
|
- lib/navgate/base.rb
|
32
|
-
- lib/navgate/
|
34
|
+
- lib/navgate/builder.rb
|
35
|
+
- lib/navgate/main.rb
|
36
|
+
- lib/navgate/modules/navgatehelpers.rb
|
33
37
|
- lib/readme.rdoc
|
34
38
|
- navGATE.gemspec
|
35
39
|
- readme.rdoc
|
36
40
|
homepage: https://github.com/Thermatix/navGATE
|
37
|
-
licenses:
|
38
|
-
- GLP-2
|
41
|
+
licenses: []
|
39
42
|
metadata: {}
|
40
43
|
post_install_message:
|
41
44
|
rdoc_options:
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module NavGateHelpers
|
2
|
-
def NavGateHelpers.included(mod)
|
3
|
-
if Module.const_get("Rails").is_a?(Module).inspect
|
4
|
-
#with rails
|
5
|
-
def make_menu
|
6
|
-
@navgate = NAVGATE
|
7
|
-
@selected ||= @navgate.select(params[:selection], params[:controller])
|
8
|
-
end
|
9
|
-
def render_navigation options = nil
|
10
|
-
@navgate.render_nav((params[:selection]||request.fullpath), params[:controller], options )
|
11
|
-
end
|
12
|
-
else
|
13
|
-
#without rails
|
14
|
-
def make_menu selection, controller
|
15
|
-
@navgate = NAVGATE
|
16
|
-
@selected ||= @navgate.select(selection, controller)
|
17
|
-
end
|
18
|
-
def render_navigation controller, options = nil
|
19
|
-
@navgate.render_nav( @selected , controller, options )
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|