tabit 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1,20 +1 @@
1
- #!/usr/bin/env bash
2
-
3
- environment_id="ruby-1.9.3-head@langwhich"
4
-
5
- if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
6
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
7
- then
8
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
9
-
10
- if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
11
- then
12
- . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
13
- fi
14
- else
15
- if ! rvm --create use "$environment_id"
16
- then
17
- echo "Failed to create RVM environment '${environment_id}'."
18
- return 1
19
- fi
20
- fi
1
+ rvm use ruby-1.9.3-head@tabit --create
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Langwhich GmbH <http://www.langwhich.com>
1
+ Copyright (c) 2012 Langwhich GmbH <http://www.langwhich.com>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
- # Tabit [![Build Status](https://secure.travis-ci.org/eifion/tabit.png)](https://secure.travis-ci.org/eifion/tabit.png)
1
+ # Tabit [![Build Status](https://secure.travis-ci.org/Langwhich/tabit)](https://secure.travis-ci.org/Langwhich/tabit.png)
2
2
 
3
3
  Tabit is a simple tab menu generator. It depends on `active_link_to`
4
4
  helper. If you dont know how to set an item active take a look at it first.
5
+ The generated source is compatible to bootstrap tabs with dropdowns.
5
6
 
6
7
  ## Install
7
8
 
@@ -12,12 +13,14 @@ helper. If you dont know how to set an item active take a look at it first.
12
13
  ## Usage
13
14
 
14
15
  ```ruby
15
- = tabit 'nav nav-tabs' do |t|
16
- = t.add 'Videos', videos_path
17
- = t.add 'Movies', movies_path, :active => /movies(\/\d)*(\/edit)*$/
18
- = t.add 'Add movie, new_movies_path, :active => :exclusive
16
+ = tabit :class => 'nav nav-tabs' do |t1|
17
+ - t1.add 'Videos', videos_path
18
+ - t1.add 'Movies', movies_path, :active => /movies(\/\d)*(\/edit)*$/
19
+ - t1.add 'Movies, movies_path, :active => :exclusive, :type => :dropdown do |t2|
20
+ - t2.add 'Add movie', new_movie_path, :active => :exclusive
19
21
  ```
20
22
 
21
23
  ## Credits
22
24
 
23
- Copyright (c) 2011 Langwhich GmbH <http://www.langwhich.com>
25
+ Copyright (c) 20112 Langwhich GmbH <http://www.langwhich.com>
26
+
data/lib/tabit.rb CHANGED
@@ -4,6 +4,7 @@ module Tabit
4
4
  autoload :Railtie, 'tabit/railtie'
5
5
  autoload :Helper, 'tabit/helper'
6
6
  autoload :Builder, 'tabit/builder'
7
+ autoload :Item, 'tabit/item'
7
8
 
8
9
  def self.configure(&block)
9
10
  @configuration = Tabit::Config.new(&block)
data/lib/tabit/builder.rb CHANGED
@@ -1,43 +1,21 @@
1
1
  module Tabit
2
- class Builder
3
- include ActionView::Helpers::TagHelper
4
- include ActionView::Helpers::CaptureHelper
2
+ class Builder < Item
3
+ def initialize(template, options, &block)
4
+ @@template = template
5
5
 
6
- attr_accessor :output_buffer
7
- attr_accessor :template
6
+ @children = []
7
+ @options = options
8
8
 
9
- def initialize(template)
10
- @template = template
9
+ yield self if block_given?
11
10
  end
12
11
 
