navGATE 0.1.02 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,19 +2,19 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "navGATE"
5
- s.version = "0.1.02"
5
+ s.version = "0.1.3"
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 = "2013-10-14"
10
- s.description = "Allows the easy creation of menus with config files"
9
+ s.date = "2014-01-09"
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"]
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"]
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/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/builder.rb", "lib/navgate/main.rb", "lib/navgate/modules/navgatehelpers.rb", "lib/navgate/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
- s.summary = "Allows the easy creation of menus with config files"
19
+ s.summary = "Allows the easy creation of navigation with config files"
20
20
  end
@@ -1,94 +1,175 @@
1
1
  = navGATE
2
2
 
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
3
+ This gem is provided as is.
4
4
 
5
- note: this is my first gem, I am still trying to set it up, so be carefull when downloading this.
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.
6
8
 
7
- ==Building the menu
9
+ This gem was built with Rails in mind.
10
+
11
+
12
+ lastly the gem is up on rubygems.org
13
+
14
+ ==Setup
15
+ in the Application controller you have to <tt> include 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
+ ==Building the menus
8
36
 
9
37
  When building the menu there are multiple options available, building the menu is done in an initializer file in the configs directory.
10
38
 
11
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.
12
40
 
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.
13
42
  ===Options
14
43
 
15
- selection: This is used to build the menu options.
44
+ <b>selection</b>: This is used to build the menu options.
16
45
  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
17
46
 
18
- 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.
47
+ <b>Default</b>: 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 default selection, if no string is passed then the first item from selection is used.
48
+
49
+ <b>prefix</b>: 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". Namespacing is ignored within this gem, it only looks at the controller's name and nothing else when controller matching.
19
50
 
20
- 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.
51
+ <b>controller</b>: This is used to match the menu to a controller, when deciding which menu to render, it can also be an array of strings; it matches this attribute to the current controller.
21
52
 
22
- 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.
53
+ <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.
23
54
 
24
- 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
55
+ <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.
25
56
 
26
- 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.
57
+ <b>css_selected</b>: the css override for the selected that's currently selected. if no override is passed then the link is simply not rendered out, as with css_class it overrides the one passed in the view, but only for the selected link
27
58
 
28
59
  examples:
29
60
 
30
61
  ===Building menu object from scratch
31
62
  The default option doesn't have to be the first in the selection list.
