navGATE 0.1.03 → 0.1.3.1

Sign up to get free protection for your applications and to get access to all the features.
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.03"
5
+ s.version = "0.1.3.1"
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-15"
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
data/readme.rdoc CHANGED
@@ -1,99 +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
+
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.
4
8
 
5
9
  This gem was built with Rails in mind.
6
10
 
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.
11
+
10
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
+
11
35
  ==Building the menus
12
36
 
13
37
  When building the menu there are multiple options available, building the menu is done in an initializer file in the configs directory.
14
38
 
15
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.
16
40
 
17
- Also note, you can pass multiple Navgate::builders as you need, just match them to there controllers and they should render properly.
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.
18
42
  ===Options
19
43
 
20
- selection: This is used to build the menu options.
44
+ <b>selection</b>: This is used to build the menu options.
21
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
22
46
 
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.
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.
24
50
 
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.
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.
26
52
 
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.
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.
28
54
 
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
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.
30
56
 
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.
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
32
58
 
33
59
  examples:
34
60
 
35
61
  ===Building menu object from scratch
36
62
  The default option doesn't have to be the first in the selection list.
37
- NAVGATE = Navgate.new do |build|
38
- build.navs = [ Navgate::Builder.new do |options|
63
+ NavGate.configure do |build|
64
+ build.navs = [ NavGate::Builder.new do |options|
39
65
  options[:selection] = %w(selection site_settings users images misc)
40
66
  options[:default] = 'users'
41
- options[:namespace] = 'admin'
67
+ options[:prefix] = = 'admin'
42
68
  options[:controller] = 'admin_panel'
69
+ options[:css_class] = 'nav button'
43
70
  end
44
71
  ]
45
72
  end
46
73
 
47
74
  ===Building menu object from database fields
48
- 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
49
77
 
50
- NAVGATE = Navgate.new do |build|
51
- build.navs = [ Navgate::Builder.new do |options|
78
+ NavGate.configure do |build|
79
+ build.navs = [ NavGate::Builder.new do |options|
52
80
  options[:selection] = {categories: :title }
53
81
  options[:prefix] = 'shop_category'
54
- options[:controller] = 'front_page'
82
+ options[:controller] = "front_page side_page about_page".split(" ")
55
83
  options[:by_id] = true
56
84
  end
57
85
  ]
58
86
  end
87
+ ===Building multiple menus
59
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
60
106
 
61
107
  === Using a yml file to build the menu
62
- 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".
63
109
  when using this method you are unable to use a database model to create the menu.
64
110
 
65
111
  ===Building from yaml file,
66
112
  Initializing the object:
67
- NAVGATE = Navgate.new do |build|
113
+ NavGate.configure do |build|
68
114
  build.navs = "#{Rails.root}/config/build_menu.yml"
69
115
  end
116
+
70
117
  The yaml file:
71
118
  nav_1:
72
119
  selection: welcome about_us gallery
73
120
  default: welcome
74
121
  prefix: main
75
- namespace: front_end
76
122
  controller: front_page
77
123
  nav_2:
78
124
  selection: settings users misc
79
125
  default: settings
80
- namespace: back_end
126
+ preix: back_end
81
127
  controller: admin_panel
82
128
 
83
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.
84
134
 
85
135
  ==Rendering the menu
86
136
 
87
- 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>;
88
138
  options is a hash that is used to build any html options you might want such as
89
- 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:'.
90
140
 
91
141
  ===Options
92
142
 
93
- 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
+
94
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.
95
146
 
96
147
  example:
97
- 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
98
175
 
99
- 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.03
4
+ version: 0.1.3.1
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-15 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