bootstrap_help 0.0.28 → 0.0.29

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: 009745243b1acf73fa3dad07f238728299c96325
4
- data.tar.gz: ba4355e89e5251daed1dc606b94cea72cef4908a
3
+ metadata.gz: f8410998cb554a1cb82729ea606d43258a10f47c
4
+ data.tar.gz: 4495846e70282207cb75ce8bf48a3450f5ff0c43
5
5
  SHA512:
6
- metadata.gz: cd050bc37813840f4f73e86e438acefab81b8fed026ccd8ea2b843d90c6e6407f3087906b5c830477ccd6585d368d2b380a3519b8625f3f2690c64224b89adec
7
- data.tar.gz: ea0f937330ed2ec0b896c5c7575a1a9f0551bbf1c06a3bfec87a8f5a9d08c3a1dc8051828bc8fd072f277aac35618792bf6620d49760cfbff614e1e8636148bd
6
+ metadata.gz: a9058bc39bf84d703cb8916d56a9cb2050be435569923ec8c947b7069ca73e4acdf26ff80002eeea769d47bf8fe632f3f9a00a5b67925a7381fd801552a12f20
7
+ data.tar.gz: c918c2138049ebced3af6067eca8bc4efb49e72f0422b9ab440c8336c00ce8ff7c19d81dc4d48c346906fa0c830697fe6b2a1e84be4213ff223c4b90438ec393
data/README.md CHANGED
@@ -51,8 +51,8 @@ The Table Helper helps you quickly build Bootstrap tables with collections of in
51
51
  The button helper renders buttons with the proper Bootstrap markup. You can optionally add icons from the Bootstrap library that are listed [here](http://getbootstrap.com/2.3.2/base-css.html#icons "Bootstrap Icons")
52
52
 
53
53
  ```haml
54
- = button_to "New Store", new_store_path
55
- = button_to "Edit Store", edit_store_path(@store), icon: "edit"
54
+ = primary_button_to "New Store", new_store_path
55
+ = primary_button_to "Edit Store", edit_store_path(@store), icon: "edit"
56
56
  ```
57
57
 
58
58
  ```haml
@@ -6,45 +6,47 @@ module BootstrapHelp
6
6
  include ActionView::Context
7
7
  include BootstrapHelp::OptionHelpers
8
8
 
9
+ BUTTON_OPTIONS = %i(icon icon_color)
10
+
9
11
  def button_toolbar(&block)
10
12
  @buttons = []
11
13
  block.call
12
14
  content_tag :div, class: "btn-toolbar" do
13
15
  content_tag :div, class: "btn-group" do
14
16
  @buttons.each do |button|
15
- concat(draw_icon_button(*button))
17
+ concat(toolbar_button_to(nil, button[:url], button[:options]))
16
18
  end
17
19
  end
18
20
  end
19
21
  end
20
22
 
21
- def button(*args)
22
- @buttons << args
23
+ def button(url=nil, options={})
24
+ @buttons << { url: url, options: options }
23
25
  nil
24
26
  end
25
27
 
26
- def button_to(name=nil, url=nil, options={})
27
- icon_suffix = options[:icon]
28
- options.delete_if { |k, v| k == :icon }
28
+ def primary_button_to(name=nil, url=nil, options={})
29
29
  button_options = append_css_class("btn btn-primary", options)
30
- link_to url, button_options do
31
- if icon_suffix.present?
32
- concat(content_tag :i, nil, class: "icon-#{icon_suffix} icon-white")
33
- name = " #{name}"
34
- end
35
- concat(name)
36
- end
30
+ draw_button(name, url, button_options)
31
+ end
32
+
33
+ def toolbar_button_to(name=nil, url=nil, options={})
34
+ button_options = append_css_class("btn", options)
35
+ draw_button(nil, url, button_options)
37
36
  end
38
37
 
39
38
  private
40
39
 
41
- def draw_icon_button(*args)
42
- icon_suffix = args.first
43
- options = args[1] || {}
44
- html_options = args[2] || {}
45
- html_options.merge!(class: "btn")
46
- link_to options, html_options do
47
- content_tag :i, nil, class: "icon-#{icon_suffix}"
40
+ def draw_button(name=nil, url=nil, options={})
41
+ icon_suffix = options[:icon]
42
+ icon_color = options.fetch(:icon_color, "black")
43
+ options.delete_if { |k, v| BUTTON_OPTIONS.include?(k) }
44
+ link_to url, options do
45
+ if icon_suffix.present?
46
+ concat(content_tag :i, nil, class: "icon-#{icon_suffix} icon-#{icon_color}")
47
+ name = " #{name}"
48
+ end
49
+ concat(name)
48
50
  end
49
51
  end
50
52
  end
@@ -1,3 +1,3 @@
1
1
  module BootstrapHelp
2
- VERSION = "0.0.28"
2
+ VERSION = "0.0.29"
3
3
  end
@@ -12,12 +12,12 @@ describe BootstrapHelp::ButtonHelpers do
12
12
 
13
13
  describe '#table_for' do
14
14
  it 'returns a bootstrap table for a given collection' do
15
- expected_result = "<div class=\"btn-toolbar\"><div class=\"btn-group\"><a class=\"btn\" href=\"/test\"><i class=\"icon-edit\"></i></a><a class=\"btn\" href=\"/test-again\"><i class=\"icon-new\"></i></a><a class=\"btn\" data-method=\"delete\" href=\"/test-again\" rel=\"nofollow\"><i class=\"icon-new\"></i></a></div></div>"
15
+ expected_result = "<div class=\"btn-toolbar\"><div class=\"btn-group\"><a class=\"btn\" href=\"/test\"><i class=\"icon-edit icon-black\"></i> </a><a class=\"btn\" href=\"/test-again\"><i class=\"icon-new icon-black\"></i> </a><a class=\"btn\" data-method=\"delete\" href=\"/test-again\" rel=\"nofollow\"><i class=\"icon-new icon-black\"></i> </a></div></div>"
16
16
 
17
17
  block = Proc.new {
18
- helpers.button 'edit', "/test"
19
- helpers.button 'new', "/test-again"
20
- helpers.button 'new', "/test-again", method: :delete
18
+ helpers.button "/test", icon: 'edit'
19
+ helpers.button "/test-again", icon: 'new'
20
+ helpers.button "/test-again", method: :delete, icon: 'new'
21
21
  }
22
22
 
23
23
  expect(helpers.button_toolbar(&block)).to eq(expected_result)
@@ -26,12 +26,13 @@ describe BootstrapHelp::ButtonHelpers do
26
26
 
27
27
  describe '#button_to' do
28
28
  it "returns a primary button" do
29
- expect(helpers.button_to('New Store', '#')).to eq("<a class=\"btn btn-primary\" href=\"#\">New Store</a>")
29
+ expect(helpers.primary_button_to('New Store', '#')).to eq("<a class=\"btn btn-primary\" href=\"#\">New Store</a>")
30
30
  end
31
31
 
32
32
  it "returns a primary button with an icon when specified" do
33
33
  expected_result = "<a class=\"btn btn-primary\" href=\"#\"><i class=\"icon-edit icon-white\"></i> New Store</a>"
34
- expect(helpers.button_to('New Store', '#', icon: "edit")).
34
+ expect(helpers.primary_button_to('New Store', '#', icon: "edit",
35
+ icon_color: "white")).
35
36
  to eq(expected_result)
36
37
  end
37
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_help
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Klina