32
- NAVGATE = Navgate.new do |build|
33
- build.navs = [ Navgate::Builder.new do |options|
63
+ NavGate.configure do |build|
64
+ build.navs = [ NavGate::Builder.new do |options|
34
65
  options[:selection] = %w(selection site_settings users images misc)
35
66
  options[:default] = 'users'
36
- options[:namespace] = 'admin'
67
+ options[:prefix] = = 'admin'
37
68
  options[:controller] = 'admin_panel'
69
+ options[:css_class] = 'nav button'
38
70
  end
39
71
  ]
40
72
  end
41
73
 
42
74
  ===Building menu object from database fields
43
- Be sure to pass it as {model_name: :field}
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
44
77
 
45
- NAVGATE = Navgate.new do |build|
46
- build.navs = [ Navgate::Builder.new do |options|
78
+ NavGate.configure do |build|
79
+ build.navs = [ NavGate::Builder.new do |options|
47
80
  options[:selection] = {categories: :title }
48
81
  options[:prefix] = 'shop_category'
49
- options[:controller] = 'front_page'
82
+ options[:controller] = "front_page side_page about_page".split(" ")
50
83
  options[:by_id] = true
51
84
  end
52
85
  ]
53
86
  end
87
+ ===Building multiple menus
54
88
 
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
55
106
 
56
107
  === Using a yml file to build the menu
57
- 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".
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 directory called "build_menu.yml".
58
109
  when using this method you are unable to use a database model to create the menu.
59
110
 
60
111
  ===Building from yaml file,
61
112
  Initializing the object:
62
- NAVGATE = Navgate.new do |build|
113
+ NavGate.configure do |build|
63
114
  build.navs = "#{Rails.root}/config/build_menu.yml"
64
115
  end
116
+
65
117
  The yaml file:
66
118
  nav_1:
67
119
  selection: welcome about_us gallery
68
120
  default: welcome
69
121
  prefix: main
70
- namespace: front_end
71
122
  controller: front_page
72
123
  nav_2:
73
124
  selection: settings users misc
74
125
  default: settings
75
- namespace: back_end
126
+ preix: back_end
76
127
  controller: admin_panel
77
128
 
78
129
 
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.
79
134
 
80
135
  ==Rendering the menu
81
136
 
82
- To render the menu use the provided helper "render_navigation(options)"
137
+ To render the menu use the provided helper <tt>render_navigation(options)</tt>;
83
138
  options is a hash that is used to build any html options you might want such as
84
- class, it can also take two extra options, 'styling:' and 'wrap:'.
139
+ 'class='some_css_class', it can also take two extra options, 'styling:' and 'wrap:'.
85
140
 
86
141
  ===Options
87
142
 
88
- 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.
143
+ Styling: This is how the navigation can be styled, it can either be ':vertical’ or a character that you wish to use for spacing such as '|' or ':' and so on, it can only be vertical or a spacing character.
144
+
89
145
  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.
90
146
 
91
147
  example:
92
- render_navigation({"class" => "'nav button'",styling: :verticle, wrap: ['li','test']}) %>
148
+ render_navigation({:class => "'nav button'", styling: :vertical, wrap: ['li','test']}) %>
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
93
175
 
94
- note: class has to be in "" due to it being a keyword in ruby.
metadata CHANGED
@@ -1,32 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navGATE
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.02
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Becker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-14 00:00:00.000000000 Z
11
+ date: 2014-01-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Allows the easy creation of menus with config files
13
+ description: Can create navigation from objects using the nav builder,from database
14
+ tables or from a yaml file
14
15
  email: mbeckerwork@gmail.com
15
16
  executables: []
16
17
  extensions: []
17
18
  extra_rdoc_files:
18
19
  - lib/navgate.rb
19
20
  - lib/navgate/base.rb
21
+ - lib/navgate/builder.rb
22
+ - lib/navgate/main.rb
23
+ - lib/navgate/modules/navgatehelpers.rb
24
+ - lib/navgate/navgatehelpers.rb
25
+ - lib/readme.rdoc
20
26
  files:
27
+ - LICENCE/GPL-2
21
28
  - Manifest
22
29
  - Rakefile
23
- - app/controller/application_controller.rb
24
- - app/helpers/application_helper.rb
25
30
  - config/build_menu.yml
26
31
  - config/initializers/build_menu.rb
27
32
  - init.rb
28
33
  - lib/navgate.rb
29
34
  - lib/navgate/base.rb
35
+ - lib/navgate/builder.rb
36
+ - lib/navgate/main.rb
37
+ - lib/navgate/modules/navgatehelpers.rb
38
+ - lib/navgate/navgatehelpers.rb
39
+ - lib/readme.rdoc
30
40
  - navGATE.gemspec
31
41
  - readme.rdoc
32
42
  homepage: https://github.com/Thermatix/navGATE
@@ -57,5 +67,5 @@ rubyforge_project: navgate
57
67
  rubygems_version: 2.0.6
58
68
  signing_key:
59
69
  specification_version: 4
60
- summary: Allows the easy creation of menus with config files
70
+ summary: Allows the easy creation of navigation with config files
61
71
  test_files: []
@@ -1,9 +0,0 @@
1
-
2
- class ApplicationController < ActionController::Base
3
- before_filter :make_menu
4
- def make_menu
5
- @navgate = NAVGATE
6
- @selected ||= @navgate.select(params)
7
- end
8
- end
9
-
@@ -1,5 +0,0 @@
1
- module ApplicationHelper
2
- def render_navigation options = nil
3
- @navgate.render_nav(params, options)
4
- end
5
- end