13
- def add(name, url = nil, options = {})
14
- options[:inner] ||= {}
15
- options[:outer] ||= {}
16
-
17
- options[:active] ||= configuration.active_detect
18
- url ||= '#'
19
-
20
- clazz = template.active_link_to_class(
21
- url,
22
- {
23
- :active => options[:active],
24
- :class_active => configuration.active_class
25
- }
12
+ def to_s
13
+ template.content_tag(
14
+ :ul,
15
+ children.collect(&:to_s).join.html_safe,
16
+ options
26
17
  )
27
-
28
- options[:outer][:class] = '' if options[:outer][:class].nil?
29
- options[:outer][:class] << " #{clazz}"
30
- options[:outer][:class].strip!
31
-
32
- content_tag(:li, name, options[:outer]) do
33
- template.link_to name, url, options[:inner]
34
- end
35
18
  end
36
-
37
- protected
38
- def configuration
39
- Tabit.configuration
40
- end
41
19
  end
42
20
  end
43
21
 
data/lib/tabit/helper.rb CHANGED
@@ -2,14 +2,11 @@ module Tabit
2
2
  module Helper
3
3
  include ActionView::Helpers::TagHelper
4
4
  include ActionView::Helpers::UrlHelper
5
- include ActionView::Helpers::CaptureHelper
6
5
 
7
- def tabit(clazz = '', options = {}, &block)
8
- options[:class] ||= clazz.blank? ? '' : clazz
9
-
10
- content_tag(:ul, options) do
11
- yield(configuration.builder_class.new(self))
12
- end
6
+ def tabit(options = {}, &block)
7
+ configuration
8
+ .builder_class
9
+ .new(self, options, &block).to_s
13
10
  end
14
11
 
15
12
  protected
data/lib/tabit/item.rb ADDED
@@ -0,0 +1,104 @@
1
+ module Tabit
2
+ class Item
3
+ include ActionView::Helpers::TagHelper
4
+ include ActionView::Helpers::UrlHelper
5
+
6
+ cattr_accessor :template
7
+ attr_accessor :children
8
+
9
+ attr_accessor :name
10
+ attr_accessor :url
11
+ attr_accessor :options
12
+
13
+ def initialize(name, url = nil, options = {})
14
+ @name, @url, @options = name, url, options
15
+
16
+ @active = @options.delete(:active) || configuration.active_detect
17
+ @type = @options.delete(:type) || :default
18
+
19
+ @children = []
20
+
21
+ @options[:inner] ||= {}
22
+ @options[:outer] ||= {}
23
+
24
+ clazz = template.active_link_to_class(
25
+ url,
26
+ {
27
+ active: @active,
28
+ class_active: configuration.active_class
29
+ }
30
+ )
31
+
32
+ @options[:outer][:class] = '' if @options[:outer][:class].nil?
33
+ @options[:outer][:class] << " #{clazz}"
34
+ @options[:outer][:class].strip!
35
+ end
36
+
37
+ def add(name, url = nil, options = {})
38
+ Item.new(name, url, options).tap do |adding|
39
+ @children << adding
40
+ yield adding if block_given?
41
+ end
42
+ end
43
+
44
+ def to_s
45
+ case @type
46
+ when :dropdown
47
+ options[:outer][:class] = '' if @options[:outer][:class].nil?
48
+ options[:outer][:class] << " dropdown"
49
+ options[:outer][:class].strip!
50
+
51
+ options[:inner][:class] = '' if @options[:inner][:class].nil?
52
+ options[:inner][:class] << " dropdown-toggle"
53
+ options[:inner][:class].strip!
54
+
55
+ options[:inner][:data] ||= {}
56
+ options[:inner][:data][:toggle] = 'dropdown'
57
+
58
+ template.content_tag(
59
+ :li,
60
+ [
61
+ template.link_to([name, content_tag(:b, '', :class => 'caret')].join.html_safe, url, options[:inner]),
62
+ output
63
+ ].compact.join.html_safe,
64
+ options[:outer]
65
+ )
66
+ else
67
+ template.content_tag(
68
+ :li,
69
+ [
70
+ template.link_to(name, url, options[:inner]),
71
+ output
72
+ ].compact.join.html_safe,
73
+ options[:outer]
74
+ )
75
+ end
76
+ end
77
+
78
+ protected
79
+ def output
80
+ if children.empty?
81
+ nil
82
+ else
83
+ case @type
84
+ when :dropdown
85
+ template.content_tag(
86
+ :ul,
87
+ children.collect(&:to_s).join.html_safe,
88
+ :class => 'dropdown-menu'
89
+ )
90
+ else
91
+ template.content_tag(
92
+ :ul,
93
+ children.collect(&:to_s).join.html_safe
94
+ )
95
+ end
96
+ end
97
+ end
98
+
99
+ def configuration
100
+ Tabit.configuration
101
+ end
102
+ end
103
+ end
104
+
data/lib/tabit/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Tabit
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 1
5
- PATCH = 2
4
+ MINOR = 2
5
+ PATCH = 0
6
6
  BUILD = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
data/tabit.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "tabit"
8
- s.version = "0.1.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 = ["Thomas Boerger", "Tim Rudat"]
12
- s.date = "2012-03-06"
12
+ s.date = "2012-04-30"
13
13
  s.email = "thomas.boerger@langwhich.com"
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.md",
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/tabit/cell.rb",
30
30
  "lib/tabit/config.rb",
31
31
  "lib/tabit/helper.rb",
32
+ "lib/tabit/item.rb",
32
33
  "lib/tabit/railtie.rb",
33
34
  "lib/tabit/version.rb",
34
35
  "tabit.gemspec"
@@ -36,7 +37,7 @@ Gem::Specification.new do |s|
36
37
  s.homepage = "https://github.com/Langwhich/tabit"
37
38
  s.licenses = ["MIT"]
38
39
  s.require_paths = ["lib"]
39
- s.rubygems_version = "1.8.10"
40
+ s.rubygems_version = "1.8.21"
40
41
  s.summary = "Tabit is a simple tab menu generator"
41
42
 
42
43
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-06 00:00:00.000000000 Z
13
+ date: 2012-04-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: active_link_to
17
- requirement: &70109394377500 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: 1.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70109394377500
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 1.0.0
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: redcarpet
28
- requirement: &70109394377000 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ~>
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: 2.1.0
34
39
  type: :development
35
40
  prerelease: false
36
- version_requirements: *70109394377000
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 2.1.0
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: yard
39
- requirement: &70109394376520 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ~>
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: 0.7.5
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *70109394376520
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 0.7.5
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: jeweler
50
- requirement: &70109394376040 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ~>
@@ -55,7 +70,12 @@ dependencies:
55
70
  version: 1.8.3
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *70109394376040
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 1.8.3
59
79
  description:
60
80
  email: thomas.boerger@langwhich.com
61
81
  executables: []
@@ -77,6 +97,7 @@ files:
77
97
  - lib/tabit/cell.rb
78
98
  - lib/tabit/config.rb
79
99
  - lib/tabit/helper.rb
100
+ - lib/tabit/item.rb
80
101
  - lib/tabit/railtie.rb
81
102
  - lib/tabit/version.rb
82
103
  - tabit.gemspec
@@ -95,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
116
  version: '0'
96
117
  segments:
97
118
  - 0
98
- hash: 1142525965539006714
119
+ hash: -786843556050653153
99
120
  required_rubygems_version: !ruby/object:Gem::Requirement
100
121
  none: false
101
122
  requirements:
@@ -104,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
125
  version: '0'
105
126
  requirements: []
106
127
  rubyforge_project:
107
- rubygems_version: 1.8.10
128
+ rubygems_version: 1.8.21
108
129
  signing_key:
109
130
  specification_version: 3
110
131
  summary: Tabit is a simple tab menu generator