navGATE 0.1.18 → 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63ca97abca52aba21054660fff6be9290fc01ed6
4
- data.tar.gz: 01d56b71610b89892c59aa85a9d9323c61342c94
3
+ metadata.gz: 291c99018a5fa97fdca58d16a220a62ef9452d03
4
+ data.tar.gz: 3a417976c1eddccef98e4b3c68957a2be0867965
5
5
  SHA512:
6
- metadata.gz: 1534caaf5ef23e63fae080d8d0a2d6fb5c3a67e1fec161441bc0811422724f2a4dd8e1f1e8d4473c4cc79d6db2cb351408763ec05277ae058b427fa8a9b86d23
7
- data.tar.gz: d473eead02eb00d376cd475a2172e18220cf0a708717ff0bbfca9e0c9e82499f2745607d39ea0306e5e34c1c9860a98cb6c79a22b3971a16dd787df6f858c124
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.18') do |p|
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
- options[:class] = "'#{self.css_class}'" if self.css_class
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}=#{value}" + " ") unless ignoring 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
- wrap_with options[:wrap] do
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
- wrap_with options[:wrap] do
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 params, options
103
- nav = select_nav(params[:controller].split('/').last).render_it_with(options).html_safe
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 params
109
-
110
- if params[:selection]
111
- return params[:selection]
132
+ def select selection, controller
133
+ if selection
134
+ return selection
112
135
  else
113
- return select_nav(params[:controller]).default.to_s
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 make_menu
3
- @navgate = NAVGATE
4
- @selected ||= @navgate.select(params)
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
- ==setup
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
- just add
21
+ Just add:
21
22
  helper_method :render_navigation
22
23
  before_filter :make_menu
23
24
 
24
- 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 the navigations
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "navGATE"
5
- s.version = "0.1.18"
5
+ s.version = "0.1.21"
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"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navGATE
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Becker