Permalink
Browse files

Started writing tests, completed render refactor

  • Loading branch information...
1 parent 59bccff commit e09b3da05c131fc15ca293965cfb659c2beaeab2 @thetron committed Mar 7, 2011
View
@@ -0,0 +1 @@
+require 'autotest/growl'
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--format documentation
View
@@ -2,3 +2,9 @@ source "http://rubygems.org"
# Specify your gem's dependencies in menumatic.gemspec
gemspec
+
+gem 'rspec'
+gem 'autotest'
+gem 'autotest-growl'
+gem 'factory_girl'
+gem 'rails', '~>3.0.4'
View
@@ -0,0 +1,95 @@
+PATH
+ remote: .
+ specs:
+ menumatic (0.0.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ ZenTest (4.5.0)
+ abstract (1.0.0)
+ actionmailer (3.0.5)
+ actionpack (= 3.0.5)
+ mail (~> 2.2.15)
+ actionpack (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ activesupport (3.0.5)
+ arel (2.0.9)
+ autotest (4.4.6)
+ ZenTest (>= 4.4.1)
+ autotest-growl (0.2.9)
+ builder (2.1.2)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ factory_girl (1.3.2)
+ i18n (0.5.0)
+ mail (2.2.15)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.5)
+ actionmailer (= 3.0.5)
+ actionpack (= 3.0.5)
+ activerecord (= 3.0.5)
+ activeresource (= 3.0.5)
+ activesupport (= 3.0.5)
+ bundler (~> 1.0)
+ railties (= 3.0.5)
+ railties (3.0.5)
+ actionpack (= 3.0.5)
+ activesupport (= 3.0.5)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ rspec (2.5.0)
+ rspec-core (~> 2.5.0)
+ rspec-expectations (~> 2.5.0)
+ rspec-mocks (~> 2.5.0)
+ rspec-core (2.5.1)
+ rspec-expectations (2.5.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.5.0)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.24)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ autotest
+ autotest-growl
+ factory_girl
+ menumatic!
+ rails (~> 3.0.4)
+ rspec
View
@@ -5,18 +5,104 @@ navigation menus.
# Getting Started
-Start by generating a new navigation
+Include the gem in your `Gemfile` like so:
+
+ gem 'menumatic'
+
+Then update your bundle:
+
+ $ bundle
+
+You can then get started by generating a new navigation:
$ rails g navigation
This will create the file `app/navigation/application_navigation.rb` which you can use to
define the structure of your navigation items.
-If you want to include the bundled stylesheet, add the following to your
+If you want to use the bundled stylesheet (bland, but functional), add the following to your
layout:
<%= stylesheet_link_tag "application_navigation" %>
-# Options
+
+# Philosophy
+
+Menumatic takes a slightly different approach to other navigation gems,
+in that the structure of the menu is considered to be more 'M' than 'V'
+in the MVC world. This is because given any view, we may only want to
+display _parts_ of a particular navigation, such as sub-navigations and
+sidebars, for which there is a simple view helper.
+
+This results in simple, clean and easy-to-read code that you can
+leverage in any part of your Rails app.
+
+
+# Using Menumatic
+
+Navigations are stored in `app/navigation`. The default navigation is
+given a name of 'application', however you can specify the name in the
+generator:
+
+ $ rails g navigation admin
+
+Which will generate a navigation called 'admin'
+
+Inside your navigation file, you can then define the structure of your
+navigation, here is an example taken from the [Menumatic example
+application](http://www.github.com/thetron/menumatic-test):
+
+_todo_
+
+To display your navigation in your view, simply use the menumatic
+helper:
+
+ # app/views/layouts/application.html.erb
+ <!-- snip -->
+ <header>
+ <nav>
+ <%= navigation :application %>
+ </nav>
+ </header>
+
+Which will give you a full-semantic, auto-highlighted navigation.
+
+
+# More Options
+
+## Options for `navigate_to`
+
+_todo_
+
+## Selective Rendering
+
+By default, Menumatic displays your navigation as a set of nested
+unordered lists. However, if you need to break up your layout, this is
+easily achiveable:
+
+
+ # app/views/layouts/application.html.erb
+ <!-- snip -->
+ <header>
+ <nav>
+ <%= navigation :application, :level => :primary %>
+ </nav>
+ </header>
+
+ <div class="sub_navigation">
+ <%= navigation :application, :start_level => :secondary %>
+ </div>
+
+The above example would render the top-level navigation in the
+`<header>` and everything else in the `sub_navigation` div below.
+
+
+## Grouping
+
+Menumatic also supports grouping navigation items together. By default,
+groups nested in your navigation will not display as part of the normal
+rendering, but only when you request them.
+
+The best example of when this is useful is for developing a sidebar. Particularly in the case of a sidebar whose navigation items will vary, depending on the page. For example:
_todo_
View
14 TODO.md
@@ -20,3 +20,17 @@ hopefully produce some cleaner code.
This should be the next highest priority, and we need to consider how to
pass the requested groups and chain position through the render process,
to make sure no link is left behind.
+
+## Sitemap generation
+
+Create a helper method for the routes.rb file (similar to `devise_for`):
+
+ sitemap :application
+
+Which will create a route for sitemap.xml and automatically generate and
+handle the requests that go through to it. The sitemap will be generated
+from the navigation specified in the sitemap helper. This will include
+all links and groups (except those not visible by default from
+conditional effects).
+
+
View
@@ -5,12 +5,11 @@ module Helpers
end
module Navigation
- module Group
- autoload :Base, 'menumatic/navigation/group'
- end
module Item
autoload :Renderers, 'menumatic/navigation/item/renderers'
autoload :Navigators, 'menumatic/navigation/item/navigators'
+ autoload :Group, 'menumatic/navigation/item/group'
+ autoload :Link, 'menumatic/navigation/item/link'
autoload :Base, 'menumatic/navigation/item'
end
autoload :Base, 'menumatic/navigation'
@@ -17,7 +17,8 @@ def navigation(ids, options = {})
end
navigation = Menumatic::Navigation::Base.get(navigation_id)
- render_list(navigation.items, 1, true)
+ #render_list(navigation.items, 1, true)
+ navigation.root.render(request, options)
end
private
@@ -6,11 +6,11 @@ class Base
attr_accessor :id, :root
class << self
- def navigate_to(label, destination, options = {}, html_options = {})
+ def navigate_to(label, destination, options = {})
if block_given?
- item = self.get_instance.root.navigate_to(label, destination, options, html_options, &Proc.new)
+ item = self.get_instance.root.navigate_to(label, destination, options, &Proc.new)
else
- item = self.get_instance.root.navigate_to(label, destination, options, html_options)
+ item = self.get_instance.root.navigate_to(label, destination, options)
end
end
@@ -42,7 +42,7 @@ def destroy_all
def initialize(id)
self.id = id
- self.root = Menumatic::Navigation::Item::Base.new("Root", "javascript:void(0)", {:root => true})
+ self.root = Menumatic::Navigation::Item::Group.new("#{id}_root".to_sym)
end
def items
@@ -1,16 +0,0 @@
-module Menumatic
- module Navigation
- module Group
- class Base
- attr_accessor :id, :items, :groups
- include Menumatic::Navigation::Item::Navigators
-
- def initialize(id)
- self.id = id
- self.items = []
- self.groups = {}
- end
- end
- end
- end
-end
@@ -2,21 +2,29 @@ module Menumatic
module Navigation
module Item
class Base
- attr_accessor :is_root, :items, :groups, :label, :destination, :options, :html_options
+ attr_accessor :items, :options
include Menumatic::Navigation::Item::Renderers
include Menumatic::Navigation::Item::Navigators
- def initialize(label, destination, options = {}, html_options = {})
- self.label = label
- self.destination = destination
- self.options = options
- self.html_options = html_options
- self.is_root = options[:root]
+ def initialize(*args)
+ self.options = args.last
self.items = []
- self.groups = {}
end
+ def is_link?
+ self.is_a? Menumatic::Navigation::Item::Link
+ end
+
+ def is_group?
+ self.is_a? Menumatic::Navigation::Item::Group
+ end
+
+ private
+ def add_item(item)
+ self.items << item
+ item
+ end
end
end
end
@@ -0,0 +1,13 @@
+module Menumatic
+ module Navigation
+ module Item
+ class Group < Menumatic::Navigation::Item::Base
+ attr_accessor :id
+ def initialize(*args)
+ super
+ self.id = args[0]
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,14 @@
+module Menumatic
+ module Navigation
+ module Item
+ class Link < Menumatic::Navigation::Item::Base
+ attr_accessor :label, :destination
+ def initialize(*args)
+ super
+ self.label = args[0]
+ self.destination = args[1]
+ end
+ end
+ end
+ end
+end
@@ -2,21 +2,14 @@ module Menumatic
module Navigation
module Item
module Navigators
- def navigate_to(label, destination, options = {}, html_options = {})
- item = add_item(Menumatic::Navigation::Item::Base.new(label, destination, options, html_options))
+ def navigate_to(label, destination, options = {})
+ item = add_item(Menumatic::Navigation::Item::Link.new(label, destination, options))
yield item if block_given?
end
- def group(id)
- self.groups[id] = Menumatic::Navigation::Group::Base.new(id) unless self.groups.has_key?(id)
- group = self.groups[id]
- yield group if block_given?
- end
-
- private
- def add_item(item, group = nil)
- self.items << item
- item
+ def group(id, options = {})
+ item = add_item(Menumatic::Navigation::Item::Group.new(id, options))
+ yield item if block_given?
end
end
end
Oops, something went wrong.

0 comments on commit e09b3da

Please sign in to comment.