tabs_on_rails 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,6 +1,15 @@
1
1
  = Changelog
2
2
 
3
3
 
4
+ == Release 1.2.0
5
+
6
+ * ADDED: Rails 3 compatibility.
7
+
8
+ * CHANGED: Simplified tabs_tag helper by moving the rendering logic into TabsOnRails::Tabs#render.
9
+
10
+ * CHANGED: TabsOnRails::Tabs::Builder (and all child classes) now has full access to @options hash.
11
+
12
+
4
13
  == Release 1.1.0
5
14
 
6
15
  * FIXED: Incompatibility with release < 1.0.0 caused by open_tabs and close_tabs methods changes compared to 0.8.0.
data/README.rdoc CHANGED
@@ -9,19 +9,26 @@ It provides helpers for creating tabs with a flexible interface.
9
9
  * Ruby >= 1.8.6
10
10
  * Rails >= 2.2
11
11
 
12
- Note. TabsOnRails doesn't work with Rails 2.1 or previous versions (see {this comment}[http://www.simonecarletti.com/blog/2009/04/tabsonrails/#comment-2901] and {this commit}[http://github.com/weppos/tabs_on_rails/commit/d5ae9f401e3d0acc87251fa8957a8625e90ba4b3]).
12
+ or
13
13
 
14
+ * Rails 3
14
15
 
