navGATE 0.1.18 → 0.1.21
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.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/navgate.rb +46 -22
- data/lib/navgate/base.rb +3 -2
- data/lib/navgate/navgatehelpers.rb +20 -7
- data/lib/readme.rdoc +17 -4
- data/navGATE.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 291c99018a5fa97fdca58d16a220a62ef9452d03
|
4
|
+
data.tar.gz: 3a417976c1eddccef98e4b3c68957a2be0867965
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ca2989830edca020ee92519616d9cb73f90bd34a3aab6fce4fcbe307d190746e43c28d5caa63a10612a34a8b7dd1b6aac4b3de055df04ee98ac8661e477469f
|
7
|
+
data.tar.gz: a0b04ce2a4a6c03aad7959013e072ad6e1f1c45f00babbf095cb75a459b1141c5b842f093ba37e4460a2197092cf7b5b17c6ef22a08100d18c5b680cace73e00
|
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.21') 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
@@ -3,35 +3,60 @@ require 'navgate/navgatehelpers'
|
|
3
3
|
class Navgate
|
4
4
|
class Builder < Base
|
5
5
|
|
6
|
-
def render_it_with(options)
|
6
|
+
def render_it_with(options,selected)
|
7
7
|
options_to_render = ""
|
8
|
-
|
8
|
+
if self.css_class
|
9
|
+
if options && options[:class]
|
10
|
+
options[:class] = self.css_class
|
11
|
+
else
|
12
|
+
options = { class: self.css_class}
|
13
|
+
end
|
14
|
+
end
|
9
15
|
if options
|
10
16
|
options.each do |key,value|
|
11
|
-
options_to_render += ("#{key}
|
17
|
+
options_to_render += ("#{key}='#{value}'" + " ") unless ignoring key
|
12
18
|
end
|
13
19
|
end
|
14
20
|
style = styling(options)
|
15
21
|
@text_to_render = ""
|
22
|
+
selected.gsub!('/',"")
|
16
23
|
if !self.by_id
|
17
24
|
self.selection.each do |select|
|
18
|
-
|
19
|
-
@text_to_render += "<a href=\"#{path_for(select)}\" #{options_to_render}>#{select.gsub('_'," ")}</a>#{style}"
|
20
|
-
end
|
25
|
+
@text_to_render += select_text_for(select,selected,options[:wrap],options_to_render,style)
|
21
26
|
end
|
22
27
|
else
|
23
28
|
self.selection.each_with_index do |select,i|
|
24
|
-
|
25
|
-
@text_to_render += "<a href=\"#{path_for(self.by_id[i])}\" #{options_to_render}>#{select.gsub('_'," ")}</a>#{style}"
|
26
|
-
end
|
29
|
+
@text_to_render += select_text_for(select,selected,options[:wrap],options_to_render,style,i)
|
27
30
|
end
|
28
31
|
end
|
29
32
|
@text_to_render
|
30
33
|
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
35
|
private
|
36
|
+
def select_text_for select, selected, wrap, options_to_render, style, id=nil
|
37
|
+
return_temp = ""
|
38
|
+
wrap_with(wrap) do
|
39
|
+
if select != id && select != selected
|
40
|
+
return_temp = generate_text(select,options_to_render,style,id)
|
41
|
+
else
|
42
|
+
if self.css_selected
|
43
|
+
if options_to_render =~ /class='.*'/
|
44
|
+
temp = options_to_render.gsub(/class='.*'/,"class='#{self.css_selected}'")
|
45
|
+
return_temp = generate_text(select,temp,style,id)
|
46
|
+
else
|
47
|
+
temp = options_to_render + "class='#{self.css_selected}'"
|
48
|
+
return_temp = generate_text(select,temp,style,id)
|
49
|
+
end#select which version to use
|
50
|
+
else
|
51
|
+
return_temp = ""
|
52
|
+
end #render nothing or css_selected
|
53
|
+
end #for select if
|
54
|
+
end #for wrap method
|
55
|
+
return_temp
|
56
|
+
end #for method
|
57
|
+
def generate_text(select,options_to_render,style,id = nil)
|
58
|
+
"<a href=\"#{path_for(id || select)}\" #{options_to_render}>#{select.gsub('_'," ")}</a>#{style}"
|
59
|
+
end
|
35
60
|
def wrap_with tag, &block
|
36
61
|
if tag.is_a?(Array)
|
37
62
|
tag_beggining = "#{tag[0]} class='#{tag[1]}'"
|
@@ -51,9 +76,9 @@ class Navgate
|
|
51
76
|
|
52
77
|
def path_for link_to
|
53
78
|
if self.prefix
|
54
|
-
return "/#{self.prefix}/#{link_to}"
|
79
|
+
return "/#{self.prefix}/#{link_to.downcase}"
|
55
80
|
else
|
56
|
-
return "/#{link_to}"
|
81
|
+
return "/#{link_to.downcase}"
|
57
82
|
end
|
58
83
|
end
|
59
84
|
|
@@ -99,25 +124,23 @@ class Navgate
|
|
99
124
|
|
100
125
|
|
101
126
|
|
102
|
-
def render_nav
|
103
|
-
nav = select_nav(
|
104
|
-
ap nav.inspect
|
127
|
+
def render_nav selection, controller, options
|
128
|
+
nav = select_nav(controller.split('/').last).render_it_with(options,selection).html_safe
|
105
129
|
nav
|
106
130
|
end
|
107
131
|
|
108
|
-
def select
|
109
|
-
|
110
|
-
|
111
|
-
return params[:selection]
|
132
|
+
def select selection, controller
|
133
|
+
if selection
|
134
|
+
return selection
|
112
135
|
else
|
113
|
-
|
136
|
+
|
137
|
+
return select_nav(controller).default.to_s
|
114
138
|
end
|
115
139
|
end
|
116
140
|
private
|
117
141
|
def select_nav controller
|
118
142
|
self.navs.each do |nav|
|
119
143
|
if nav.controller.is_a?(String)
|
120
|
-
ap nav.inspect
|
121
144
|
return nav if (nav.controller) == controller.split('/').last
|
122
145
|
elsif nav.controller.is_a?(Array)
|
123
146
|
return nav if nav.controller.include?(controller)
|
@@ -125,6 +148,7 @@ class Navgate
|
|
125
148
|
raise TypeError, "expecting nav.controller to be a String or an Array, got #{nav.controller.class} "
|
126
149
|
end
|
127
150
|
end
|
151
|
+
raise ArgumentError, "No matching controllers for #{controller}"
|
128
152
|
end
|
129
153
|
|
130
154
|
def not_bad_type? navs
|
data/lib/navgate/base.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class Base
|
2
|
-
attr_accessor :selection, :default, :prefix, :controller, :by_id, :css_class
|
2
|
+
attr_accessor :selection, :default, :prefix, :controller, :by_id, :css_class, :css_selected
|
3
3
|
|
4
4
|
def initialize(&block)
|
5
|
-
options = {selection: nil,default: nil, controller: nil, css_class: nil}
|
5
|
+
options = {selection: nil,default: nil, controller: nil, css_class: nil, css_selected: nil}
|
6
6
|
yield(options)
|
7
7
|
self.selection = pull_data(options[:selection])
|
8
8
|
self.default = options[:default] || self.selection.first
|
@@ -10,6 +10,7 @@ class Base
|
|
10
10
|
self.controller = options[:controller]
|
11
11
|
self.by_id = pull_data({options[:selection].to_a.first.first => :id }) if options[:by_id]
|
12
12
|
self.css_class = options[:css_class]
|
13
|
+
self.css_selected = options[:css_selected]
|
13
14
|
end
|
14
15
|
private
|
15
16
|
def pull_data selection
|
@@ -1,11 +1,24 @@
|
|
1
1
|
module NavGateHelpers
|
2
|
-
def
|
3
|
-
|
4
|
-
|
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
|
5
22
|
end
|
6
|
-
def render_navigation options = nil
|
7
|
-
@navgate.render_nav(params, options)
|
8
|
-
end
|
9
|
-
|
10
23
|
end
|
11
24
|
|
data/lib/readme.rdoc
CHANGED
@@ -12,16 +12,26 @@ note: this is my first gem.
|
|
12
12
|
|
13
13
|
lastly the gem is up on rubygems.org
|
14
14
|
|
15
|
-
==
|
15
|
+
==Setup
|
16
16
|
in the Application controller you have to <tt> include NavGateHelpers </tt> first.
|
17
17
|
|
18
|
+
===For Rails
|
18
19
|
You next have to add a before_filter and helper method to the application controller
|
19
20
|
|
20
|
-
|
21
|
+
Just add:
|
21
22
|
helper_method :render_navigation
|
22
23
|
before_filter :make_menu
|
23
24
|
|
24
|
-
|
25
|
+
To your list of filters and helper methods in the application controller, thats it, you can now use the helper method and the gem to build your navigations.
|
26
|
+
==For non Rails
|
27
|
+
For non rails version of NavGATE the helpers change, instead they work like so:
|
28
|
+
|
29
|
+
make_menu(selection, controller)
|
30
|
+
|
31
|
+
render_navigation(selection, controller, options = nil)
|
32
|
+
|
33
|
+
You have to pass the controller (or page it matches) and the current selection,
|
34
|
+
in rails they would pass automatically as <tt> params[:controller] </tt> and <tt> params[:selection] </tt> respecivly (selection being the currenty selected nav item).
|
25
35
|
|
26
36
|
==Building the menus
|
27
37
|
|
@@ -43,7 +53,9 @@ There are two ways to use this, the first is to use an array of strings containi
|
|
43
53
|
|
44
54
|
<b>by_id</b>: This is used when you are using a database model to build the menu and you want to link with IDs rather then the selection list. To use it simply set it to true.
|
45
55
|
|
46
|
-
<b>css_class</b>: This is used when you want to hard code the CSS class selector into the menu rather then from the view
|
56
|
+
<b>css_class</b>: This is used when you want to hard code the CSS class selector into the menu rather then from the view.
|
57
|
+
|
58
|
+
<b>css_selected</b>: the css overide for the selected thats currently selected. if no overide is passed then the link is simply not rendered out, as with css_class it overides the one passed in the view, but only for the selected link
|
47
59
|
|
48
60
|
examples:
|
49
61
|
|
@@ -157,3 +169,4 @@ resulting url
|
|
157
169
|
routes to the root but the paritals rendered would be respectively
|
158
170
|
_books.html.erb
|
159
171
|
_games.html.erb
|
172
|
+
|
data/navGATE.gemspec
CHANGED