menumatic 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -7,4 +7,4 @@ gem 'rspec'
7
7
  gem 'autotest'
8
8
  gem 'autotest-growl'
9
9
  gem 'factory_girl'
10
- gem 'rails', '~>3.0.4'
10
+ gem 'rails', '3.0.5'
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  Menumatic is a _Rails 3 exclusive_ gem which aids in developing HTML
4
4
  navigation menus.
5
5
 
6
+ __Please note__ menumatic is still in alpha however all the features mentioned in the readme should be working as expected - at the moment we're focussed on improving test coverage to bring us up to a proper, full release.
6
7
 
7
8
  ## Philosophy
8
9
 
@@ -28,7 +29,7 @@ Then update your bundle:
28
29
 
29
30
  You can then get started by generating a new navigation:
30
31
 
31
- $ rails g navigation
32
+ $ rails g menumatic:navigation
32
33
 
33
34
  This will create the file `app/navigation/application_navigation.rb` which you can use to
34
35
  define the structure of your navigation items.
@@ -45,7 +46,7 @@ Navigations are stored in `app/navigation`. The default navigation is
45
46
  given a name of 'application', however you can specify the name in the
46
47
  generator:
47
48
 
48
- $ rails g navigation application
49
+ $ rails g menumatic:navigation application
49
50
 
50
51
  Which will generate a navigation called
51
52
  `app/navigation/application_navigation.rb` and the basic stylesheet.
@@ -1,4 +1,5 @@
1
1
  module Menumatic
2
2
  class Engine < Rails::Engine
3
+ ActionController::Base.helper(Menumatic::Helpers::NavigationHelper)
3
4
  end
4
5
  end
@@ -1,7 +1,7 @@
1
1
  module Menumatic
2
2
  module Helpers
3
3
  module NavigationHelper
4
- def navigation(navigation_id = "application", options = {})
4
+ def menumatic(navigation_id = :application, options = {})
5
5
  options[:level] ||= nil # single level to render, overrides any other level settings
6
6
  options[:levels] ||= [options[:level]].delete_if{ |l| l.blank? }
7
7
 
@@ -9,9 +9,9 @@ module Menumatic
9
9
  options[:groups] ||= [options[:groups]].delete_if{ |g| g.blank? }
10
10
 
11
11
  options[:class] ||= ""
12
- options[:class] += "navigation #{navigation_id}"
12
+ options[:class] += "navigation #{navigation_id.to_s}"
13
13
 
14
- navigation = load_navigation(navigation_id)
14
+ navigation = Menumatic::Navigation::Base.load_navigation(navigation_id.to_sym)
15
15
  navigation.root.render(request, options)
16
16
  end
17
17
 
@@ -19,18 +19,6 @@ module Menumatic
19
19
  navigation = load_navigation(navigation_id)
20
20
  navigation.root.render_sitemap(document, request, options)
21
21
  end
22
-
23
- def load_navigation(navigation_id)
24
- # Eager load the requested navgation (allows for use of normal if/unless statements)
25
- Menumatic::Navigation::Base.destroy_all
26
- load "app/navigation/#{navigation_id}_navigation.rb"
27
- Menumatic::Navigation::Base.get(navigation_id)
28
- end
29
-
30
- def navigation_group(navigation_id, group_id, options = {})
31
- options = options.merge({:group => group_id})
32
- navigation(navigation_id, options)
33
- end
34
22
  end
35
23
  end
36
24
  end
@@ -10,8 +10,9 @@ module Menumatic
10
10
 
11
11
  if args.length > 2
12
12
  options = args[2]
13
- self.active_paths = options[:active_paths]
13
+ self.active_paths = options[:active_on]
14
14
  end
15
+ self.active_paths ||= []
15
16
  end
16
17
  end
17
18
  end
@@ -26,7 +26,7 @@ module Menumatic
26
26
  unless list.blank?
27
27
  list_options = html_options.merge({})
