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.
data/lib/navgate/main.rb DELETED
@@ -1,60 +0,0 @@
1
- module NavGate
2
- class Navigation
3
- def self.select selection, controller
4
- split_controller = controller.split('/').last
5
- if selection
6
- selection
7
- else
8
- if config.ignoring.include?(split_controller)
9
- nil
10
- else
11
- nav_cache(split_controller).default.to_s
12
- end
13
- end
14
- end
15
-
16
- def self.render_nav selection, controller, options
17
- split_controller = controller.split('/').last
18
- if config.ignoring.include?(split_controller)
19
- nil
20
- else
21
- nav = nav_cache(split_controller).render_it_with(options,selection).html_safe
22
- nav
23
- end
24
- end
25
-
26
- private
27
-
28
- def self.config
29
- NavGate.configuration
30
- end
31
-
32
- def self.nav_cache controller
33
- if @selected_nav
34
- if @selected_nav.controller.is_a?(Array)
35
- return @selected_nav if @selected_nav.controller.include?(controller)
36
- else
37
- return @selected_nav unless @selected_nav.controller != controller
38
- end
39
- @selected_nav = nil
40
- nav_cache(controller)
41
- else
42
- @selected_nav ||= select_nav(controller)
43
- end
44
- end
45
-
46
- def self.select_nav controller
47
- nav_to_return = nil
48
- config.navs.each do |nav|
49
- if nav.controller.is_a?(String)
50
- nav_to_return = nav if (nav.controller) == controller
51
- elsif nav.controller.is_a?(Array)
52
- nav_to_return = nav if nav.controller.include?(controller)
53
- else
54
- raise TypeError, "expecting nav.controller to be a String or an Array, got #{nav.controller.class} "
55
- end
56
- end
57
- nav_to_return ? (return nav_to_return) : (raise ArgumentError, "No matching controllers for #{controller}")
58
- end
59
- end
60
- end
@@ -1,26 +0,0 @@
1
- module NavGate
2
- module NavGateHelpers
3
- def NavGateHelpers.included(mod)
4
- if Module.const_get("Rails").is_a?(Module).inspect
5
- #with rails
6
- def make_menu
7
- @navgate = NavGate::Navigation
8
- @selected ||= @navgate.select(params[:selection], params[:controller])
9
- end
10
- def render_navigation options = nil
11
- @navgate.render_nav((params[:selection]||request.fullpath), params[:controller], options )
12
- end
13
- else
14
- #without rails
15
- def make_menu selection, controller
16
- @navgate = NavGate::Navigation
17
- @selected ||= @navgate.select(selection, controller)
18
- end
19
- def render_navigation controller, options = nil
20
- @navgate.render_nav( @selected , controller, options )
21
- end
22
- end
23
- end
24
- end
25
- end
26
-
data/lib/readme.rdoc DELETED
@@ -1,174 +0,0 @@
1
- = navGATE
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.
8
-
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
36
-
37
- When building the menu there are multiple options available, building the menu is done in an initializer file in the configs directory.
38
-
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.
40
-
41
- Also note, you can pass multiple Navgate::builders as you need, just match them to there controllers and they should render properly.
42
- ===Options
43
-
44
- <b>selection</b>: This is used to build the menu options.
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
46
-
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.
50
-
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.
52
-
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.
54
-
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.
56
-
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
58
-
59
- examples:
60
-
61
- ===Building menu object from scratch
62
- The default option doesn't have to be the first in the selection list.
63
- NAVGATE = Navgate.new do |build|
64
- build.navs = [ Navgate::Builder.new do |options|
65
- options[:selection] = %w(selection site_settings users images misc)
66
- options[:default] = 'users'
67
- options[:prefix] = = 'admin'
68
- options[:controller] = 'admin_panel'
69
- options[:css_class] = 'nav button'
70
- end
71
- ]
72
- end
73
-
74
- ===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
77
-
78
- NAVGATE = Navgate.new do |build|
79
- build.navs = [ Navgate::Builder.new do |options|
80
- options[:selection] = {categories: :title }
81
- options[:prefix] = 'shop_category'
82
- options[:controller] = "front_page side_page about_page".split(" ")
83
- options[:by_id] = true
84
- end
85
- ]
86
- end
87
- ===Building multiple menus
88
-
89
- NAVGATE = Navgate.new 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
-
107
- === 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 directory called "build_menu.yml".
109
- when using this method you are unable to use a database model to create the menu.
110
-
111
- ===Building from yaml file,
112
- Initializing the object:
113
- NAVGATE = Navgate.new do |build|
114
- build.navs = "#{Rails.root}/config/build_menu.yml"
115
- end
116
- The yaml file:
117
- nav_1:
118
- selection: welcome about_us gallery
119
- default: welcome
120
- prefix: main
121
- controller: front_page
122
- nav_2:
123
- selection: settings users misc
124
- default: settings
125
- preix: back_end
126
- controller: admin_panel
127
-
128
-
129
- ==Ignoring Controllers
130
- 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
131
- build.ignoring = ['controllers','to','ignore']
132
- before or after you pass through the navs.
133
-
134
- ==Rendering the menu
135
-
136
- To render the menu use the provided helper <tt>render_navigation(options)</tt>;
137
- options is a hash that is used to build any html options you might want such as
138
- 'class='some_css_class', it can also take two extra options, 'styling:' and 'wrap:'.
139
-
140
- ===Options
141
-
142
- 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.
143
-
144
- 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.
145
-
146
- example:
147
- render_navigation({:class => "'nav button'", styling: :vertical, wrap: ['li','test']}) %>
148
-
149
- 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,
150
- unless of course you're using multiple menus and some of them don't have css overides then they will take this option up.
151
-
152
- ==Using the selection to automatically render a matching partial
153
-
154
- 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>
155
- in the route, then you can use <tt><%= render @selected %></tt> to automatically select either the default selection or the current selection.
156
-
157
- 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>
158
- example:
159
-
160
- routes.rb
161
- get "/:selection", to: "front_page#index"
162
- root to: "front_page#index"
163
-
164
- front_page/index.html.erb
165
- <%= render @selected %>
166
-
167
- resulting url
168
- host.com/books
169
- host.com/games
170
-
171
- routes to the root but the partials rendered would be respectively
172
- _books.html.erb
173
- _games.html.erb
174
-