15
- == Rails Installation
16
+ Warning: TabsOnRails doesn't work with Rails 2.1 or previous versions
17
+ (see {this comment}[http://www.simonecarletti.com/blog/2009/04/tabsonrails/#comment-2901]
18
+ and {this commit}[http://github.com/weppos/tabs_on_rails/commit/d5ae9f401e3d0acc87251fa8957a8625e90ba4b3]).
16
19
 
17
- === As a Gem
18
20
 
19
- This is the preferred way to install TabsOnRails and the best way if you want install a stable version.
21
+ == Installation
22
+
23
+ === As a Gem (Rails 2)
24
+
25
+ RubyGems is the preferred way to install TabsOnRails and the best way if you want install a stable version.
20
26
  The GEM is hosted on {RubyGems}[http://rubygems.org/gems/tabs_on_rails].
21
27
 
22
28
  $ gem install tabs_on_rails
23
29
 
24
- With Rails >= 2.2, you can specify the GEM dependency in your environment.rb file so that Rails will automatically check the requirement on startup.
30
+ With Rails >= 2.2, specify the Gem dependency in your environment.rb file so that Rails
31
+ will automatically check the requirement on startup.
25
32
 
26
33
  Rails::Initializer.run do |config|
27
34
 
@@ -32,12 +39,19 @@ With Rails >= 2.2, you can specify the GEM dependency in your environment.rb fil
32
39
 
33
40
  end
34
41
 
35
- === As a Plugin
42
+ With Rails 3, specify the Gem dependency in the {Bundler}[http://gembundler.com/] Gemfile.
43
+
44
+ gem "tabs_on_rails"
36
45
 
37
- This is the preferred way if you want to live on the edge and install a development version.
46
+
47
+ === As a Plugin
38
48
 
39
49
  $ script/plugin install git://github.com/weppos/tabs_on_rails.git
40
50
 
51
+ Warning: this method is deprecated and will be removed in a future version.
52
+ Use Bundler and the {:git option}[http://gembundler.com/v1.0/git.html]
53
+ if you want to grab the latest version from the Git repository.
54
+
41
55
 
42
56
  == Usage
43
57
 
@@ -67,7 +81,7 @@ when you want to mark a tab as the current tab.
67
81
  set_tab :dashboard
68
82
  end
69
83
 
70
- Now, if the action belongs to DashboardController, the template will automatically render the following HTML code.
84
+ Now, if the action belongs to <tt>DashboardController</tt>, the template will automatically render the following HTML code.
71
85
 
72
86
  <ul>
73
87
  <li><a href="/">Homepage</a></li>
@@ -84,7 +98,7 @@ Use the <tt>current_tab</tt> helper method if you need to access the value of cu
84
98
  # In your view
85
99
  <p>The name of current tab is <%= current_tab %>.</p>
86
100
 
87
- The open_tag can be customized with the `:open_tabs` option.
101
+ The open_tag can be customized with the <tt>:open_tabs</tt> option.
88
102
 
89
103
  <% tabs_tag :open_tabs => { :id => "tabs", :class => "cool" } do |tab| %>
90
104
  <%= tab.home 'Homepage', root_path %>
@@ -98,7 +112,7 @@ The open_tag can be customized with the `:open_tabs` option.
98
112
  <li><a href="/account">Account</a></li>
99
113
  </ul>
100
114
 
101
- Further customizations require a custom Builder (see below).
115
+ Further customizations require a custom <tt>Builder</tt> (see below).
102
116
 
103
117
 
104
118
  == Restricting set_tab scope
data/Rakefile CHANGED
@@ -82,7 +82,7 @@ task :gemspec do
82
82
  File.open(file, "w") {|f| f << spec.to_ruby }
83
83
  end
84
84
 
85
- desc "Remove any temporary products, including gemspec."
85
+ desc "Remove any temporary products, including gemspec"
86
86
  task :clean => [:clobber] do
87
87
  rm "#{spec.name}.gemspec"
88
88
  end
@@ -96,7 +96,7 @@ task :package => [:gemspec]
96
96
  begin
97
97
  require "rcov/rcovtask"
98
98
 
99
- desc "Create a code coverage report."
99
+ desc "Create a code coverage report"
100
100
  Rcov::RcovTask.new do |t|
101
101
  t.test_files = FileList["test/**/*_test.rb"]
102
102
  t.ruby_opts << "-Itest -x mocha,rcov,Rakefile"
@@ -118,3 +118,9 @@ begin
118
118
  rescue LoadError
119
119
  puts "CodeStatistics (Rails) is not available"
120
120
  end
121
+
122
+ desc "Publish documentation to the site"
123
+ task :publish_rdoc => [:clobber_rdoc, :rdoc] do
124
+ ENV["username"] || raise(ArgumentError, "Missing ssh username")
125
+ sh "rsync -avz --delete rdoc/ #{ENV["username"]}@code:/var/www/apps/code/#{PKG_NAME}/api"
126
+ end
data/init.rb CHANGED
@@ -1 +1 @@
1
- require File.join(File.dirname(__FILE__), 'rails', 'init')
1
+ require File.join(File.dirname(__FILE__), "rails", "init")
@@ -1,8 +1,8 @@
1
- #
1
+ #
2
2
  # = Tabs on Rails
3
3
  #
4
4
  # A simple Ruby on Rails plugin for creating and managing Tabs.
5
- #
5
+ #
6
6
  #
7
7
  # Category:: Rails
8
8
  # Package:: TabsOnRails
@@ -10,16 +10,16 @@
10
10
  # License:: MIT License
11
11
  #
12
12
  #--
13
- #
13
+ #
14
14
  #++
15
15
 
16
16
 
17
17
  module TabsOnRails
18
-
18
+
19
19
  module ControllerMixin
20
-
20
+
21
21
  def self.included(base)
22
- base.extend ClassMethods
22
+ base.extend ClassMethods
23
23
  base.class_eval do
24
24
  include InstanceMethods
25
25
  helper HelperMethods
@@ -43,8 +43,8 @@ module TabsOnRails
43
43
  # For example, you can set the tab only for a restricted group of actions in the same controller
44
44
  # using the <tt>:only</tt> and <tt>:except</tt> options.
45
45
  #
46
- # ==== Examples
47
- #
46
+ # Examples
47
+ #
48
48
  # set_tab :foo
49
49
  # set_tab :foo, :except => :new
50
50
  # set_tab :foo, :only => [ :index, :show ]
@@ -55,7 +55,7 @@ module TabsOnRails
55
55
  def set_tab(*args)
56
56
  options = args.extract_options!
57
57
  name, namespace = args
58
-
58
+
59
59
  before_filter(options) do |controller|
60
60
  controller.send(:set_tab, name, namespace)
61
61
  end
@@ -69,7 +69,7 @@ module TabsOnRails
69
69
  # Sets the value for current tab to given name.
70
70
  # If you need to manage multiple tabs, then you can pass an optional namespace.
71
71
  #
72
- # ==== Examples
72
+ # Examples
73
73
  #
74
74
  # set_tab :homepage
75
75
  # set_tab :dashboard, :menu
@@ -82,7 +82,7 @@ module TabsOnRails
82
82
  # or nil if no tab has been set before.
83
83
  # You can pass <tt>namespace</tt> to get the value of current tab for a different namespace.
84
84
  #
85
- # ==== Examples
85
+ # Examples
86
86
  #
87
87
  # current_tab # => nil
88
88
  # current_tab :menu # => nil
@@ -113,19 +113,71 @@ module TabsOnRails
113
113
 
114
114
  module HelperMethods
115
115
 
116
+ # In your template use the <tt>tabs_tag</tt> helper to create your tab.
117
+ #
118
+ # <% tabs_tag do |tab| %>
119
+ # <%= tab.home 'Homepage', root_path %>
120
+ # <%= tab.dashboard 'Dashboard', dashboard_path %>
121
+ # <%= tab.account 'Account', account_path %>
122
+ # <% end %>
123
+ #
124
+ # The example above produces the following HTML output.
125
+ #
126
+ # <ul>
127
+ # <li><a href="/">Homepage</a></li>
128
+ # <li><a href="/dashboard">Dashboard</a></li>
129
+ # <li><a href="/account">Account</a></li>
130
+ # </ul>
131
+ #
132
+ # The usage is similar to the Rails route file.
133
+ # You create named tabs with the syntax <tt>tab.name_of_tab</tt>.
134
+ #
135
+ # The name you use creating a tab is the same you're going to refer to in your controller
136
+ # when you want to mark a tab as the current tab.
137
+ #
138
+ # class DashboardController < ApplicationController
139
+ # set_tab :dashboard
140
+ # end
141
+ #
142
+ # Now, if the action belongs to <tt>DashboardController</tt>,
143
+ # the template will automatically render the following HTML code.
144
+ #
145
+ # <ul>
146
+ # <li><a href="/">Homepage</a></li>
147
+ # <li><span>Dashboard</span></li>
148
+ # <li><a href="/account">Account</a></li>
149
+ # </ul>
150
+ #
151
+ # Use the <tt>current_tab</tt> helper method if you need to access
152
+ # the value of current tab in your controller or template.
153
+ #
154
+ # class DashboardController < ApplicationController
155
+ # set_tab :dashboard
156
+ # end
157
+ #
158
+ # # In your view
159
+ # <p>The name of current tab is <%= current_tab %>.</p>
160
+ #
161
+ # The open_tag can be customized with the <tt>:open_tabs</tt> option.
162
+ #
163
+ # <% tabs_tag :open_tabs => { :id => "tabs", :class => "cool" } do |tab| %>
164
+ # <%= tab.home 'Homepage', root_path %>
165
+ # <%= tab.dashboard 'Dashboard', dashboard_path %>
166
+ # <%= tab.account 'Account', account_path %>
167
+ # <% end %>
168
+ #
169
+ # <ul id="tabs" class="cool">
170
+ # <li><a href="/">Homepage</a></li>
171
+ # <li><a href="/dashboard">Dashboard</a></li>
172
+ # <li><a href="/account">Account</a></li>
173
+ # </ul>
174
+ #
175
+ # Further customizations require a custom <tt>Builder</tt>.
176
+ #
116
177
  def tabs_tag(options = {}, &block)
117
- raise LocalJumpError, "no block given" unless block_given?
118
-
119
- options = options.dup
120
- open_tabs_options = options.delete(:open_tabs) || {}
121
- close_tabs_options = options.delete(:close_tabs) || {}
122
- tabs = Tabs.new(self, { :namespace => :default }.merge(options))
123
-
124
- concat(tabs.open_tabs(open_tabs_options).to_s)
125
- yield tabs
126
- concat(tabs.close_tabs(close_tabs_options).to_s)
178
+ Tabs.new(self, { :namespace => :default }.merge(options)).render(&block)
127
179
  end
128
180
 
129
181
  end
130
182
  end
131
- end
183
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # = Tabs on Rails
3
+ #
4
+ # A simple Ruby on Rails plugin for creating and managing Tabs.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: TabsOnRails
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # License:: MIT License
11
+ #
12
+ #--
13
+ #
14
+ #++
15
+
16
+
17
+ module TabsOnRails
18
+
19
+ if defined? Rails::Railtie
20
+ require "rails"
21
+
22
+ class Railtie < Rails::Railtie
23
+ initializer "tabs_on_rails.initialize" do
24
+ ActiveSupport.on_load :action_controller do
25
+ TabsOnRails::Railtie.init
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ class Railtie
33
+
34
+ def self.rails_version
35
+ @@rails_version ||= Rails::VERSION::STRING rescue "2.2"
36
+ end
37
+
38
+ def self.init
39
+ ActionController::Base.send :include, TabsOnRails::ControllerMixin
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -22,24 +22,32 @@ module TabsOnRails
22
22
  #
23
23
  # The Builder class represents the interface for any custom Builder.
24
24
  #
25
- # To create a custom Builder extend this class
25
+ # To create a custom Builder, extend this class
26
26
  # and implement the following abstract methods:
27
27
  #
28
- # * tab_for(args)
28
+ # * <tt>tab_for</tt>
29
+ #
30
+ # Optionally, you can override the following methods to customize
31
+ # the Builder behavior:
32
+ #
33
+ # * <tt>open_tabs</tt>
34
+ # * <tt>close_tabs</tt>
29
35
  #
30
36
  class Builder
31
37
 
32
- # Initializes a new builder with +context+.
38
+ # Initializes a new builder with the given hash of <tt>options</tt>,
39
+ # providing the current Rails template as <tt>context</tt>.
33
40
  #
34
- # Note. You should not overwrite this method to prevent incompatibility with future versions.
41
+ # Warning: You should not override this method to prevent incompatibility with future versions.
35
42
  def initialize(context, options = {})
36
43
  @context = context
37
44
  @namespace = options.delete(:namespace) || :default
45
+ @options = options
38
46
  end
39
47
 
40
48
  # Returns true if +tab+ is the +current_tab+.
41
49
  #
42
- # ==== Examples
50
+ # Examples
43
51
  #
44
52
  # class MyController < ApplicationController
45
53
  # tab :foo
@@ -56,24 +64,21 @@ module TabsOnRails
56
64
 
57
65
 
58
66
  # Creates and returns a tab with given +args+.
59
- #
60
- # ==== Raises
61
- #
62
- # NotImplemented:: you should implement this method in your custom Builder.
63
- #
67
+ #
68
+ # Raises NotImplemented: you should implement this method in your custom Builder.
64
69
  def tab_for(*args)
65
70
  raise NotImplementedError
66
71
  end
67
72
 
68
- # Overwrite this method to use a custom open tag for your tabs.
73
+ # Override this method to use a custom open tag for your tabs.
69
74
  def open_tabs(*args)
70
75
  end
71
76
 
72
- # Overwrite this method to use a custom close tag for your tabs.
77
+ # Override this method to use a custom close tag for your tabs.
73
78
  def close_tabs(*args)
74
79
  end
75
80
 
76
81
  end
77
82
 
78
83
  end
79
- end
84
+ end
@@ -21,11 +21,9 @@ module TabsOnRails
21
21
  # = Tabs Builder
22
22
  #
23
23
  # The TabsBuilder is and example of custom Builder.
24
- # It creates a new tab
25
24
  #
26
25
  class TabsBuilder < Builder
27
26
 
28
- # Implements Builder#tab_for.
29
27
  # Returns a link_to +tab+ with +name+ and +options+ if +tab+ is not the current tab,
30
28
  # a simple tab name wrapped by a span tag otherwise.
31
29
  #
@@ -37,6 +35,8 @@ module TabsOnRails
37
35
  # tab_for :bar, 'Bar', bar_path
38
36
  # # => <li><a href="/link/to/bar">Bar</a></li>
39
37
  #
38
+ # Implements Builder#tab_for.
39
+ #
40
40
  def tab_for(tab, name, options)
41
41
  content = @context.link_to_unless(current_tab?(tab), name, options) do
42
42
  @context.content_tag(:span, name)
@@ -44,10 +44,9 @@ module TabsOnRails
44
44
  @context.content_tag(:li, content)
45
45
  end
46
46
 
47
- # Implements Builder#open_tabs.
48
- #
49
47
  # Returns an unordered list open tag.
50
- # The <tt>options</tt> is used to customize the HTML attributes of the tag.
48
+ #
49
+ # The <tt>options</tt> hash is used to customize the HTML attributes of the tag.
51
50
  #
52
51
  # open_tag
53
52
  # # => "<ul>"
@@ -55,15 +54,16 @@ module TabsOnRails
55
54
  # open_tag :class => "centered"
56
55
  # # => "<ul class=\"centered\">"
57
56
  #
57
+ # Implements Builder#open_tabs.
58
+ #
58
59
  def open_tabs(options = {})
59
60
  @context.tag("ul", options, open = true)
60
61
  end
61
62
 
62
- # Implements Builder#close_tabs.
63
- #
64
63
  # Returns an unordered list close tag.
65
- # The <tt>options</tt> hash is ignored. It exists only for
66
- # coeherence with the parent Builder API.
64
+ #
65
+ # The <tt>options</tt> hash is ignored here.
66
+ # It exists only for coherence with the parent Builder API.
67
67
  #
68
68
  # close_tag
69
69
  # # => "</ul>"
@@ -71,11 +71,13 @@ module TabsOnRails
71
71
  # close_tag :class => "centered"
72
72
  # # => "</ul>"
73
73
  #
74
+ # Implements Builder#close_tabs.
75
+ #
74
76
  def close_tabs(options = {})
75
- "</ul>"
77
+ "</ul>".try(:html_safe)
76
78
  end
77
79
 
78
80
  end
79
81
 
80
82
  end
81
- end
83
+ end
@@ -22,9 +22,10 @@ module TabsOnRails
22
22
 
23
23
  class Tabs
24
24
 
25
- def initialize(context, options = {}, &block)
25
+ def initialize(context, options = {})
26
26
  @context = context
27
27
  @builder = (options.delete(:builder) || TabsBuilder).new(@context, options)
28
+ @options = options
28
29
  end
29
30
 
30
31
  %w(open_tabs close_tabs).each do |name|
@@ -45,7 +46,27 @@ module TabsOnRails
45
46
  def method_missing(*args)
46
47
  @builder.tab_for(*args)
47
48
  end
48
-
49
+
50
+ def render(&block)
51
+ raise LocalJumpError, "no block given" unless block_given?
52
+
53
+ options = @options.dup
54
+ open_tabs_options = options.delete(:open_tabs) || {}
55
+ close_tabs_options = options.delete(:close_tabs) || {}
56
+
57
+ if Railtie.rails_version < "3"
58
+ @context.concat(open_tabs(open_tabs_options).to_s)
59
+ yield self
60
+ @context.concat(close_tabs(close_tabs_options).to_s)
61
+ else
62
+ "".tap do |html|
63
+ html << open_tabs(open_tabs_options).to_s
64
+ html << capture(self, &block)
65
+ html << close_tabs(close_tabs_options).to_s
66
+ end.html_safe
67
+ end
68
+ end
69
+
49
70
  end
50
71
 
51
- end
72
+ end
@@ -18,7 +18,7 @@ module TabsOnRails
18
18
 
19
19
  module Version
20
20
  MAJOR = 1
21
- MINOR = 1
21
+ MINOR = 2
22
22
  PATCH = 0
23
23
  BUILD = nil
24
24
 
data/lib/tabs_on_rails.rb CHANGED
@@ -16,13 +16,13 @@
16
16
 
17
17
  require 'tabs_on_rails/controller_mixin'
18
18
  require 'tabs_on_rails/tabs'
19
+ require 'tabs_on_rails/railtie'
19
20
  require 'tabs_on_rails/version'
20
21
 
21
22
 
22
23
  module TabsOnRails
23
24
 
24
- NAME = 'Tabs on Rails'
25
- GEM = 'tabs_on_rails'
26
- AUTHOR = 'Simone Carletti <weppos@weppos.net>'
27
-
28
- end
25
+ NAME = "Tabs on Rails"
26
+ GEM = "tabs_on_rails"
27
+
28
+ end
data/rails/init.rb CHANGED
@@ -1,3 +1,20 @@
1
- require 'tabs_on_rails'
1
+ #
2
+ # = Tabs on Rails
3
+ #
4
+ # A simple Ruby on Rails plugin for creating and managing Tabs.
5
+ #
6
+ #
7
+ # Category:: Rails
8
+ # Package:: TabsOnRails
9
+ # Author:: Simone Carletti <weppos@weppos.net>
10
+ # License:: MIT License
11
+ #
12
+ #--
13
+ #
14
+ #++
2
15
 
3
- ActionController::Base.send :include, TabsOnRails::ControllerMixin
16
+
17
+ require "tabs_on_rails"
18
+
19
+
20
+ TabsOnRails::Railtie.init
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  }
12
12
  s.email = %q{weppos@weppos.net}
13
13
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc"]
14
- s.files = ["Rakefile", "init.rb", "CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc", "tabs_on_rails.gemspec", "test/controller_mixin_test.rb", "test/fixtures", "test/fixtures/mixin", "test/fixtures/mixin/default.html.erb", "test/fixtures/mixin/with_open_close_tabs.html.erb", "test/tabs", "test/tabs/builder_test.rb", "test/tabs/tabs_builder_test.rb", "test/tabs_test.rb", "test/test_helper.rb", "lib/tabs_on_rails", "lib/tabs_on_rails/controller_mixin.rb", "lib/tabs_on_rails/tabs", "lib/tabs_on_rails/tabs/builder.rb", "lib/tabs_on_rails/tabs/tabs_builder.rb", "lib/tabs_on_rails/tabs.rb", "lib/tabs_on_rails/version.rb", "lib/tabs_on_rails.rb", "rails/init.rb"]
14
+ s.files = ["Rakefile", "init.rb", "CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc", "tabs_on_rails.gemspec", "test/controller_mixin_test.rb", "test/fixtures/mixin/default.html.erb", "test/fixtures/mixin/with_open_close_tabs.html.erb", "test/tabs/builder_test.rb", "test/tabs/tabs_builder_test.rb", "test/tabs_test.rb", "test/test_helper.rb", "lib/tabs_on_rails/controller_mixin.rb", "lib/tabs_on_rails/tabs/builder.rb", "lib/tabs_on_rails/tabs/tabs_builder.rb", "lib/tabs_on_rails/tabs.rb", "lib/tabs_on_rails/version.rb", "lib/tabs_on_rails.rb", "rails/init.rb"]
15
15
  s.homepage = %q{http://www.simonecarletti.com/code/tabs_on_rails}
16
16
  s.rdoc_options = ["--main", "README.rdoc"]
17
17
  s.require_paths = ["lib"]
@@ -24,42 +24,59 @@ class BuilderTest < ActiveSupport::TestCase
24
24
  end
25
25
 
26
26
 
27
- def test_initialize_should_require_context
27
+ def test_initialize_without_context
28
28
  assert_raise(ArgumentError) { TabsOnRails::Tabs::Builder.new }
29
- assert_nothing_raised { TabsOnRails::Tabs::Builder.new(@template) }
30
29
  end
31
30
 
32
- def test_initialize_should_allow_options
33
- assert_nothing_raised { TabsOnRails::Tabs::Builder.new(@template, { :namespace => 'foonamespace' }) }
31
+ def test_initialize_with_context
32
+ assert_nothing_raised { TabsOnRails::Tabs::Builder.new(@template) }
33
+ end
34
+
35
+ def test_initialize_with_options
36
+ assert_nothing_raised { TabsOnRails::Tabs::Builder.new(@template, { :namespace => "foonamespace" }) }
34
37
  end
35
38
 
36
39
  def test_initialize_should_set_context
37
- assert_equal(@template, @builder.instance_variable_get(:'@context'))
40
+ assert_equal @template, @builder.instance_variable_get(:"@context")
38
41
  end
39
42
 
40
43
  def test_initialize_should_set_namespace
41
- @builder = TabsOnRails::Tabs::Builder.new(@template)
42
- assert_equal(:default, @builder.instance_variable_get(:'@namespace'))
44
+ @builder = TabsOnRails::Tabs::Builder.new(@template)
45
+ assert_equal :default, @builder.instance_variable_get(:"@namespace")
43
46
 
44
- @builder = TabsOnRails::Tabs::Builder.new(@template, :namespace => :foobar)
45
- assert_equal(:foobar, @builder.instance_variable_get(:'@namespace'))
47
+ @builder = TabsOnRails::Tabs::Builder.new(@template, :namespace => :foobar)
48
+ assert_equal :foobar, @builder.instance_variable_get(:"@namespace")
49
+ end
50
+
51
+ def test_initialize_should_set_options
52
+ @builder = TabsOnRails::Tabs::Builder.new(@template)
53
+ assert_equal({}, @builder.instance_variable_get(:"@options"))
54
+
55
+ @builder = TabsOnRails::Tabs::Builder.new(@template, :weather => :sunny)
56
+ assert_equal({ :weather => :sunny }, @builder.instance_variable_get(:"@options"))
57
+
58
+ @builder = TabsOnRails::Tabs::Builder.new(@template, :namespace => :foobar, :weather => :sunny)
59
+ assert_equal({ :weather => :sunny }, @builder.instance_variable_get(:"@options"))
60
+
61
+ @builder = TabsOnRails::Tabs::Builder.new(@template, :namespace => :foobar)
62
+ assert_equal({}, @builder.instance_variable_get(:"@options"))
46
63
  end
47
64
 
48
65
 
49
66
  def test_current_tab
50
- @builder = TabsOnRails::Tabs::Builder.new(@template)
51
- assert( @builder.current_tab?(:dashboard))
52
- assert( @builder.current_tab?('dashboard'))
53
- assert(!@builder.current_tab?(:welcome))
54
- assert(!@builder.current_tab?('welcome'))
67
+ @builder = TabsOnRails::Tabs::Builder.new(@template)
68
+ assert @builder.current_tab?(:dashboard)
69
+ assert @builder.current_tab?("dashboard")
70
+ assert !@builder.current_tab?(:welcome)
71
+ assert !@builder.current_tab?("welcome")
55
72
  end
56
73
 
57
74
  def test_current_tab_with_namespace
58
- @builder = TabsOnRails::Tabs::Builder.new(@template, :namespace => :foospace)
59
- assert( @builder.current_tab?(:footab))
60
- assert( @builder.current_tab?('footab'))
61
- assert(!@builder.current_tab?(:dashboard))
62
- assert(!@builder.current_tab?('dashboard'))
75
+ @builder = TabsOnRails::Tabs::Builder.new(@template, :namespace => :foospace)
76
+ assert @builder.current_tab?(:footab)
77
+ assert @builder.current_tab?("footab")
78
+ assert !@builder.current_tab?(:dashboard)
79
+ assert !@builder.current_tab?("dashboard")
63
80
  end
64
81
 
65
82
 
@@ -82,8 +99,8 @@ class BuilderTest < ActiveSupport::TestCase
82
99
 
83
100
  def test_tab_for_should_raise_not_implemented_error
84
101
  assert_raise(NotImplementedError) { @builder.tab_for }
85
- assert_raise(NotImplementedError) { @builder.tab_for('foo') }
86
- assert_raise(NotImplementedError) { @builder.tab_for('foo', 'bar') }
102
+ assert_raise(NotImplementedError) { @builder.tab_for("foo") }
103
+ assert_raise(NotImplementedError) { @builder.tab_for("foo", "bar") }
87
104
  end
88
-
89
- end
105
+
106
+ end
@@ -20,39 +20,44 @@ class TabsBuilderTest < ActionView::TestCase
20
20
 
21
21
  def setup
22
22
  @template = Template.new
23
- @builder = TabsOnRails::Tabs::TabsBuilder.new(@template)
23
+ @klass = TabsOnRails::Tabs::TabsBuilder
24
+ @builder = @klass.new(@template)
25
+ end
26
+
27
+ def test_should_extend_builder
28
+ assert_equal TabsOnRails::Tabs::Builder, @klass.superclass
24
29
  end
25
30
 
26
31
 
27
32
  def test_open_tabs
28
- assert_equal '<ul>', @builder.open_tabs
33
+ assert_dom_equal %Q{<ul>}, @builder.open_tabs
29
34
  end
30
35
 
31
36
  def test_open_tabs_with_options
32
- assert_equal '<ul style="foo">', @builder.open_tabs(:style => "foo")
37
+ assert_dom_equal %Q{<ul style="foo">}, @builder.open_tabs(:style => "foo")
33
38
  end
34
39
 
35
40
  def test_close_tabs
36
- assert_equal "</ul>", @builder.close_tabs
41
+ assert_dom_equal %Q{</ul>}, @builder.close_tabs
37
42
  end
38
43
 
39
44
  def test_close_tabs_with_options
40
- assert_equal '</ul>', @builder.close_tabs(:foo => "bar")
45
+ assert_dom_equal %Q{</ul>}, @builder.close_tabs(:foo => "bar")
41
46
  end
42
47
 
43
48
 
44
- def test_should_implement_builder
45
- assert_equal(TabsOnRails::Tabs::Builder, TabsOnRails::Tabs::TabsBuilder.superclass)
46
- end
47
-
48
49
  def test_tab_for_should_return_link_to_unless_current_tab
49
- assert_dom_equal('<li><a href="#">Welcome</a></li>', @builder.tab_for(:welcome, 'Welcome', '#'))
50
- assert_dom_equal('<li><a href="http://foobar.com/">Foo Bar</a></li>', @builder.tab_for(:welcome, 'Foo Bar', 'http://foobar.com/'))
50
+ assert_dom_equal %Q{<li><a href="#">Welcome</a></li>},
51
+ @builder.tab_for(:welcome, 'Welcome', '#')
52
+ assert_dom_equal %Q{<li><a href="http://foobar.com/">Foo Bar</a></li>},
53
+ @builder.tab_for(:welcome, 'Foo Bar', 'http://foobar.com/')
51
54
  end
52
55
 
53
56
  def test_tab_for_should_return_span_if_current_tab
54
- assert_dom_equal('<li><span>Dashboard</span></li>', @builder.tab_for(:dashboard, 'Dashboard', '#'))
55
- assert_dom_equal('<li><span>Foo Bar</span></li>', @builder.tab_for(:dashboard, 'Foo Bar', '#'))
57
+ assert_dom_equal %Q{<li><span>Dashboard</span></li>},
58
+ @builder.tab_for(:dashboard, 'Dashboard', '#')
59
+ assert_dom_equal %Q{<li><span>Foo Bar</span></li>},
60
+ @builder.tab_for(:dashboard, 'Foo Bar', '#')
56
61
  end
57
62
 
58
63
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabs_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simone Carletti
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-09 00:00:00 +02:00
18
+ date: 2010-08-10 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -44,6 +44,7 @@ files:
44
44
  - test/tabs_test.rb
45
45
  - test/test_helper.rb
46
46
  - lib/tabs_on_rails/controller_mixin.rb
47
+ - lib/tabs_on_rails/railtie.rb
47
48
  - lib/tabs_on_rails/tabs/builder.rb
48
49
  - lib/tabs_on_rails/tabs/tabs_builder.rb
49
50
  - lib/tabs_on_rails/tabs.rb