navGATE 0.1.3.3 → 0.1.04
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest +2 -5
- data/Rakefile +2 -3
- data/app/controller/application_controller.rb +9 -0
- data/app/helpers/application_helper.rb +5 -0
- data/config/initializers/build_menu.rb +24 -24
- data/init.rb +1 -1
- data/lib/navgate.rb +103 -41
- data/lib/navgate/base.rb +30 -27
- data/navGATE.gemspec +6 -6
- data/readme.rdoc +29 -101
- metadata +6 -14
- data/LICENCE/GPL-2 +0 -342
- data/lib/navgate/builder.rb +0 -96
- data/lib/navgate/main.rb +0 -60
- data/lib/navgate/modules/navgatehelpers.rb +0 -26
- data/lib/readme.rdoc +0 -174
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c71af2c06a9d676bb6af15bc21b23895f64fa335
|
4
|
+
data.tar.gz: 733d11cd02ca5133b24d89ce994c026d7ffcc10a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fadaabfeced76f4ac4f4b4d01d9e540fcfab063f8d32f42564a5b0a54df0eb0ee5910494a7e1bf865052728bd7120ce1963c805e1a9501524dc5097201c2b787
|
7
|
+
data.tar.gz: b379cf0cbb8d44dcfbb4d709cf0ccfe29b72bdcfe8e379032fd200114f155bce580a5a0208dcb53c3f9d9f880bac22456375fd49d0b1411e5de0f2df7462c134
|
data/Manifest
CHANGED
@@ -1,14 +1,11 @@
|
|
1
|
-
LICENCE/GPL-2
|
2
1
|
Manifest
|
3
2
|
Rakefile
|
3
|
+
app/controller/application_controller.rb
|
4
|
+
app/helpers/application_helper.rb
|
4
5
|
config/build_menu.yml
|
5
6
|
config/initializers/build_menu.rb
|
6
7
|
init.rb
|
7
8
|
lib/navgate.rb
|
8
9
|
lib/navgate/base.rb
|
9
|
-
lib/navgate/builder.rb
|
10
|
-
lib/navgate/main.rb
|
11
|
-
lib/navgate/modules/navgatehelpers.rb
|
12
|
-
lib/readme.rdoc
|
13
10
|
navGATE.gemspec
|
14
11
|
readme.rdoc
|
data/Rakefile
CHANGED
@@ -3,9 +3,8 @@ require 'rake'
|
|
3
3
|
require 'echoe'
|
4
4
|
|
5
5
|
|
6
|
-
Echoe.new('navGATE','0.1.
|
7
|
-
p.
|
8
|
-
p.description = "Can create navigation from objects using the nav builder,from database tables or from a yaml file"
|
6
|
+
Echoe.new('navGATE','0.1.04') do |p|
|
7
|
+
p.description = "Allows the easy creation of menus with config files"
|
9
8
|
p.url = "https://github.com/Thermatix/navGATE"
|
10
9
|
p.author = "Martin Becker"
|
11
10
|
p.email = "mbeckerwork@gmail.com"
|
@@ -1,26 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
require 'navgate'
|
2
|
+
building menu object from scratch
|
3
|
+
NAVGATE = Navgate.new do |build|
|
4
|
+
build.navs = [ Navgate::Builder.new do |options|
|
5
|
+
options[:selection] = %w(selection site_settings users images misc)
|
6
|
+
options[:namespace] = 'admin'
|
7
|
+
options[:controller] = 'admin_panel'
|
8
|
+
end
|
9
|
+
]
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
building menu object from database fields be sure to pass it as {Model_name: field}
|
13
|
+
NAVGATE = Navgate.new do |build|
|
14
|
+
build.navs = [ Navgate::Builder.new do |options|
|
15
|
+
options[:selection] = {categories: :title }
|
16
|
+
options[:prefix] = 'shop_category'
|
17
|
+
options[:controller] = 'front_page'
|
18
|
+
options[:by_id] = true
|
19
|
+
end
|
20
|
+
]
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
building from yaml file, look through the yaml file for an example
|
24
|
+
NAVGATE = Navgate.new do |build|
|
25
|
+
build.navs = "#{Rails.root}/config/build_menu.yml"
|
26
|
+
end
|
data/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require '
|
1
|
+
require 'navgate'
|
data/lib/navgate.rb
CHANGED
@@ -1,58 +1,120 @@
|
|
1
|
-
Dir[File.dirname(__FILE__) + '/navgate/modules/*.rb'].each {|file| require file }
|
2
1
|
require 'navgate/base'
|
3
|
-
|
4
|
-
|
2
|
+
class Navgate
|
3
|
+
class Builder < Base
|
5
4
|
|
6
|
-
|
5
|
+
def render_it_with(options)
|
6
|
+
options_to_render = ""
|
7
|
+
if options
|
8
|
+
options.each do |key,value|
|
9
|
+
options_to_render += ("#{key}=#{value}" + " ") unless ignoring key
|
10
|
+
options_to_render += ("class='#{self.css_class}") if self.css_class
|
11
|
+
end
|
12
|
+
end
|
13
|
+
style = styling(options)
|
14
|
+
@text_to_render = ""
|
15
|
+
if !self.by_id
|
16
|
+
self.selection.each do |select|
|
17
|
+
wrap_with options[:wrap] do
|
18
|
+
@text_to_render += "<a href=\"#{path_for(select)}\" #{options_to_render}>#{select.gsub('_'," ")}</a>#{style}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
else
|
22
|
+
self.selection.each_with_index do |select,i|
|
23
|
+
wrap_with options[:wrap] do
|
24
|
+
@text_to_render += "<a href=\"#{path_for(self.by_id[i])}\" #{options_to_render}>#{select.gsub('_'," ")}</a>#{style}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@text_to_render
|
29
|
+
end
|
7
30
|
|
8
|
-
class << self
|
9
|
-
attr_accessor :configuration
|
10
|
-
end
|
11
31
|
|
12
|
-
def self.configure
|
13
|
-
self.configuration ||= Configuration.new
|
14
|
-
yield(configuration)
|
15
|
-
self.configuration.post_setup
|
16
|
-
end
|
17
32
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
33
|
+
private
|
34
|
+
def wrap_with tag, &block
|
35
|
+
if tag.is_a?(Array)
|
36
|
+
tag_beggining = "#{tag[0]} class='#{tag[1]}'"
|
37
|
+
tag_end = tag[0]
|
38
|
+
else
|
39
|
+
tag_beggining = tag
|
40
|
+
tag_end = tag
|
41
|
+
end
|
42
|
+
if tag
|
43
|
+
@text_to_render += "<#{tag_beggining}>"
|
44
|
+
yield
|
45
|
+
@text_to_render += "</#{tag_end}>"
|
46
|
+
else
|
47
|
+
yield
|
48
|
+
end
|
49
|
+
end
|
25
50
|
|
26
|
-
|
51
|
+
def path_for link_to
|
52
|
+
if self.namespace
|
53
|
+
return "/#{self.namespace}/#{link_to}"
|
54
|
+
elsif self.prefix
|
55
|
+
return "/#{self.prefix}/#{link_to}"
|
56
|
+
else
|
57
|
+
return "/#{link_to}"
|
58
|
+
end
|
59
|
+
end
|
27
60
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
)
|
61
|
+
def styling options
|
62
|
+
if options
|
63
|
+
return "<br>" if options[:styling] == :verticle
|
64
|
+
return options[:styling] if options[:styling]
|
43
65
|
end
|
44
|
-
|
66
|
+
" "
|
45
67
|
end
|
46
|
-
self.ignoring ||= [""]
|
47
|
-
end
|
48
68
|
|
49
|
-
|
69
|
+
def ignoring k
|
70
|
+
[:styling,:wrap].include?(k) || ((k == "class") if self.css_class)
|
71
|
+
end
|
50
72
|
|
51
|
-
|
52
|
-
|
73
|
+
end
|
74
|
+
|
75
|
+
attr_accessor :controllers, :navs
|
76
|
+
|
77
|
+
def initialize
|
78
|
+
self.controllers = Rails.application.routes.routes.map do |route|
|
79
|
+
route.defaults[:controller]
|
80
|
+
end.uniq.compact
|
81
|
+
yield(self)
|
82
|
+
raise TypeError, "Expected Navgate:Builder or string" unless not_bad_type?(self.navs)
|
83
|
+
if self.navs.is_a?(String)
|
84
|
+
setup = YAML.load_file(self.navs)
|
85
|
+
temp = []
|
86
|
+
setup.each do |menu|
|
87
|
+
temp.push(Navgate::Builder.new do |options|
|
88
|
+
options[:selection] = menu[1]['selection'].split(" ")
|
89
|
+
options[:default] = menu[1]['default'] || nill
|
90
|
+
options[:namespace] = menu[1]['namespace'] || nil
|
91
|
+
options[:prefix] = menu[1]['prefix'] || nil
|
92
|
+
options[:controller] = menu[1]['controller'] || nil
|
93
|
+
end
|
94
|
+
)
|
53
95
|
end
|
96
|
+
self.navs = temp
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
54
100
|
|
101
|
+
|
102
|
+
def render_nav params, options
|
103
|
+
select_nav(params[:controller]).render_it_with(options).html_safe
|
55
104
|
end
|
56
105
|
|
106
|
+
def select params
|
107
|
+
nav = select_nav(params[:controller])
|
108
|
+
return params[:selection] ? params[:selection] : nav.default
|
109
|
+
end
|
110
|
+
private
|
111
|
+
def select_nav controller
|
112
|
+
self.navs.each do |nav|
|
113
|
+
return nav if nav.controller == controller
|
114
|
+
end
|
115
|
+
end
|
57
116
|
|
117
|
+
def not_bad_type? navs
|
118
|
+
navs.is_a?(String) || navs.map{ |n| n.is_a?(Navgate::Builder)}.any?
|
119
|
+
end
|
58
120
|
end
|
data/lib/navgate/base.rb
CHANGED
@@ -1,33 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
attr_accessor :selection, :default, :prefix, :controller, :by_id, :css_class, :css_selected
|
1
|
+
class Base
|
2
|
+
attr_accessor :selection, :default, :namespace, :controller, :prefix, :by_id, :css_class
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
def initialize(&block)
|
5
|
+
options = {selection: nil,default: nil, controller: nil, namespace: nil, css_class: nil}
|
6
|
+
yield(options)
|
7
|
+
self.selection = pull_data(options[:selection])
|
8
|
+
self.default = options[:default] || self.selection.first
|
9
|
+
self.namespace = options[:namespace]
|
10
|
+
self.prefix = options[:prefix]
|
11
|
+
self.controller = "#{namespace?}#{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
|
+
end
|
15
|
+
private
|
16
|
+
def namespace?
|
17
|
+
self.namespace ? "#{self.namespace}/" : ""
|
15
18
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
19
|
+
|
20
|
+
def pull_data selection
|
21
|
+
if selection.is_a?(Array)
|
22
|
+
output = selection
|
23
|
+
elsif selection.is_a?(Hash)
|
24
|
+
output = []
|
25
|
+
selection.each do |key,value|
|
26
|
+
key.to_s.singularize.classify.constantize.all.each do |item|
|
27
|
+
output.push(item.send(value))
|
26
28
|
end
|
27
|
-
else
|
28
|
-
raise TypeError, " Selection was a #{selection.class}, expecting a (Array,Hash)"
|
29
29
|
end
|
30
|
-
|
30
|
+
else
|
31
|
+
raise TypeError, " Selection was a #{selection.class}, expecting a (Array,Hash)"
|
31
32
|
end
|
32
|
-
|
33
|
+
output
|
34
|
+
end
|
35
|
+
|
33
36
|
end
|
data/navGATE.gemspec
CHANGED
@@ -2,19 +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.04"
|
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 = "
|
10
|
-
s.description = "
|
9
|
+
s.date = "2013-10-15"
|
10
|
+
s.description = "Allows the easy creation of menus with config files"
|
11
11
|
s.email = "mbeckerwork@gmail.com"
|
12
|
-
s.extra_rdoc_files = ["lib/navgate.rb", "lib/navgate/base.rb"
|
13
|
-
s.files = ["
|
12
|
+
s.extra_rdoc_files = ["lib/navgate.rb", "lib/navgate/base.rb"]
|
13
|
+
s.files = ["Manifest", "Rakefile", "app/controller/application_controller.rb", "app/helpers/application_helper.rb", "config/build_menu.yml", "config/initializers/build_menu.rb", "init.rb", "lib/navgate.rb", "lib/navgate/base.rb", "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
|
-
s.summary = "Allows the easy creation of
|
19
|
+
s.summary = "Allows the easy creation of menus with config files"
|
20
20
|
end
|
data/readme.rdoc
CHANGED
@@ -1,70 +1,46 @@
|
|
1
1
|
= navGATE
|
2
2
|
|
3
|
-
This gem is provided as is.
|
4
|
-
|
5
|
-
This gem allows for the ease of navigation building, from preset lists, from active model databases (eg, categories), from yaml files; but it's not just
|
6
|
-
for the ease of use it's also that you can have multiple navigation menus for differant controllers, or the same menu for differant controllers.
|
7
|
-
However you want it, it's up to you.
|
3
|
+
This gem is provided as is, please read through the intializer file "build_menu.rb" for examples on how you can use this gem to build a nav menu.
|
8
4
|
|
9
5
|
This gem was built with Rails in mind.
|
10
6
|
|
11
|
-
|
7
|
+
note: this is my first gem, I am still trying to set it up, so be carefull when downloading this.
|
8
|
+
Also I've included the extra files needed to get it working in there respective directories, eg, the code in 'Applicationhelper' needs to go in 'Applicationhelper'.
|
9
|
+
I've tried to to make it easy to install but I'm still not sure how to get those things into the right files automaticly, if some one could point me in the right direction, I'd be happy to make the needed changes.
|
12
10
|
lastly the gem is up on rubygems.org
|
13
|
-
|
14
|
-
==Setup
|
15
|
-
in the Application controller you have to <tt> include NavGate::NavGateHelpers </tt> first.
|
16
|
-
|
17
|
-
===For Rails
|
18
|
-
You next have to add a before_filter and helper method to the application controller
|
19
|
-
|
20
|
-
Just add:
|
21
|
-
helper_method :render_navigation
|
22
|
-
before_filter :make_menu
|
23
|
-
|
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 your navigations.
|
25
|
-
==For non Rails
|
26
|
-
For non rails version of NavGATE the helpers change, instead they work like so:
|
27
|
-
|
28
|
-
make_menu(selection, controller)
|
29
|
-
|
30
|
-
render_navigation(selection, controller, options = nil)
|
31
|
-
|
32
|
-
You have to pass the controller (or page it matches) and the current selection,
|
33
|
-
in rails they would pass automatically as <tt> params[:controller] </tt> and <tt> params[:selection] </tt> respectively (selection being the currently selected nav item).
|
34
|
-
|
35
11
|
==Building the menus
|
36
12
|
|
37
13
|
When building the menu there are multiple options available, building the menu is done in an initializer file in the configs directory.
|
38
14
|
|
39
15
|
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
16
|
|
41
|
-
Also note, you can pass multiple
|
17
|
+
Also note, you can pass multiple Navgate::builders as you need, just match them to there controllers and they should render properly.
|
42
18
|
===Options
|
43
19
|
|
44
|
-
|
20
|
+
selection: This is used to build the menu options.
|
45
21
|
There are two ways to use this, the first is to use an array of strings containing the menu options a person can select; the second is to pull from a database table, to do this pass a hash with the key being the name of the model and it's value being the field containing it's name
|
46
22
|
|
47
|
-
|
23
|
+
default: This is used to give the menu a default selection for when the user has not selected anything. Pass a string containing the name of the defualt selection, if no string is passed then the first item from selection is used.
|
48
24
|
|
49
|
-
|
25
|
+
prefix: This is used when you have a prefix before the target in the url, eg: if your links render out as "host.com/books" without a prefix; with a prefix of 'shelf' it will render out as "host.com/shelf/books". This is not for namespacing, for namespacing see the namespace option.
|
50
26
|
|
51
|
-
|
27
|
+
namespace: This is used for when you have namespacing. It works like prefix however unlike prefix it will also search for the controller within the namespace unlike prefix which doesn't.
|
52
28
|
|
53
|
-
|
29
|
+
controller: This is used to match the menu to a controller, when deciding which menu to render, it matches this attribute to the current controller. If you have namespacing, the 'namespace' options MUST be used before the 'controller' option otherwise it won't recognise the namespace
|
54
30
|
|
55
|
-
|
31
|
+
by_id: 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.
|
56
32
|
|
57
|
-
|
33
|
+
css_class: This is used when you want to hard code the CSS class selector into the menu rather then from the view
|
58
34
|
|
59
35
|
examples:
|
60
36
|
|
61
37
|
===Building menu object from scratch
|
62
38
|
The default option doesn't have to be the first in the selection list.
|
63
|
-
|
64
|
-
build.navs = [
|
39
|
+
NAVGATE = Navgate.new do |build|
|
40
|
+
build.navs = [ Navgate::Builder.new do |options|
|
65
41
|
options[:selection] = %w(selection site_settings users images misc)
|
66
42
|
options[:default] = 'users'
|
67
|
-
options[:
|
43
|
+
options[:namespace] = 'admin'
|
68
44
|
options[:controller] = 'admin_panel'
|
69
45
|
options[:css_class] = 'nav button'
|
70
46
|
end
|
@@ -72,104 +48,56 @@ The default option doesn't have to be the first in the selection list.
|
|
72
48
|
end
|
73
49
|
|
74
50
|
===Building menu object from database fields
|
75
|
-
Be sure to pass it as {model_name: :field}
|
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
|
51
|
+
Be sure to pass it as {model_name: :field}
|
77
52
|
|
78
|
-
|
79
|
-
build.navs = [
|
53
|
+
NAVGATE = Navgate.new do |build|
|
54
|
+
build.navs = [ Navgate::Builder.new do |options|
|
80
55
|
options[:selection] = {categories: :title }
|
81
56
|
options[:prefix] = 'shop_category'
|
82
|
-
options[:controller] =
|
57
|
+
options[:controller] = 'front_page'
|
83
58
|
options[:by_id] = true
|
84
59
|
end
|
85
60
|
]
|
86
61
|
end
|
87
|
-
===Building multiple menus
|
88
62
|
|
89
|
-
NavGate.configure do |build|
|
90
|
-
build.navs = [
|
91
|
-
NavGate::Builder.new do |options|
|
92
|
-
options[:selection] = %w(selection site_settings users images misc)
|
93
|
-
options[:default] = 'users'
|
94
|
-
options[:prefix] = = 'admin'
|
95
|
-
options[:controller] = 'admin_panel'
|
96
|
-
options[:css_class] = 'nav button'
|
97
|
-
end,
|
98
|
-
NavGate::Builder.new do |options|
|
99
|
-
options[:selection] = %w(welcome about_us gallery news)
|
100
|
-
options[:default] = 'news'
|
101
|
-
options[:controller] = 'front_page'
|
102
|
-
options[:css_class] = 'nav button'
|
103
|
-
end
|
104
|
-
]
|
105
|
-
end
|
106
63
|
|
107
64
|
=== Using a yml file to build the menu
|
108
|
-
There is also a third option to build the menu, you can use a structured yml file, there is an example yaml file in the config
|
65
|
+
There is also a third option to build the menu, you can use a structured yml file, there is an example yaml file in the config dirrectory called "build_menu.yml".
|
109
66
|
when using this method you are unable to use a database model to create the menu.
|
110
67
|
|
111
68
|
===Building from yaml file,
|
112
69
|
Initializing the object:
|
113
|
-
|
70
|
+
NAVGATE = Navgate.new do |build|
|
114
71
|
build.navs = "#{Rails.root}/config/build_menu.yml"
|
115
72
|
end
|
116
|
-
|
117
73
|
The yaml file:
|
118
74
|
nav_1:
|
119
75
|
selection: welcome about_us gallery
|
120
76
|
default: welcome
|
121
77
|
prefix: main
|
78
|
+
namespace: front_end
|
122
79
|
controller: front_page
|
123
80
|
nav_2:
|
124
81
|
selection: settings users misc
|
125
82
|
default: settings
|
126
|
-
|
83
|
+
namespace: back_end
|
127
84
|
controller: admin_panel
|
128
85
|
|
129
86
|
|
130
|
-
==Ignoring Controllers
|
131
|
-
Sometimes you're going to want to ignore controllers that don't any gui. Doing that is simple, when you're building the menu just pass an Array to build like so
|
132
|
-
build.ignoring = ['controllers','to','ignore']
|
133
|
-
before or after you pass through the navs.
|
134
87
|
|
135
88
|
==Rendering the menu
|
136
89
|
|
137
|
-
To render the menu use the provided helper
|
90
|
+
To render the menu use the provided helper "render_navigation(options)"
|
138
91
|
options is a hash that is used to build any html options you might want such as
|
139
|
-
|
92
|
+
class, it can also take two extra options, 'styling:' and 'wrap:'.
|
140
93
|
|
141
94
|
===Options
|
142
95
|
|
143
|
-
Styling: This is how the navigation can be styled
|
144
|
-
|
96
|
+
Styling: This is how the navigation can be styled it can either be ':verticle' or a character that you wish to use for spacing such as '|' or ':' and so on, it can only be verticle or a spaceing character.
|
145
97
|
Wrap: This allows you to wrap each link in a html tag, wrap can itself take two differant options, either a string containing the tag's name (without "<>", only the tag name) or an Array containing the tag name and it's class.
|
146
98
|
|
147
99
|
example:
|
148
|
-
render_navigation({
|
149
|
-
|
150
|
-
note: There is no point in passing a class here if you have one set when you first build the menu, it will just be overridden,
|
151
|
-
unless of course you're using multiple menus and some of them don't have css overides then they will take this option up.
|
152
|
-
|
153
|
-
==Using the selection to automatically render a matching partial
|
154
|
-
|
155
|
-
naveGATE is set up so you can use it to render out a partial using <tt>@selected</tt>, to do this you have to pass a route param of <tt>:selection</tt>
|
156
|
-
in the route, then you can use <tt><%= render @selected %></tt> to automatically select either the default selection or the current selection.
|
157
|
-
|
158
|
-
That said you don't have use this feature, it will still route to whatever url you set up as a normal url, but <tt>@selected</tt> won't work without <tt>:selection</tt>
|
159
|
-
example:
|
160
|
-
|
161
|
-
routes.rb
|
162
|
-
get "/:selection", to: "front_page#index"
|
163
|
-
root to: "front_page#index"
|
164
|
-
|
165
|
-
front_page/index.html.erb
|
166
|
-
<%= render @selected %>
|
167
|
-
|
168
|
-
resulting url
|
169
|
-
host.com/books
|
170
|
-
host.com/games
|
171
|
-
|
172
|
-
routes to the root but the partials rendered would be respectively
|
173
|
-
_books.html.erb
|
174
|
-
_games.html.erb
|
100
|
+
render_navigation({"class" => "'nav button'",styling: :verticle, wrap: ['li','test']}) %>
|
175
101
|
|
102
|
+
note: class has to be in "" due to it being a keyword in ruby.
|
103
|
+
note: There is no point in passing a class here if you have one set when you first build the menu, it will just be ignored.
|