rails-bootstrap-tabs 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9387ee7d3a1b5eb0317ee1754f6990fef284f409
4
- data.tar.gz: bb0a3016597dd703d25ecf09a8a6192830ab5953
3
+ metadata.gz: b53b4afa84fd1f6157955b98548c4c013351aaf2
4
+ data.tar.gz: aa9afc668ceaade23c10a1e0e19bd8de54184535
5
5
  SHA512:
6
- metadata.gz: 2bb7c59df9ab48adb88e52d9169c42a2bd11b9d4c77e344ce07739ef80b3eb22400a46437721a8728cc291cd90f2759e42bc44be84839a5f089b309f993a455b
7
- data.tar.gz: a464a0da3c2c7348b0e3178200339e474254040d3850874e3f750190b8b581457174752d72a7dd413dbaac2b222b2c0f36292791ee8fcbefe83ac2b0412cee61
6
+ metadata.gz: 1bb500380c7bcd7f18b2bdf30ced28003dcdb10597bea6c6b205c0e100c7a0157d22db0a41c2f21093116d1811751ecbbfdd6d4a616957041445d0d45b0d43fb
7
+ data.tar.gz: 22e8369fce286b8ac46b385da53f06672a8117b439f1c6db027b2efd0af5a5e57b66c53a3971caa957c64095dad05e8c95b72a647e547e3e9d39a6b62041c994
@@ -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]}", 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,43 @@
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
+ content_tag :li, class: 'nav-item' do
14
+ link_to "##{options[:anchor]}", data: { toggle: 'tab' }, class: link_class do
15
+ yield
16
+ end
17
+ end
18
+ end
19
+
20
+ def render_panes_wrapper(options)
21
+ content_class = 'tab-content'
22
+ content_class << " #{options[:content_class]}" if options[:content_class]
23
+
24
+ content_tag :div, class: content_class do
25
+ yield
26
+ end
27
+ end
28
+
29
+ def render_pane(tab)
30
+ options = tab.options
31
+ pane_class = 'tab-pane'
32
+ pane_class << ' active' if options[:active]
33
+ if options[:fade_effect]
34
+ pane_class << ' fade'
35
+ pane_class << ' show' if options[:active]
36
+ pane_class << ' in' unless options[:active]
37
+ end
38
+ content_tag :div, id: options[:anchor].to_s, class: pane_class, role: 'tabpanel' do
39
+ yield
40
+ end
41
+ end
42
+ end
43
+ end
@@ -21,6 +21,7 @@ module RailsBootstrapTabs::Renderers
21
21
  def prepare_tabs
22
22
  @tabs.each.with_index do |tab, index|
23
23
  tab.options[:anchor] ||= "tab-#{index}-#{rstr}"
24
+ tab.options[:fade_effect] ||= RailsBootstrapTabs.fade_effect || @options[:fade_effect]
24
25
  end
25
26
  active_tab = @tabs.find { |t| t.options[:active] }
26
27
  active_tab ||= @tabs.first
@@ -29,32 +30,41 @@ module RailsBootstrapTabs::Renderers
29
30
  end
30
31
 
31
32
  def render_tabs(tabs)
32
- content_tag :ul, class: 'nav nav-tabs' do
33
+ render_tabs_wrapper do
33
34
  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' }
35
+ render_tab(tab) do
36
+ tab.name
37
37
  end
38
38
  end.join("\n").html_safe
39
39
  end
40
40
  end
41
41
 
42
42
  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
43
+ render_panes_wrapper(options) do
47
44
  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
45
+ render_pane(tab) do
52
46
  tab.block.call if tab.block
53
47
  end
54
48
  end.join("\n").html_safe
55
49
  end
56
50
  end
57
51
 
52
+ def render_tabs_wrapper
53
+ raise "Must be redefined"
54
+ end
55
+
56
+ def render_tab(tab)
57
+ raise "Must be redefined"
58
+ end
59
+
60
+ def render_panes_wrapper(options)
61
+ raise "Must be redefined"
62
+ end
63
+
64
+ def render_pane(tab)
65
+ raise "Must be redefined"
66
+ end
67
+
58
68
  def tab(name, options, &block)
59
69
  @tabs << Tab.new(name, options, block)
60
70
  end
@@ -1,3 +1,3 @@
1
1
  module RailsBootstrapTabs
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.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.0
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: 2017-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -34,6 +34,8 @@ files:
34
34
  - lib/rails-bootstrap-tabs.rb
35
35
  - lib/rails-bootstrap-tabs/helpers/tabs_helper.rb
36
36
  - lib/rails-bootstrap-tabs/rails/engine.rb
37
+ - lib/rails-bootstrap-tabs/renderers/tabs_bootstrap3_renderer.rb
38
+ - lib/rails-bootstrap-tabs/renderers/tabs_bootstrap4_renderer.rb
37
39
  - lib/rails-bootstrap-tabs/renderers/tabs_renderer.rb
38
40
  - lib/rails-bootstrap-tabs/version.rb
39
41
  homepage: https://github.com/resivalex/rails-bootstrap-tabs
@@ -56,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
58
  version: '0'
57
59
  requirements: []
58
60
  rubyforge_project:
59
- rubygems_version: 2.4.5
61
+ rubygems_version: 2.6.12
60
62
  signing_key:
61
63
  specification_version: 4
62
64
  summary: A Rails plugin to build bootstrap tabs