rails-bootstrap-tabs 0.1.1 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9387ee7d3a1b5eb0317ee1754f6990fef284f409
4
- data.tar.gz: bb0a3016597dd703d25ecf09a8a6192830ab5953
3
+ metadata.gz: bbfbb9984d3664b81fac5ecece7d5cf5dddbae0d
4
+ data.tar.gz: 85e4087ad3bc28c067ad3c55293239099c7076e1
5
5
  SHA512:
6
- metadata.gz: 2bb7c59df9ab48adb88e52d9169c42a2bd11b9d4c77e344ce07739ef80b3eb22400a46437721a8728cc291cd90f2759e42bc44be84839a5f089b309f993a455b
7
- data.tar.gz: a464a0da3c2c7348b0e3178200339e474254040d3850874e3f750190b8b581457174752d72a7dd413dbaac2b222b2c0f36292791ee8fcbefe83ac2b0412cee61
6
+ metadata.gz: 02d055262060e0e158bbdd326d2d1e9d59b5d7e62806727471d91a1478603fec8a8593ffa2005c408e302ff0dd6ca5f96f09cbc25be6721c452ffdff4998af62
7
+ data.tar.gz: 663814a10dc371c32cd3ec6cf4c488eedfccbf10767ee327afcc026f62a519d23d33bdfcdb86dd99018538fb0eaa32f93a576c3d4664690d75eb68baf267e8f0
@@ -1,6 +1,8 @@
1
1
  module RailsBootstrapTabs
2
2
  module Renderers
3
3
  autoload :TabsRenderer, 'rails-bootstrap-tabs/renderers/tabs_renderer'
4
+ autoload :TabsBootstrap3Renderer, 'rails-bootstrap-tabs/renderers/tabs_bootstrap3_renderer'
5
+ autoload :TabsBootstrap4Renderer, 'rails-bootstrap-tabs/renderers/tabs_bootstrap4_renderer'
4
6
  end
5
7
  end
6
8
 
@@ -1,7 +1,14 @@
1
1
  module RailsBootstrapTabs::Helpers
2
2
  module TabsHelper
3
3
  def tabs(*args, &block)
4
- RailsBootstrapTabs::Renderers::TabsRenderer.new(self, *args, &block).render
4
+ tabs_renderer_class = if RailsBootstrapTabs.bootstrap_version == 3
5
+ RailsBootstrapTabs::Renderers::TabsBootstrap3Renderer
6
+ elsif RailsBootstrapTabs.bootstrap_version == 4
7
+ RailsBootstrapTabs::Renderers::TabsBootstrap4Renderer
8
+ else
9
+ raise "Unknown bootstrap version: #{RailsBootstrapTabs.bootstrap_version}!"
10
+ end
11
+ tabs_renderer_class.new(self, *args, &block).render
5
12
  end
6
13
  end
7
14
  end
@@ -1,6 +1,9 @@
1
1
  require 'rails-bootstrap-tabs/helpers/tabs_helper'
2
2
 
3
3
  module RailsBootstrapTabs
4
+ mattr_accessor :bootstrap_version do; 3; end
5
+ mattr_accessor :fade_effect do; false; end
6
+
4
7
  module Rails
5
8
  class Engine < ::Rails::Engine
6
9
  initializer "rails-bootstrap-tabs" do
@@ -0,0 +1,36 @@
1
+ module RailsBootstrapTabs::Renderers
2
+ class TabsBootstrap3Renderer < TabsRenderer
3
+ def render_tabs_wrapper
4
+ content_tag :ul, class: 'nav nav-tabs' do
5
+ yield
6
+ end
7
+ end
8
+
9
+ def render_tab(tab)
10
+ options = tab.options
11
+ content_tag :li, class: ('active' if options[:active]) do
12
+ link_to "##{options[:anchor]}", class: (options[:link_class] if options[:link_class]), data: { toggle: 'tab' } do
13
+ yield
14
+ end
15
+ end
16
+ end
17
+
18
+ def render_panes_wrapper(options)
19
+ content_class = 'tab-content'
20
+ content_class << " #{options[:content_class]}" if options[:content_class]
21
+
22
+ content_tag :div, class: content_class do
23
+ yield
24
+ end
25
+ end
26
+
27
+ def render_pane(tab)
28
+ options = tab.options
29
+ pane_class = 'tab-pane'
30
+ pane_class << ' active' if options[:active]
31
+ content_tag :div, id: options[:anchor].to_s, class: pane_class do
32
+ yield
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,44 @@
1
+ module RailsBootstrapTabs::Renderers
2
+ class TabsBootstrap4Renderer < TabsRenderer
3
+ def render_tabs_wrapper
4
+ content_tag :ul, class: 'nav nav-tabs' do
5
+ yield
6
+ end
7
+ end
8
+
9
+ def render_tab(tab)
10
+ options = tab.options
11
+ link_class = 'nav-link'
12
+ link_class << ' active' if options[:active]
13
+ link_class << " #{options[:link_class]}" if options[:link_class]
14
+ content_tag :li, class: 'nav-item' do
15
+ link_to "##{options[:anchor]}", data: { toggle: 'tab' }, class: link_class do
16
+ yield
17
+ end
18
+ end
19
+ end
20
+
21
+ def render_panes_wrapper(options)
22
+ content_class = 'tab-content'
23
+ content_class << " #{options[:content_class]}" if options[:content_class]
24
+
25
+ content_tag :div, class: content_class do
26
+ yield
27
+ end
28
+ end
29
+
30
+ def render_pane(tab)
31
+ options = tab.options
32
+ pane_class = 'tab-pane'
33
+ pane_class << ' active' if options[:active]
34
+ if options[:fade_effect]
35
+ pane_class << ' fade'
36
+ pane_class << ' show' if options[:active]
37
+ pane_class << ' in' unless options[:active]
38
+ end
39
+ content_tag :div, id: options[:anchor].to_s, class: pane_class, role: 'tabpanel' do
40
+ yield
41
+ end
42
+ end
43
+ end
44
+ end
@@ -8,8 +8,9 @@ module RailsBootstrapTabs::Renderers
8
8
  @tabs = []
