menu_builder 0.0.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -30,11 +30,11 @@ Just install the plugin and see the example below:
30
30
 
31
31
  ==== ERB code
32
32
 
33
- <% tabs :id=>"mainMenu", :class=>"menu" do |tab| %>
34
- <%= tab.account 'Account', account_path, :style => 'float: right' %>
35
- <%= tab.users 'Users', users_path, :style => 'float: right' %>
36
- <%= tab.mydashboard 'Dashboard', '/' %>
37
- <%= tab.projects 'Projects', projects_path %>
33
+ <% menu :id=>"mainMenu", :class=>"menu" do |m| %>
34
+ <%= m.account 'Account', account_path, :style => 'float: right' %>
35
+ <%= m.users 'Users', users_path, :style => 'float: right' %>
36
+ <%= m.mydashboard 'Dashboard', '/' %>
37
+ <%= m.projects 'Projects', projects_path %>
38
38
  <% end %>
39
39
 
40
40
  ==== HTML Result
@@ -51,16 +51,12 @@ Just install the plugin and see the example below:
51
51
  Also is possible to pass blocks instead of simple strings for content.
52
52
  In this way you can create tabs with icons. Like below:
53
53
 
54
- <% tabs do |tab| %>
55
- <% tab.account account_path do %>
56
- <%= image_tag "account.jpg" /> Accounts
57
- <% end %>
58
- <% tab.users users_path do %>
59
- <%= image_tag "user.jpg" /> Users
60
- <% end %>
61
- <% tab.posts posts_path do %>
62
- <%= image_tag "posts.jpg" /> Posts
54
+ <% menu do |tab| %>
55
+ <% m.account account_path do %>
56
+ <%= image_tag "icon.jpg" /> Accounts
63
57
  <% end %>
58
+ <%= m.users "Users", users_path %>
59
+ <%= m.posts "Posts", posts_path %>
64
60
  <% end %>
65
61
 
66
62
  == CSS and HTML
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.2.0
data/lib/menu_builder.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'menu_builder/controller'
2
- require 'menu_builder/view'
2
+ require 'menu_builder/helper'
3
3
 
4
4
  ActionController::Base.extend(MenuBuilder::Controller)
5
5
  ActionView::Base.send(:include, MenuBuilder::ViewHelpers)
@@ -1,11 +1,11 @@
1
1
  module MenuBuilder
2
2
  module Controller
3
3
 
4
- def current_tab(name, options = {})
4
+ def menu_item(name, options = {})
5
5
  before_filter(options) do |controller|
6
- controller.instance_variable_set('@current_tab', name)
6
+ controller.instance_variable_set('@menu_item', name)
7
7
  end
8
8
  end
9
9
 
10
10
  end
11
- end
11
+ end
@@ -0,0 +1,27 @@
1
+ module MenuBuilder
2
+ module ViewHelpers
3
+ class Menu
4
+
5
+ def initialize(context)
6
+ @context = context
7
+ @menu_item = @context.instance_variable_get('@menu_item')
8
+ end
9
+
10
+ def current_item?(item)
11
+ @menu_item.to_s == item.to_s
12
+ end
13
+
14
+ def method_missing(item, *args, &block)
15
+ css_class = "current" if current_item?(item)
16
+ @context.content_tag :li, @context.link_to(*args, &block), :class=>css_class
17
+ end
18
+
19
+ end
20
+
21
+ def menu(options={})
22
+ concat tag(:ul, options, true)
23
+ yield Menu.new(self)
24
+ concat "</ul>"
25
+ end
26
+ end
27
+ end
data/menu_builder.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{menu_builder}
8
- s.version = "0.0.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Lopes"]
@@ -26,10 +26,12 @@ Gem::Specification.new do |s|
26
26
  "init.rb",
27
27
  "lib/menu_builder.rb",
28
28
  "lib/menu_builder/controller.rb",
29
- "lib/menu_builder/view.rb",
29
+ "lib/menu_builder/helper.rb",
30
30
  "menu_builder.gemspec",
31
- "test/helper.rb",
32
- "test/test_menu_builder.rb"
31
+ "test/controller_test.rb",
32
+ "test/helper_test.rb",
33
+ "test/support/controllers.rb",
34
+ "test/test_helper.rb"
33
35
  ]
