bootstrap_help 0.0.28 → 0.0.29
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 +4 -4
- data/README.md +2 -2
- data/lib/bootstrap_help/button_helpers.rb +22 -20
- data/lib/bootstrap_help/version.rb +1 -1
- data/spec/bootstrap_helper/button_helper_spec.rb +7 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8410998cb554a1cb82729ea606d43258a10f47c
|
4
|
+
data.tar.gz: 4495846e70282207cb75ce8bf48a3450f5ff0c43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
=
|
55
|
-
=
|
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(
|
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(
|
22
|
-
@buttons <<
|
23
|
+
def button(url=nil, options={})
|
24
|
+
@buttons << { url: url, options: options }
|
23
25
|
nil
|
24
26
|
end
|
25
27
|
|
26
|
-
def
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
42
|
-
icon_suffix =
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
@@ -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
|
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
|
19
|
-
helpers.button
|
20
|
-
helpers.button
|
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.
|
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.
|
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
|