bootstrap-components-helpers 0.0.7 → 0.0.8

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: 5817863cad4e746bee07c1e955669653071c9745
4
- data.tar.gz: 7c3b965765d7d91a3af14f179680da00bbe3c3aa
3
+ metadata.gz: 19936223524696b2929edcfe7eb6d443ba67231d
4
+ data.tar.gz: 03499a47b9d2f88302a53b7cbd7535329924f171
5
5
  SHA512:
6
- metadata.gz: b4cbb196124b509fd54f035aa8d6b0deb82b09d156dd04938f4e6c8a693f0e8d95ee75db4a36ddde3bd4252b0734fb9b7406be8bf16c7c283934904e746887b2
7
- data.tar.gz: 3ef9238abadb235368ce0d773a899edda29a5e8621f0a193bdee5d81319dcb38a9cea4a16145f1c07f649247d417776965f4da991ba76a0ab4314243a0278af0
6
+ metadata.gz: 7baf4c3dc8fc97e30af97dd5dff20f00f56b14f4646b903595500cc72d6a5b43f2a61bae07c9702babee99fd939e306eda5dbf4e2591b0102a6e53574f8c9297
7
+ data.tar.gz: fcca9bc6562ba23ceb3fd9c3e630585104946327d4b62922bc93a5a916ec5290ffe069608dd990af04ac162fd70c7f9edc14a471dd307c2c996c2d27d0bd9116
@@ -54,3 +54,5 @@ In your Gemfile:
54
54
 
55
55
  - Graham Torn
56
56
  - Caleb Adam Haye
57
+ - Darkside73
58
+ - Dave Burt
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module BootstrapComponentsHelpers
2
4
  module ModalHelper
3
5
 
@@ -40,4 +42,4 @@ module BootstrapComponentsHelpers
40
42
  end
41
43
  end
42
44
 
43
- ActionView::Base.send :include, BootstrapComponentsHelpers::ModalHelper
45
+ ActionView::Base.send :include, BootstrapComponentsHelpers::ModalHelper
@@ -5,6 +5,8 @@ module BootstrapComponentsHelpers
5
5
  opts[:style] ||= 'tabs'
6
6
  builder = TabsBuilder.new self
7
7
  yield builder
8
+ pane_handles_html = builder.pane_handles_html
9
+ return unless pane_handles_html
8
10
  tabs = content_tag(:ul, builder.pane_handles_html, :class => "nav nav-#{opts[:style]}")
9
11
  contents = content_tag(:div, builder.pane_contents_html, :class => 'tab-content')
10
12
  css_direction = "tabs-#{opts[:direction]}" unless opts[:direction] == 'above'
@@ -14,6 +16,7 @@ module BootstrapComponentsHelpers
14
16
  end
15
17
 
16
18
  class TabsBuilder
19
+ include ActionView::Helpers::OutputSafetyHelper
17
20
 
18
21
  attr_reader :parent, :pane_contents, :pane_handles
19
22
  delegate :capture, :content_tag, :to => :parent
@@ -26,28 +29,47 @@ module BootstrapComponentsHelpers
26
29
 
27
30
  def pane title, options = {}, &block
28
31
  css_class = options[:active] ? 'active' : ''
29
- link = content_tag(:a, title, :'data-toggle' => 'tab', :href => "##{title.parameterize}_tab")
30
- @pane_handles << [link, css_class]
31
- @pane_contents << [css_class, title, capture(&block)]
32
+ tab_id = options[:id] || default_tab_id(title)
33
+ link = content_tag(:a, :'data-toggle' => 'tab', :href => "##{tab_id}") do
34
+ if options[:icon]
35
+ title = raw(content_tag(:i, '', class: "#{options[:icon]}") + ' ' + title)
36
+ end
37
+ title
38
+ end
39
+ content = capture(&block)
40
+ if content.present?
41
+ @pane_handles << [link, css_class]
42
+ @pane_contents << [[css_class, options[:class]], title, tab_id, content]
43
+ end
32
44
  nil
33
45
  end
34
-
46
+
35
47
  def pane_handles_html
48
+ return if pane_handles.empty?
36
49
  pane_handles.first[1] = 'active' unless pane_handles.detect {|ph| ph[1] == 'active'}
37
50
  pane_handles.map do |link, css_class|
38
51
  content_tag(:li, link, :class => css_class)
39
52
  end.join("\n").html_safe
40
53
  end