34
36
  s.homepage = %q{http://github.com/danielvlopes/menu_builder}
35
37
  s.rdoc_options = ["--charset=UTF-8"]
@@ -37,8 +39,10 @@ Gem::Specification.new do |s|
37
39
  s.rubygems_version = %q{1.3.6}
38
40
  s.summary = %q{Killer solutions for menus and tabs for Rails}
39
41
  s.test_files = [
40
- "test/helper.rb",
41
- "test/test_menu_builder.rb"
42
+ "test/controller_test.rb",
43
+ "test/helper_test.rb",
44
+ "test/support/controllers.rb",
45
+ "test/test_helper.rb"
42
46
  ]
43
47
 
44
48
  if s.respond_to? :specification_version then
@@ -0,0 +1,18 @@
1
+ require "test_helper"
2
+
3
+ class BooksController < ApplicationController
4
+ menu_item :home
5
+
6
+ def index
7
+ end
8
+ end
9
+
10
+ class MenuBuilderTest < ActionController::TestCase
11
+ tests BooksController
12
+
13
+ test "should assigns the current tab" do
14
+ get :index
15
+ assert_equal(:home, assigns(:menu_item))
16
+ end
17
+
18
+ end
@@ -0,0 +1,43 @@
1
+ require "test_helper"
2
+
3
+ class HelperTest < ActionView::TestCase
4
+ tests MenuBuilder::ViewHelpers
5
+
6
+ test "menu yields an instance of Menu" do
7
+ menu do |m|
8
+ assert m.instance_of?(MenuBuilder::ViewHelpers::Menu)
9
+ end
10
+ end
11
+
12
+ test "menu create an unordered list" do
13
+ menu :id=>"menu" do |m| end
14
+ assert_select "ul#menu"
15
+ end
16
+
17
+ test "menu should accept html options like classes and id" do
18
+ menu :id=>"menu", :class=>"tabs" do |m| end
19
+ assert_select "ul#menu.tabs"
20
+ end
21
+
22
+ test "menu should create a line item" do
23
+ menu { |m| concat m.home "Home", "#" }
24
+ assert_select "li", 1
25
+ end
26
+
27
+ test "should create a link inside line item" do
28
+ menu { |m| concat m.home "Home", "/" }
29
+ expected = %(<ul><li><a href="/">Home</a></li></ul>)
30
+ assert_dom_equal expected, output_buffer
31
+ end
32
+
33
+ test "should set the class to the current item li" do
34
+ @menu_item = :home
35
+ menu do |m|
36
+ concat m.home "Home", "/"
37
+ concat m.contact "Store", "/store"
38
+ end
39
+
40
+ assert_select "li.current", 1
41
+ end
42
+
43
+ end
@@ -0,0 +1,13 @@
1
+ require 'active_support'
2
+ require 'action_controller'
3
+
4
+ ActionController::Routing::Routes.draw do |map|
5
+ map.connect ':controller/:action/:id'
6
+ end
7
+
8
+ class ApplicationController < ActionController::Base
9
+ protected
10
+ def default_render
11
+ render :text => action_name
12
+ end
13
+ end
@@ -1,10 +1,11 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
+ require 'action_controller'
4
+ require 'action_view/test_case'
3
5
 
4
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
8
 
7
- require 'menu_builder'
9
+ Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
8
10
 
9
- class Test::Unit::TestCase
10
- end
11
+ require 'menu_builder'
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
7
  - 2
9
- version: 0.0.2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Lopes
@@ -37,10 +37,12 @@ files:
37
37
  - init.rb
38
38
  - lib/menu_builder.rb
39
39
  - lib/menu_builder/controller.rb
40
- - lib/menu_builder/view.rb
40
+ - lib/menu_builder/helper.rb
41
41
  - menu_builder.gemspec
42
- - test/helper.rb
43
- - test/test_menu_builder.rb
42
+ - test/controller_test.rb
43
+ - test/helper_test.rb
44
+ - test/support/controllers.rb
45
+ - test/test_helper.rb
44
46
  has_rdoc: true
45
47
  homepage: http://github.com/danielvlopes/menu_builder
46
48
  licenses: []
@@ -72,5 +74,7 @@ signing_key:
72
74
  specification_version: 3
73
75
  summary: Killer solutions for menus and tabs for Rails
74
76
  test_files:
75
- - test/helper.rb
76
- - test/test_menu_builder.rb
77
+ - test/controller_test.rb
78
+ - test/helper_test.rb
79
+ - test/support/controllers.rb
80
+ - test/test_helper.rb
@@ -1,28 +0,0 @@
1
- module MenuBuilder
2
- module ViewHelpers
3
- class Tab
4
-
5
- def initialize(context)
6
- @context = context
7
- @current_tab = @context.instance_variable_get('@current_tab')
8
- end
9
-
10
- def current_tab?(tab)
11
- @current_tab.to_s == tab.to_s
12
- end
13
-
14
- def method_missing(tab, *args, &block)
15
- css_class = "current" if current_tab?(tab)
16
- @context.content_tag :li, @context.link_to(*args, &block), :class=>css_class
17
- end
18
-
19
- end
20
-
21
- def tabs(options={})
22
- concat tag(:ul, options, true)
23
- yield Tab.new(self)
24
- concat "</ul>"
25
- end
26
-
27
- end
28
- end
@@ -1,5 +0,0 @@
1
- require 'helper'
2
-
3
- class TestMenuBuilder < Test::Unit::TestCase
4
- # TODO WRITE TESTS
5
- end