9
9
  end
10
10
 
11
- def rstr
12
- (0...8).map { ('a'.ord + rand(26)).chr }.join
11
+ def rstr(seed)
12
+ rnd = Random.new(seed)
13
+ (0...8).map { ('a'.ord + rnd.rand(26)).chr }.join
13
14
  end
14
15
 
15
16
  def render
@@ -20,7 +21,8 @@ module RailsBootstrapTabs::Renderers
20
21
 
21
22
  def prepare_tabs
22
23
  @tabs.each.with_index do |tab, index|
23
- tab.options[:anchor] ||= "tab-#{index}-#{rstr}"
24
+ tab.options[:anchor] ||= "tab-#{index}-#{rstr(index)}"
25
+ tab.options[:fade_effect] ||= RailsBootstrapTabs.fade_effect || @options[:fade_effect]
24
26
  end
25
27
  active_tab = @tabs.find { |t| t.options[:active] }
26
28
  active_tab ||= @tabs.first
@@ -29,32 +31,41 @@ module RailsBootstrapTabs::Renderers
29
31
  end
30
32
 
31
33
  def render_tabs(tabs)
32
- content_tag :ul, class: 'nav nav-tabs' do
34
+ render_tabs_wrapper do
33
35
  tabs.map do |tab|
34
- options = tab.options
35
- content_tag :li, class: ('active' if options[:active]) do
36
- link_to tab.name, "##{options[:anchor]}", data: { toggle: 'tab' }
36
+ render_tab(tab) do
37
+ tab.name
37
38
  end
38
39
  end.join("\n").html_safe
39
40
  end
40
41
  end
41
42
 
42
43
  def render_panes(tabs, options)
43
- content_class = 'tab-content'
44
- content_class << " #{options[:content_class]}" if options[:content_class]
45
-
46
- content_tag :div, class: content_class do
44
+ render_panes_wrapper(options) do
47
45
  tabs.map do |tab|
48
- options = tab.options
49
- pane_class = 'tab-pane'
50
- pane_class << ' active' if options[:active]
51
- content_tag :div, id: options[:anchor].to_s, class: pane_class do
46
+ render_pane(tab) do
52
47
  tab.block.call if tab.block
53
48
  end
54
49
  end.join("\n").html_safe
55
50
  end
56
51
  end
57
52
 
53
+ def render_tabs_wrapper
54
+ raise "Must be redefined"
55
+ end
56
+
57
+ def render_tab(tab)
58
+ raise "Must be redefined"
59
+ end
60
+
61
+ def render_panes_wrapper(options)
62
+ raise "Must be redefined"
63
+ end
64
+
65
+ def render_pane(tab)
66
+ raise "Must be redefined"
67
+ end
68
+
58
69
  def tab(name, options, &block)
59
70
  @tabs << Tab.new(name, options, block)
60
71
  end
@@ -1,3 +1,3 @@
1
1
  module RailsBootstrapTabs
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-bootstrap-tabs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Reshetnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-01 00:00:00.000000000 Z
11
+ date: 2021-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,26 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.11
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.6.0
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 3.6.0
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: 3.6.0
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.6.0
27
47
  description: A Rails plugin to build bootstrap tabs
28
48
  email:
29
49
  - resivalex@gmail.com
@@ -34,6 +54,8 @@ files:
34
54
  - lib/rails-bootstrap-tabs.rb
35
55
  - lib/rails-bootstrap-tabs/helpers/tabs_helper.rb
36
56
  - lib/rails-bootstrap-tabs/rails/engine.rb
57
+ - lib/rails-bootstrap-tabs/renderers/tabs_bootstrap3_renderer.rb
58
+ - lib/rails-bootstrap-tabs/renderers/tabs_bootstrap4_renderer.rb
37
59
  - lib/rails-bootstrap-tabs/renderers/tabs_renderer.rb
38
60
  - lib/rails-bootstrap-tabs/version.rb
39
61
  homepage: https://github.com/resivalex/rails-bootstrap-tabs
@@ -56,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
78
  version: '0'
57
79
  requirements: []
58
80
  rubyforge_project:
59
- rubygems_version: 2.4.5
81
+ rubygems_version: 2.5.1
60
82
  signing_key:
61
83
  specification_version: 4
62
84
  summary: A Rails plugin to build bootstrap tabs