41
-
54
+
42
55
  def pane_contents_html
43
- pane_contents.first[0] = 'active' unless pane_contents.detect {|pc| pc[0] == 'active'}
44
- pane_contents.map do |css_class, title, content|
45
- content_tag :div, content, :class => "tab-pane #{css_class}", :id => "#{title.parameterize}_tab"
56
+ return if pane_contents.empty?
57
+ pane_contents.first[0] << 'active' unless pane_contents.detect {|pc| pc[0].include? 'active'}
58
+ pane_contents.map do |css_class, title, tab_id, content|
59
+ css_class << 'in' if css_class.include?('active') && css_class.include?('fade')
60
+ css_class = css_class.join(' ').strip
61
+ content_tag :div, content, :class => "tab-pane #{css_class}", :id => "#{tab_id}"
46
62
  end.join("\n").html_safe
47
63
  end
48
64
 
65
+ private
66
+
67
+ def default_tab_id(title)
68
+ title.parameterize + '_tab'
69
+ end
70
+
49
71
  end
50
-
72
+
51
73
  end
52
74
  end
53
75
 
@@ -1,9 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class AccordionHelperTest < ActionView::TestCase
4
-
4
+
5
5
  include BootstrapComponentsHelpers::AccordionHelper
6
-
6
+
7
7
  test "accordion method" do
8
8
  html = accordion do |accordion|
9
9
  accordion.pane 'My pane' do
@@ -4,9 +4,9 @@ require 'action_view/template'
4
4
  require 'bootstrap-components-helpers'
5
5
 
6
6
  class ActionView::TestCase
7
-
7
+
8
8
  def assert_helper_output fixture_name, actual_output
9
- assert_equal File.read("#{File.dirname __FILE__}/fixtures/#{fixture_name}.html"), actual_output
9
+ assert_equal File.read("#{File.dirname __FILE__}/fixtures/#{fixture_name}.html").strip, actual_output
10
10
  end
11
-
12
- end
11
+
12
+ end
@@ -1,9 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TabsHelperTest < ActionView::TestCase
4
-
5
4
  include BootstrapComponentsHelpers::TabsHelper
6
-
5
+
7
6
  test "calling tabs method" do
8
7
  html = tabs do |tabs|
9
8
  tabs.pane 'My first pane' do
@@ -13,4 +12,35 @@ class TabsHelperTest < ActionView::TestCase
13
12
  assert_helper_output 'tabs', html
14
13
  end
15
14
 
15
+ test "extra options" do
16
+ html = tabs do |tabs|
17
+ tabs.pane 'My first pane<br>', id: 'custom_id', icon: 'fa fa-ok', class: 'custom-class' do
18
+ 'inside the pane'
19
+ end
20
+ end
21
+ assert_match /href="#custom_id"/, html
22
+ assert_match /id="custom_id"/, html
23
+ assert_match /i class="fa fa-ok"/, html
24
+ assert_match /class=".*custom-class.*"/, html
25
+ refute_match /<br>/, html
26
+ end
27
+
28
+ test "adds 'in' css class to active tab with 'ade effect" do
29
+ html = tabs do |tabs|
30
+ tabs.pane 'My first pane', class: 'fade', active: true do
31
+ 'inside the pane'
32
+ end
33
+ end
34
+ assert_match /class=".*active.*"/, html
35
+ assert_match /class=".*in.*"/, html
36
+ end
37
+
38
+ test "empty pane does not included in html" do
39
+ html = tabs do |tabs|
40
+ tabs.pane 'Empty pane' do
41
+ ''
42
+ end
43
+ end
44
+ refute_match /Empty pane/, html
45
+ end
16
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-components-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Schneider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-28 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -32,10 +32,10 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - README.markdown
35
+ - lib/bootstrap-components-helpers.rb
35
36
  - lib/bootstrap-components-helpers/accordion_helper.rb
36
37
  - lib/bootstrap-components-helpers/modal_helper.rb
37
38
  - lib/bootstrap-components-helpers/tabs_helper.rb
38
- - lib/bootstrap-components-helpers.rb
39
39
  - test/test_accordion_helper.rb
40
40
  - test/test_helper.rb
41
41
  - test/test_modal_helper.rb
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  version: '0'
61
61
  requirements: []
62
62
  rubyforge_project:
63
- rubygems_version: 2.0.3
63
+ rubygems_version: 2.2.2
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: View helpers for Twitter Bootstrap components