tabit 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 129d9efb46d3e25453431f2e3d7c82858c42c593
4
+ data.tar.gz: 35fc966308f0372bab9491f79556f1ce83ed5511
5
+ SHA512:
6
+ metadata.gz: a3d1d1829abd42ede1cb35869c1305d4eca8b6c15e74478de236b6e2a09f8f8de4db8bfed4fce17da2065383721cfb3621b6bbd939d8b0d34771ac05db2b2337
7
+ data.tar.gz: fbdc52b570a3389c97a73a2e7468dee7fcd0cf50f6f051d330c70ab3d1564ff6d07a41690fa4c7ad640f4c7456ded6e11f29d0a1f6eddc07579fbde09c7d8780
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## [1.0.0](https://github.com/webhippie/tabit/releases/tag/v0.1.0) - 2015-07-20
4
+
5
+ * First official stable release
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2012-2015 Webhippie <http://www.webhippie.de>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,28 +1,54 @@
1
- # Tabit [![Build Status](https://secure.travis-ci.org/tbpro/tabit.png)](https://secure.travis-ci.org/#!/tbpro/tabit)
1
+ # Tabit
2
+
3
+ [![Gem Version](http://img.shields.io/gem/v/tabit.svg)](https://rubygems.org/gems/tabit)
4
+ [![Build Status](https://secure.travis-ci.org/webhippie/tabit.svg)](https://travis-ci.org/webhippie/tabit)
5
+ [![Code Climate](https://codeclimate.com/github/webhippie/tabit.svg)](https://codeclimate.com/github/webhippie/tabit)
6
+ [![Test Coverage](https://codeclimate.com/github/webhippie/tabit/badges/coverage.svg)](https://codeclimate.com/github/webhippie/tabit)
7
+ [![Dependency Status](https://gemnasium.com/webhippie/tabit.svg)](https://gemnasium.com/webhippie/tabit)
2
8
 
3
9
  Tabit is a simple tab menu generator. It depends on `active_link_to`
4
10
  helper. If you dont know how to set an item active take a look at it first.
5
11
  The generated source is compatible to bootstrap tabs with dropdowns.
6
12
 
7
- ## Install
8
13
 
9
- ```ruby
10
- gem 'tabit'
11
- ```
14
+ ## Installation
15
+
16
+ ```ruby
17
+ gem "tabit", "~> 1.0.0"
18
+ ```
19
+
12
20
 
13
21
  ## Usage
14
22
 
15
- ```ruby
16
- = tabit :class => 'nav nav-tabs' do |t1|
17
- - t1.heading 'Header'
18
- - t1.add 'Videos', videos_path
19
- - t1.divider
20
- - t1.add 'Movies', movies_path, :active => /movies(\/\d)*(\/edit)*$/
21
- - t1.add 'Movies, movies_path, :active => :exclusive, :type => :dropdown do |t2|
22
- - t2.add 'Add movie', new_movie_path, :active => :exclusive
23
+ ```ruby
24
+ = tabit :class => "nav nav-tabs" do |t1|
25
+ - t1.heading "Header"
26
+ - t1.add "Videos", videos_path
27
+ - t1.divider
28
+ - t1.add "Movies", movies_path, active: /movies(\/\d)*(\/edit)*$/
29
+ - t1.add "Movies, movies_path, active: :exclusive, type: :dropdown do |t2|
30
+ - t2.add "Add movie", new_movie_path, active: :exclusive
23
31
  ```
24
32
 
25
- ## Credits
26
33
 
27
- Copyright (c) 20112 Thomas Boerger Programmierung <http://www.tbpro.de>
34
+ ## Contributing
35
+
36
+ Fork -> Patch -> Spec -> Push -> Pull Request
37
+
38
+
39
+ ## Authors
40
+
41
+ * [Thomas Boerger](https://github.com/tboerger)
42
+ * [Other contributors](https://github.com/webhippie/tabit/graphs/contributors)
28
43
 
44
+
45
+ ## License
46
+
47
+ MIT
48
+
49
+
50
+ ## Copyright
51
+
52
+ ```
53
+ Copyright (c) 2012-2015 Webhippie <http://www.webhippie.de>
54
+ ```
@@ -1,23 +1,55 @@
1
- # -*- encoding : utf-8 -*-
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright (c) 2012-2015 Webhippie <http://www.webhippie.de>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
2
24
 
3
- require 'active_link_to'
25
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
4
26
 
5
- module Tabit
6
- autoload :Version, 'tabit/version'
7
- autoload :Config, 'tabit/config'
8
- autoload :Railtie, 'tabit/railtie'
9
- autoload :Helper, 'tabit/helper'
10
- autoload :Builder, 'tabit/builder'
11
- autoload :Item, 'tabit/item'
27
+ if File.exist? ENV["BUNDLE_GEMFILE"]
28
+ require "bundler"
29
+ Bundler.setup(:default)
30
+ else
31
+ gem "active_link_to", version: ">= 1.0.0"
32
+ end
12
33
 
13
- def self.configure(&block)
14
- @configuration = Tabit::Config.new(&block)
15
- end
34
+ require "active_link_to"
16
35
 
17
- def self.configuration
18
- @configuration ||= Tabit::Config.new
36
+ class Tabit
37
+ class << self
38
+ def configure(&block)
39
+ @configuration = Config.new(&block)
40
+ end
41
+
42
+ def configuration
43
+ @configuration ||= Config.new
44
+ end
19
45
  end
20
46
  end
21
47
 
22
- require 'tabit/railtie' if defined? Rails
23
- require 'tabit/cell' if defined? Cell
48
+ require_relative "tabit/version"
49
+ require_relative "tabit/item"
50
+ require_relative "tabit/helper"
51
+ require_relative "tabit/builder"
52
+ require_relative "tabit/config"
53
+
54
+ require_relative "tabit/railtie" if defined? Rails
55
+ require_relative "tabit/cell" if defined? Cell
@@ -1,21 +1,50 @@
1
- # -*- encoding : utf-8 -*-
2
- module Tabit
3
- class Builder < Item
4
- def initialize(template, options, &block)
5
- @@template = template
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright (c) 2012-2015 Webhippie <http://www.webhippie.de>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
6
24
 
7
- @children = []
8
- @options = options
25
+ class Tabit
26
+ class Builder < Item
27
+ def initialize(template, options)
28
+ self.template = template
29
+ self.options = options
9
30
 
10
31
  yield self if block_given?
11
32
  end
12
33
 
13
34
  def to_s
35
+ current_options = options
36
+ current_options.delete :outer
37
+ current_options.delete :inner
38
+
14
39
  template.content_tag(
15
40
  :ul,
16
41
  children.collect(&:to_s).join.html_safe,
17
- options
42
+ current_options
18
43
  )
19
44
  end
45
+
46
+ def children
47
+ @children ||= []
48
+ end
20
49
  end
21
50
  end
@@ -1,5 +1,28 @@
1
- # -*- encoding : utf-8 -*-
2
- module Cell
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright (c) 2012-2015 Webhippie <http://www.webhippie.de>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+
25
+ class Cell
3
26
  class Rails
4
27
  helper Tabit::Helper
5
28
  end
@@ -1,8 +1,32 @@
1
- # -*- encoding : utf-8 -*-
2
- module Tabit
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright (c) 2012-2015 Webhippie <http://www.webhippie.de>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+
25
+ class Tabit
3
26
  class Config
4
27
  attr_accessor :builder_class
5
28
 
29
+ attr_accessor :caret_element
6
30
  attr_accessor :active_scope
7
31
  attr_accessor :active_detect
8
32
  attr_accessor :active_class
@@ -10,13 +34,14 @@ module Tabit
10
34
  attr_accessor :divider_class
11
35
 
12
36
  def initialize(&block)
13
- @builder_class = Tabit::Builder
37
+ self.builder_class = Tabit::Builder
14
38
 
15
- @active_scope = :outer
16
- @active_detect = :exclusive
17
- @active_class = 'active'
18
- @heading_class = 'nav-header'
19
- @divider_class = 'divider'
39
+ self.caret_element = :b
40
+ self.active_scope = :outer
41
+ self.active_detect = :exclusive
42
+ self.active_class = "active"
43
+ self.heading_class = "nav-header"
44
+ self.divider_class = "divider"
20
45
 
21
46
  instance_eval(&block) if block_given?
22
47
  end
@@ -1,5 +1,28 @@
1
- # -*- encoding : utf-8 -*-
2
- module Tabit
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright (c) 2012-2015 Webhippie <http://www.webhippie.de>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+
25
+ class Tabit
3
26
  module Helper
4
27
  include ActionView::Helpers::TagHelper
5
28
  include ActionView::Helpers::UrlHelper
@@ -11,8 +34,9 @@ module Tabit
11
34
  end
12
35
 
13
36
  protected
14
- def configuration
15
- Tabit.configuration
16
- end
37
+
38
+ def configuration
39
+ Tabit.configuration
40
+ end
17
41
  end
18
42
  end
@@ -1,5 +1,28 @@
1
- # -*- encoding : utf-8 -*-
2
- module Tabit
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright (c) 2012-2015 Webhippie <http://www.webhippie.de>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+
25
+ class Tabit
3
26
  class Item
4
27
  include ActionView::Helpers::TagHelper
5
28
  include ActionView::Helpers::UrlHelper
@@ -11,43 +34,38 @@ module Tabit
11
34
  attr_accessor :url
12
35
  attr_accessor :options
13
36
  attr_accessor :active
37
+ attr_accessor :type
14
38
 
15
39
  def initialize(name, url = nil, options = {})
16
- @name, @url, @options = name, url, options
40
+ self.name = name
41
+ self.url = url
42
+ self.options = options
17
43
 
18
- @active = @options.delete(:active) || configuration.active_detect
19
- @type = @options.delete(:type) || :default
20
- @children = []
21
-
22
- @options[:inner] ||= {}
23
- @options[:outer] ||= {}
44
+ self.active = self.options.delete(:active) || configuration.active_detect
45
+ self.type = self.options.delete(:type) || :default
24
46
  end
25
47
 
26
48
  def add(name, url = nil, options = {})
27
49
  Item.new(name, url, options).tap do |adding|
28
- @children << adding
50
+ children.push adding
29
51
  yield adding if block_given?
30
52
  end
31
53
  end
32
54
 
33
55
  def heading(name = nil, options = {})
34
- options[:class] = '' if options[:class].nil?
35
- options[:class] << " #{configuration.heading_class}"
36
- options[:class].strip!
56
+ append_class_to_options configuration.heading_class, options
37
57
 
38
- @children << template.content_tag(
58
+ children.push template.content_tag(
39
59
  :li,
40
60
  name,
41
61
  options
42
62
  )
43
63
  end
44
64
 
45
- def divider(name = nil)
46
- options[:class] = '' if options[:class].nil?
47
- options[:class] << " #{configuration.divider_class}"
48
- options[:class].strip!
65
+ def divider(name = nil, options = {})
66
+ append_class_to_options configuration.divider_class, options
49
67
 
50
- @children << template.content_tag(
68
+ children.push template.content_tag(
51
69
  :li,
52
70
  name,
53
71
  options
@@ -55,53 +73,13 @@ module Tabit
55
73
  end
56
74
 
57
75
  def to_s
58
- clazz = if active?
59
- configuration.active_class
60
- else
61
- ''
62
- end
76
+ configure_item_attrs
63
77
 
64
- case configuration.active_scope
65
- when :outer
66
- options[:outer][:class] = '' if @options[:outer][:class].nil?
67
- options[:outer][:class] << " #{clazz}"
68
- options[:outer][:class].strip!
69
- when :inner
70
- options[:inner][:class] = '' if @options[:inner][:class].nil?
71
- options[:inner][:class] << " #{clazz}"
72
- options[:inner][:class].strip!
73
- end
74
-
75
- case @type
76
- when :dropdown
77
- options[:outer][:class] = '' if @options[:outer][:class].nil?
78
- options[:outer][:class] << " dropdown"
79
- options[:outer][:class].strip!
80
-
81
- options[:inner][:class] = '' if @options[:inner][:class].nil?
82
- options[:inner][:class] << " dropdown-toggle"
83
- options[:inner][:class].strip!
84
-
85
- options[:inner][:data] ||= {}
86
- options[:inner][:data][:toggle] = 'dropdown'
87
-
88
- template.content_tag(
89
- :li,
90
- [
91
- template.link_to([name, content_tag(:b, '', :class => 'caret')].join.html_safe, url, options[:inner]),
92
- output
93
- ].compact.join.html_safe,
94
- options[:outer]
95
- )
96
- else
97
- template.content_tag(
98
- :li,
99
- [
100
- template.link_to(name, url, options[:inner]),
101
- output
102
- ].compact.join.html_safe,
103
- options[:outer]
104
- )
78
+ case type
79
+ when :dropdown
80
+ generate_dropdown_item
81
+ else
82
+ generate_default_item
105
83
  end
106
84
  end
107
85
 
@@ -110,38 +88,119 @@ module Tabit
110
88
  true
111
89
  else
112
90
  children.each do |child|
113
- if child.active?
114
- return true
115
- end
91
+ next if child.is_a? String
92
+ return true if child.active?
116
93
  end
117
94
 
118
95
  false
119
96
  end
120
97
  end
121
98
 
99
+ def children
100
+ @children ||= []
101
+ end
102
+
103
+ def options
104
+ @options[:inner] ||= {}
105
+ @options[:outer] ||= {}
106
+
107
+ @options
108
+ end
109
+
122
110
  protected
123
- def output
124
- if children.empty?
125
- nil
126
- else
127
- case @type
128
- when :dropdown
129
- template.content_tag(
130
- :ul,
131
- children.collect(&:to_s).join.html_safe,
132
- :class => 'dropdown-menu'
133
- )
134
- else
135
- template.content_tag(
136
- :ul,
137
- children.collect(&:to_s).join.html_safe
138
- )
139
- end
140
- end
111
+
112
+ def current_active_class
113
+ configuration.active_class if active?
114
+ end
115
+
116
+ def configure_item_attrs
117
+ case configuration.active_scope
118
+ when :outer
119
+ append_class_to_options current_active_class, options[:outer]
120
+ when :inner
121
+ append_class_to_options current_active_class, options[:inner]
141
122
  end
123
+ end
124
+
125
+ def generate_dropdown_item
126
+ append_class_to_options "dropdown", options[:outer]
127
+ append_class_to_options "dropdown-toggle", options[:inner]
128
+
129
+ append_toggle_to_options "dropdown", options[:inner]
130
+
131
+ generate_simple_item(
132
+ generate_caret_label(name)
133
+ )
134
+ end
135
+
136
+ def generate_default_item
137
+ generate_simple_item(
138
+ name
139
+ )
140
+ end
141
+
142
+ def generate_caret_label(label)
143
+ [
144
+ label,
145
+ content_tag(
146
+ configuration.caret_element,
147
+ "",
148
+ class: "caret"
149
+ )
150
+ ].join(" ").html_safe
151
+ end
142
152
 
143
- def configuration
144
- Tabit.configuration
153
+ def generate_simple_item(label)
154
+ template.content_tag(
155
+ :li,
156
+ [
157
+ template.link_to(
158
+ label,
159
+ url,
160
+ options[:inner]
161
+ ),
162
+ output
163
+ ].compact.join.html_safe,
164
+ options[:outer]
165
+ )
166
+ end
167
+
168
+ def append_class_to_options(value, target = nil)
169
+ target ||= options
170
+
171
+ target[:class] ||= ""
172
+ target[:class] << " #{value}"
173
+ target[:class].strip!
174
+ end
175
+
176
+ def append_toggle_to_options(value, target = nil)
177
+ target ||= options
178
+
179
+ target[:data] ||= {}
180
+ target[:data][:toggle] = value
181
+ end
182
+
183
+ def output
184
+ return if children.empty?
185
+
186
+ case type
187
+ when :dropdown
188
+ list "dropdown-menu"
189
+ else
190
+ list
145
191
  end
192
+ end
193
+
194
+ def list(clazz = nil)
195
+ template.content_tag(
196
+ :ul,
197
+ children.collect(&:to_s).join.html_safe,
198
+ class: clazz
199
+ )
200
+ end
201
+
202
+ def configuration
203
+ Tabit.configuration
204
+ end
146
205
  end
147
206
  end
@@ -1,5 +1,28 @@
1
- # -*- encoding : utf-8 -*-
2
- module Tabit
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright (c) 2012-2015 Webhippie <http://www.webhippie.de>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+
25
+ class Tabit
3
26
  class Railtie < Rails::Railtie
4
27
  ActiveSupport.on_load :action_controller do
5
28
  helper Tabit::Helper
@@ -1,11 +1,39 @@
1
- # -*- encoding : utf-8 -*-
2
- module Tabit
3
- module Version
4
- MAJOR = 0
5
- MINOR = 4
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright (c) 2012-2015 Webhippie <http://www.webhippie.de>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+
25
+ class Tabit
26
+ class Version
27
+ MAJOR = 1
28
+ MINOR = 0
6
29
  PATCH = 0
7
- BUILD = nil
8
30
 
9
- STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
31
+ PRE = nil
32
+
33
+ class << self
34
+ def to_s
35
+ [MAJOR, MINOR, PATCH, PRE].compact.join(".")
36
+ end
37
+ end
10
38
  end
11
39
  end
@@ -0,0 +1,53 @@
1
+ # -*- coding: UTF-8 -*-
2
+ #
3
+ # Copyright (c) 2012-2015 Webhippie <http://www.webhippie.de>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+
25
+ require "simplecov"
26
+
27
+ if ENV["CODECLIMATE_REPO_TOKEN"]
28
+ require "coveralls"
29
+ require "codeclimate-test-reporter"
30
+
31
+ Coveralls.wear!
32
+ CodeClimate::TestReporter.start
33
+
34
+ SimpleCov.start do
35
+ add_filter "/spec"
36
+
37
+ formatter SimpleCov::Formatter::MultiFormatter[
38
+ SimpleCov::Formatter::HTMLFormatter,
39
+ CodeClimate::TestReporter::Formatter
40
+ ]
41
+ end
42
+ else
43
+ SimpleCov.start do
44
+ add_filter "/spec"
45
+ end
46
+ end
47
+
48
+ require "tabit"
49
+ require "rspec"
50
+
51
+ RSpec.configure do |config|
52
+ config.mock_with :rspec
53
+ end
metadata CHANGED
@@ -1,163 +1,131 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Thomas Boerger
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-19 00:00:00.000000000 Z
11
+ date: 2015-07-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: active_link_to
14
+ name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 1.0.0
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
16
  requirements:
27
- - - ~>
17
+ - - '>='
28
18
  - !ruby/object:Gem::Version
29
- version: 1.0.0
30
- - !ruby/object:Gem::Dependency
31
- name: redcarpet
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: 2.1.0
19
+ version: '0'
38
20
  type: :development
39
21
  prerelease: false
40
22
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
23
  requirements:
43
- - - ~>
24
+ - - '>='
44
25
  - !ruby/object:Gem::Version
45
- version: 2.1.0
26
+ version: '0'
46
27
  - !ruby/object:Gem::Dependency
47
- name: yard
28
+ name: rake
48
29
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
30
  requirements:
51
- - - ~>
31
+ - - '>='
52
32
  - !ruby/object:Gem::Version
53
- version: 0.8.2.1
33
+ version: '0'
54
34
  type: :development
55
35
  prerelease: false
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
37
  requirements:
59
- - - ~>
38
+ - - '>='
60
39
  - !ruby/object:Gem::Version
61
- version: 0.8.2.1
40
+ version: '0'
62
41
  - !ruby/object:Gem::Dependency
63
- name: jeweler
42
+ name: yard
64
43
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
44
  requirements:
67
- - - ~>
45
+ - - '>='
68
46
  - !ruby/object:Gem::Version
69
- version: 1.8.3
47
+ version: '0'
70
48
  type: :development
71
49
  prerelease: false
72
50
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
51
  requirements:
75
- - - ~>
52
+ - - '>='
76
53
  - !ruby/object:Gem::Version
77
- version: 1.8.3
54
+ version: '0'
78
55
  - !ruby/object:Gem::Dependency
79
- name: magic_encoding
56
+ name: rspec
80
57
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
58
  requirements:
83
- - - ~>
59
+ - - '>='
84
60
  - !ruby/object:Gem::Version
85
- version: 0.0.2
61
+ version: '0'
86
62
  type: :development
87
63
  prerelease: false
88
64
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
65
  requirements:
91
- - - ~>
66
+ - - '>='
92
67
  - !ruby/object:Gem::Version
93
- version: 0.0.2
68
+ version: '0'
94
69
  - !ruby/object:Gem::Dependency
95
- name: whitespace
70
+ name: active_link_to
96
71
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
72
  requirements:
99
- - - ~>
73
+ - - '>='
100
74
  - !ruby/object:Gem::Version
101
- version: 2.0.4
102
- type: :development
75
+ version: 1.0.0
76
+ type: :runtime
103
77
  prerelease: false
104
78
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
79
  requirements:
107
- - - ~>
80
+ - - '>='
108
81
  - !ruby/object:Gem::Version
109
- version: 2.0.4
110
- description:
111
- email: tboerger@tbpro.de
82
+ version: 1.0.0
83
+ description: |2
84
+ Tabit is a simple tab menu generator. It depends on active_link_to helper.
85
+ If you dont know how to set an item active take a look at it first. The
86
+ generated source is compatible to bootstrap tabs with dropdowns.
87
+ email:
88
+ - thomas@webhippie.de
112
89
  executables: []
113
90
  extensions: []
114
- extra_rdoc_files:
115
- - LICENSE.md
116
- - README.md
91
+ extra_rdoc_files: []
117
92
  files:
118
- - .rvmrc
119
- - .travis.yml
120
- - Gemfile
121
- - Gemfile.lock
122
- - LICENSE.md
93
+ - CHANGELOG.md
123
94
  - README.md
124
- - Rakefile
125
- - init.rb
126
- - lib/tabit.rb
127
- - lib/tabit/builder.rb
128
- - lib/tabit/cell.rb
129
- - lib/tabit/config.rb
95
+ - LICENSE
96
+ - lib/tabit/version.rb
130
97
  - lib/tabit/helper.rb
98
+ - lib/tabit/config.rb
99
+ - lib/tabit/cell.rb
100
+ - lib/tabit/builder.rb
131
101
  - lib/tabit/item.rb
132
102
  - lib/tabit/railtie.rb
133
- - lib/tabit/version.rb
134
- - tabit.gemspec
135
- homepage: https://github.com/tbpro/tabit
103
+ - lib/tabit.rb
104
+ - spec/spec_helper.rb
105
+ homepage: https://github.com/webhippie/tabit
136
106
  licenses:
137
107
  - MIT
108
+ metadata: {}
138
109
  post_install_message:
139
110
  rdoc_options: []
140
111
  require_paths:
141
112
  - lib
142
113
  required_ruby_version: !ruby/object:Gem::Requirement
143
- none: false
144
114
  requirements:
145
- - - ! '>='
115
+ - - '>='
146
116
  - !ruby/object:Gem::Version
147
117
  version: '0'
148
- segments:
149
- - 0
150
- hash: 1497893305618295686
151
118
  required_rubygems_version: !ruby/object:Gem::Requirement
152
- none: false
153
119
  requirements:
154
- - - ! '>='
120
+ - - '>='
155
121
  - !ruby/object:Gem::Version
156
122
  version: '0'
157
123
  requirements: []
158
124
  rubyforge_project:
159
- rubygems_version: 1.8.24
125
+ rubygems_version: 2.0.3
160
126
  signing_key:
161
- specification_version: 3
127
+ specification_version: 4
162
128
  summary: Tabit is a simple tab menu generator
163
- test_files: []
129
+ test_files:
130
+ - spec/spec_helper.rb
131
+ has_rdoc:
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use ruby-1.9.3-p194@tabit --create
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.2
4
- - 1.9.3
data/Gemfile DELETED
@@ -1,11 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'active_link_to', '~> 1.0.0'
4
-
5
- group :development do
6
- gem 'redcarpet', '~> 2.1.0'
7
- gem 'yard', '~> 0.8.2.1'
8
- gem 'jeweler', '~> 1.8.3'
9
- gem 'magic_encoding', '~> 0.0.2'
10
- gem 'whitespace', '~> 2.0.4'
11
- end
@@ -1,29 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- active_link_to (1.0.0)
5
- git (1.2.5)
6
- jeweler (1.8.4)
7
- bundler (~> 1.0)
8
- git (>= 1.2.5)
9
- rake
10
- rdoc
11
- json (1.7.5)
12
- magic_encoding (0.0.2)
13
- rake (0.9.2.2)
14
- rdoc (3.12)
15
- json (~> 1.4)
16
- redcarpet (2.1.1)
17
- whitespace (2.0.4)
18
- yard (0.8.2.1)
19
-
20
- PLATFORMS
21
- ruby
22
-
23
- DEPENDENCIES
24
- active_link_to (~> 1.0.0)
25
- jeweler (~> 1.8.3)
26
- magic_encoding (~> 0.0.2)
27
- redcarpet (~> 2.1.0)
28
- whitespace (~> 2.0.4)
29
- yard (~> 0.8.2.1)
data/LICENSE.md DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2012 Thomas Boerger Programmierung <http://www.tbpro.de>
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,32 +0,0 @@
1
- require 'rubygems'
2
-
3
- begin
4
- require 'bundler'
5
- Bundler.setup(:default, :development)
6
- rescue Bundler::BundlerError => e
7
- $stderr.puts e.message
8
- $stderr.puts 'Run `bundle install` to install missing gems'
9
- exit e.status_code
10
- end
11
-
12
- require 'rake'
13
- require 'jeweler'
14
- require 'yard'
15
-
16
- $:.push File.expand_path('../lib', __FILE__)
17
- require 'tabit/version'
18
-
19
- Jeweler::Tasks.new do |gem|
20
- gem.name = 'tabit'
21
- gem.version = Tabit::Version::STRING
22
- gem.homepage = 'https://github.com/tbpro/tabit'
23
- gem.license = 'MIT'
24
- gem.summary = %Q{Tabit is a simple tab menu generator}
25
- gem.email = 'tboerger@tbpro.de'
26
- gem.authors = ['Thomas Boerger']
27
- end
28
-
29
- Jeweler::RubygemsDotOrgTasks.new
30
- YARD::Rake::YardocTask.new
31
-
32
- task :default => :version
data/init.rb DELETED
@@ -1,2 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'tabit'
@@ -1,70 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "tabit"
8
- s.version = "0.4.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Thomas Boerger"]
12
- s.date = "2012-09-19"
13
- s.email = "tboerger@tbpro.de"
14
- s.extra_rdoc_files = [
15
- "LICENSE.md",
16
- "README.md"
17
- ]
18
- s.files = [
19
- ".rvmrc",
20
- ".travis.yml",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE.md",
24
- "README.md",
25
- "Rakefile",
26
- "init.rb",
27
- "lib/tabit.rb",
28
- "lib/tabit/builder.rb",
29
- "lib/tabit/cell.rb",
30
- "lib/tabit/config.rb",
31
- "lib/tabit/helper.rb",
32
- "lib/tabit/item.rb",
33
- "lib/tabit/railtie.rb",
34
- "lib/tabit/version.rb",
35
- "tabit.gemspec"
36
- ]
37
- s.homepage = "https://github.com/tbpro/tabit"
38
- s.licenses = ["MIT"]
39
- s.require_paths = ["lib"]
40
- s.rubygems_version = "1.8.24"
41
- s.summary = "Tabit is a simple tab menu generator"
42
-
43
- if s.respond_to? :specification_version then
44
- s.specification_version = 3
45
-
46
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- s.add_runtime_dependency(%q<active_link_to>, ["~> 1.0.0"])
48
- s.add_development_dependency(%q<redcarpet>, ["~> 2.1.0"])
49
- s.add_development_dependency(%q<yard>, ["~> 0.8.2.1"])
50
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
51
- s.add_development_dependency(%q<magic_encoding>, ["~> 0.0.2"])
52
- s.add_development_dependency(%q<whitespace>, ["~> 2.0.4"])
53
- else
54
- s.add_dependency(%q<active_link_to>, ["~> 1.0.0"])
55
- s.add_dependency(%q<redcarpet>, ["~> 2.1.0"])
56
- s.add_dependency(%q<yard>, ["~> 0.8.2.1"])
57
- s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
58
- s.add_dependency(%q<magic_encoding>, ["~> 0.0.2"])
59
- s.add_dependency(%q<whitespace>, ["~> 2.0.4"])
60
- end
61
- else
62
- s.add_dependency(%q<active_link_to>, ["~> 1.0.0"])
63
- s.add_dependency(%q<redcarpet>, ["~> 2.1.0"])
64
- s.add_dependency(%q<yard>, ["~> 0.8.2.1"])
65
- s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
66
- s.add_dependency(%q<magic_encoding>, ["~> 0.0.2"])
67
- s.add_dependency(%q<whitespace>, ["~> 2.0.4"])
68
- end
69
- end
70
-