28
28
  list_options[:class] += " level_#{options[:current_level]}"
29
- list_options[:class] += " depth_#{count_active_descendants(request)}" if options[:current_level] == 1
29
+ list_options[:class] += " depth_#{depth_count(request, options)}" if options[:current_level] == 1
30
30
  if on_valid_level?(options[:levels], options[:current_level]) || options[:current_level] == 1
31
31
  list = content_tag(options[:wrapper_tag], list.html_safe, list_options)
32
32
  else
@@ -92,8 +92,19 @@ module Menumatic
92
92
  0
93
93
  end
94
94
 
95
+ def depth_count(request, options = {})
96
+ return options[:levels].count unless options[:levels].empty?
97
+ count_active_descendants(request)
98
+ end
99
+
95
100
  def paths_match?(request)
96
- request.fullpath == self.destination || request.url == self.destination if self.is_link?
101
+ if self.is_link?
102
+ self.active_paths.each do |path|
103
+ return true if path.is_a?(Regexp) && (request.fullpath =~ path || request.url =~ path)
104
+ return true if path.is_a?(String) && (request.fullpath == path || request.url == path)
105
+ end
106
+ return request.fullpath == self.destination || request.url == self.destination if self.active_paths.empty?
107
+ end
97
108
  end
98
109
 
99
110
  def on_valid_level?(levels, current_level)
@@ -101,7 +112,7 @@ module Menumatic
101
112
  end
102
113
 
103
114
  def levels_to_i(levels_in_words)
104
- levels_in_words.map{ |word| @@level_options.index(word.to_sym) + 1 }
115
+ levels_in_words.map{ |word| word.is_a?(Symbol) ? @@level_options.index(word.to_sym) + 1 : word }
105
116
  end
106
117
  end
107
118
  end
@@ -38,6 +38,13 @@ module Menumatic
38
38
  def destroy_all
39
39
  @@navigations = {}
40
40
  end
41
+
42
+ def load_navigation(navigation_id)
43
+ # Eager load the requested navgation (allows for use of normal if/unless statements)
44
+ Menumatic::Navigation::Base.destroy_all
45
+ load "app/navigation/#{navigation_id}_navigation.rb"
46
+ Menumatic::Navigation::Base.get(navigation_id)
47
+ end
41
48
  end
42
49
 
43
50
  def initialize(id)
@@ -0,0 +1,14 @@
1
+ module ActionView
2
+ module Rendering
3
+ def render_with_navigation_option(options = {}, locals = {}, &block)
4
+ if options.has_key? :navigation
5
+ navigation_id = options[:navigation]
6
+ options.delete(:navigation)
7
+ menumatic(navigation_id, options)
8
+ else
9
+ render_without_navigation_option(options, locals, &block)
10
+ end
11
+ end
12
+ alias_method_chain :render, :navigation_option
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Menumatic
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/menumatic.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  module Menumatic
2
2
  module Helpers
3
3
  autoload :NavigationHelper, 'menumatic/helpers/navigation_helper'
4
- ActionController::Base.helper(Menumatic::Helpers::NavigationHelper)
5
4
  end
6
5
 
7
6
  module Navigation
@@ -20,4 +19,5 @@ module Menumatic
20
19
  end
21
20
 
22
21
  require 'menumatic/rails/routes'
22
+ require 'menumatic/rails/rendering'
23
23
  require 'menumatic/engine'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: menumatic
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nicholas Bruning
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-08 00:00:00 +11:00
18
+ date: 2011-03-10 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -57,6 +57,7 @@ files:
57
57
  - lib/menumatic/navigation/item/link.rb
58
58
  - lib/menumatic/navigation/item/navigators.rb
59
59
  - lib/menumatic/navigation/item/renderers.rb
60
+ - lib/menumatic/rails/rendering.rb
60
61
  - lib/menumatic/rails/routes.rb
61
62
  - lib/menumatic/version.rb
62
63
  - menumatic.gemspec