rails-bootstrap-helpers 0.0.1 → 0.1.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.
- data/README.md +336 -14
- data/lib/rails-bootstrap-helpers.rb +14 -3
- data/lib/rails-bootstrap-helpers/helpers/accordion_helper.rb +8 -0
- data/lib/rails-bootstrap-helpers/helpers/alert_helper.rb +24 -14
- data/lib/rails-bootstrap-helpers/helpers/base_helper.rb +25 -13
- data/lib/rails-bootstrap-helpers/helpers/button_helper.rb +85 -13
- data/lib/rails-bootstrap-helpers/helpers/form_tag_helper.rb +42 -10
- data/lib/rails-bootstrap-helpers/helpers/navigation_helper.rb +17 -0
- data/lib/rails-bootstrap-helpers/helpers/options_helper.rb +24 -3
- data/lib/rails-bootstrap-helpers/helpers/tag_helper.rb +26 -0
- data/lib/rails-bootstrap-helpers/helpers/url_helper.rb +17 -0
- data/lib/rails-bootstrap-helpers/rails/engine.rb +4 -2
- data/lib/rails-bootstrap-helpers/renderers/{abstract_button_renderer.rb → abstract_link_renderer.rb} +23 -7
- data/lib/rails-bootstrap-helpers/renderers/accordion_renderer.rb +94 -0
- data/lib/rails-bootstrap-helpers/renderers/action_link_renderer.rb +19 -0
- data/lib/rails-bootstrap-helpers/renderers/button_renderer.rb +6 -4
- data/lib/rails-bootstrap-helpers/renderers/content_tag_renderer.rb +67 -0
- data/lib/rails-bootstrap-helpers/renderers/dropdown_button_renderer.rb +87 -0
- data/lib/rails-bootstrap-helpers/renderers/iconic_icon_renderer.rb +75 -0
- data/lib/rails-bootstrap-helpers/renderers/row_link_renderer.rb +12 -0
- data/lib/rails-bootstrap-helpers/renderers/tabbable_renderer.rb +186 -0
- data/lib/rails-bootstrap-helpers/version.rb +1 -1
- data/spec/dummy/log/test.log +296 -0
- data/spec/helpers/accordion_helper_spec.rb +35 -0
- data/spec/helpers/alert_helper_spec.rb +11 -7
- data/spec/helpers/base_helper_spec.rb +44 -0
- data/spec/helpers/button_helper_spec.rb +214 -9
- data/spec/helpers/form_tag_helper_spec.rb +27 -0
- data/spec/helpers/navigation_helper_spec.rb +228 -0
- data/spec/helpers/options_helper_spec.rb +50 -0
- data/spec/helpers/tag_helper_spec.rb +26 -0
- data/spec/helpers/url_helper_spec.rb +33 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/html.rb +9 -0
- data/spec/support/matchers/helpers/alert_helper/render_bs_alert.rb +19 -10
- data/spec/support/matchers/helpers/base_helper/render_icon.rb +18 -1
- data/spec/support/matchers/helpers/base_helper/render_iconic_icon.rb +191 -0
- data/spec/support/matchers/helpers/button_helper/render_bs_button_to.rb +44 -3
- data/spec/support/matchers/helpers/button_helper/render_inline_button_to.rb +1 -1
- data/spec/support/matchers/helpers/form_tag_helper/render_bs_button_tag.rb +39 -1
- data/spec/support/matchers/helpers/form_tag_helper/render_bs_submit_tag.rb +96 -0
- data/spec/support/matchers/helpers/url_helper/render_action_link_to.rb +123 -0
- data/spec/support/matchers/helpers/url_helper/render_row_link_to.rb +97 -0
- metadata +59 -8
- checksums.yaml +0 -15
@@ -44,4 +44,54 @@ describe RailsBootstrapHelpers::Helpers::OptionsHelper do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
|
+
|
48
|
+
describe "append_class!" do
|
49
|
+
it "should return the options hash" do
|
50
|
+
options = { class: "foo" }
|
51
|
+
helper.append_class!(options, "bar").should == options
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with non existing class" do
|
55
|
+
let(:options) { { } }
|
56
|
+
|
57
|
+
it "should append the given class" do
|
58
|
+
helper.append_class!(options, "foo")
|
59
|
+
options[:class].should == "foo"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should add a new key, :class, to the options hash" do
|
63
|
+
helper.append_class!(options, "foo")
|
64
|
+
options.key?(:class).should be_true
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when appending multiple classes" do
|
68
|
+
let(:classes) { %w[foo bar button small] }
|
69
|
+
|
70
|
+
it "should append all the given classes" do
|
71
|
+
helper.append_class!(options, *classes)
|
72
|
+
options[:class].should == classes.join(" ")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "with existing class" do
|
78
|
+
it "should preserve the existing class and append the new" do
|
79
|
+
options = { class: "foo" }
|
80
|
+
helper.append_class!(options, "bar")
|
81
|
+
options[:class].should == "foo bar"
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should handle 'class' as a key" do
|
85
|
+
options = { "class" => "foo" }
|
86
|
+
helper.append_class!(options, "bar")
|
87
|
+
options["class"].should == "foo bar"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should handle :class as key" do
|
91
|
+
options = { class: "foo" }
|
92
|
+
helper.append_class!(options, "bar")
|
93
|
+
options[:class].should == "foo bar"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
47
97
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RailsBootstrapHelpers::Helpers::TagHelper do
|
4
|
+
describe "bs_content_tag" do
|
5
|
+
it "should render an HTML tag" do
|
6
|
+
expected_html = <<-eos
|
7
|
+
<div id="foo">
|
8
|
+
<div>
|
9
|
+
foo
|
10
|
+
</div>
|
11
|
+
bar
|
12
|
+
</div>
|
13
|
+
eos
|
14
|
+
|
15
|
+
html = bs_content_tag :div, id: "foo" do
|
16
|
+
bs_content_tag :div do
|
17
|
+
append "foo"
|
18
|
+
end
|
19
|
+
|
20
|
+
append "bar"
|
21
|
+
end
|
22
|
+
|
23
|
+
html.should == expected_html
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RailsBootstrapHelpers::Helpers::UrlHelper do
|
4
|
+
describe "action_link_to" do
|
5
|
+
context "with url" do
|
6
|
+
it { should render_action_link_to("foo").to("bar") }
|
7
|
+
end
|
8
|
+
|
9
|
+
context "with style" do
|
10
|
+
it { should render_action_link_to("foo") }
|
11
|
+
it { should render_action_link_to("foo").with_style(:default).with_class("asd") }
|
12
|
+
it { should render_action_link_to("foo").with_style(:primary) }
|
13
|
+
it { should render_action_link_to("foo").with_style(:info) }
|
14
|
+
it { should render_action_link_to("foo").with_style(:success) }
|
15
|
+
it { should render_action_link_to("foo").with_style(:warning) }
|
16
|
+
it { should render_action_link_to("foo").with_style(:danger) }
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with tooltip" do
|
20
|
+
it { should render_action_link_to("foo").with_tooltip("asd") }
|
21
|
+
it { should render_action_link_to("foo").with_tooltip("asd").with_tooltip_position(:left) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "row_link_to" do
|
26
|
+
it { should render_row_link_to("foo").to("bar") }
|
27
|
+
|
28
|
+
context "with tooltip" do
|
29
|
+
it { should render_row_link_to("foo").with_tooltip("asd") }
|
30
|
+
it { should render_row_link_to("foo").with_tooltip("asd").with_tooltip_position(:left) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,11 +7,13 @@ Spork.prefork do
|
|
7
7
|
|
8
8
|
require "rspec/rails"
|
9
9
|
require "rspec/autorun"
|
10
|
+
require "pry"
|
10
11
|
|
11
12
|
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
12
13
|
|
13
14
|
RSpec.configure do |config|
|
14
15
|
config.order = "random"
|
16
|
+
config.include Html
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -12,15 +12,15 @@ RSpec::Matchers.define :render_bs_alert do |text|
|
|
12
12
|
def cls
|
13
13
|
cls = "alert"
|
14
14
|
|
15
|
-
if type?
|
16
|
-
|
15
|
+
if style? || type?
|
16
|
+
style = (options[:style] || options[:type]).to_s
|
17
17
|
|
18
|
-
if
|
19
|
-
|
18
|
+
if style == "notice"
|
19
|
+
style = "success"
|
20
20
|
end
|
21
21
|
|
22
|
-
unless
|
23
|
-
cls << " alert-#{
|
22
|
+
unless style == "warning" || style == "default"
|
23
|
+
cls << " alert-#{style}"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -53,7 +53,11 @@ RSpec::Matchers.define :render_bs_alert do |text|
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def html_class
|
56
|
-
@html_class ||= class? ?
|
56
|
+
@html_class ||= class? ? @class.to_s : options[:status].to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
def style?
|
60
|
+
@style_set
|
57
61
|
end
|
58
62
|
|
59
63
|
def type?
|
@@ -69,7 +73,12 @@ RSpec::Matchers.define :render_bs_alert do |text|
|
|
69
73
|
end
|
70
74
|
|
71
75
|
def class?
|
72
|
-
|
76
|
+
!@class.nil?
|
77
|
+
end
|
78
|
+
|
79
|
+
chain :with_style do |style|
|
80
|
+
options[:style] = style
|
81
|
+
@style_set = true
|
73
82
|
end
|
74
83
|
|
75
84
|
chain :with_type do |type|
|
@@ -88,8 +97,7 @@ RSpec::Matchers.define :render_bs_alert do |text|
|
|
88
97
|
end
|
89
98
|
|
90
99
|
chain :as_class do |cls|
|
91
|
-
|
92
|
-
@class_set = true
|
100
|
+
@class = cls
|
93
101
|
end
|
94
102
|
|
95
103
|
match do
|
@@ -109,6 +117,7 @@ RSpec::Matchers.define :render_bs_alert do |text|
|
|
109
117
|
desc = "render an alert '#{text}'"
|
110
118
|
desc << " as block" if block?
|
111
119
|
desc << " with dismiss button" if dismiss_button?
|
120
|
+
desc << " with the style: #{options[:style]}" if style?
|
112
121
|
desc << " with the type: #{options[:type]}" if type?
|
113
122
|
desc << " as the class #{html_class}" if class?
|
114
123
|
desc
|
@@ -13,12 +13,21 @@ RSpec::Matchers.define :render_icon do |icon|
|
|
13
13
|
cls
|
14
14
|
end
|
15
15
|
|
16
|
+
def cls
|
17
|
+
@cls ||= begin
|
18
|
+
base_class = "icon-#{icon}"
|
19
|
+
cls = extra_class.present? ? extra_class + " " + base_class : base_class
|
20
|
+
cls << " icon-white" if invert?
|
21
|
+
cls
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
16
25
|
def expected
|
17
26
|
@render_icon_expected ||= "<i class=\"#{cls}\"></i>"
|
18
27
|
end
|
19
28
|
|
20
29
|
def got
|
21
|
-
@got ||= helper.icon(icon, invert: options[:invert])
|
30
|
+
@got ||= helper.icon(icon, invert: options[:invert], class: options[:class])
|
22
31
|
end
|
23
32
|
|
24
33
|
def failure_message (is_not)
|
@@ -30,11 +39,19 @@ RSpec::Matchers.define :render_icon do |icon|
|
|
30
39
|
@invert_set
|
31
40
|
end
|
32
41
|
|
42
|
+
def extra_class
|
43
|
+
options[:class]
|
44
|
+
end
|
45
|
+
|
33
46
|
chain :inverted do |invert|
|
34
47
|
options[:invert] = invert
|
35
48
|
@invert_set = true
|
36
49
|
end
|
37
50
|
|
51
|
+
chain :with_class do |cls|
|
52
|
+
options[:class] = cls
|
53
|
+
end
|
54
|
+
|
38
55
|
match do
|
39
56
|
@icon = icon
|
40
57
|
expected == got
|
@@ -0,0 +1,191 @@
|
|
1
|
+
RSpec::Matchers.define :render_iconic_icon do |icon|
|
2
|
+
def options
|
3
|
+
@options ||= { }
|
4
|
+
end
|
5
|
+
|
6
|
+
def icon
|
7
|
+
@icon
|
8
|
+
end
|
9
|
+
|
10
|
+
def cls
|
11
|
+
@cls ||= begin
|
12
|
+
"iconic-#{icon}".tap do |cls|
|
13
|
+
cls << bs_style_class
|
14
|
+
cls << action_style_class
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def bs_style_class
|
20
|
+
if bs_style = options[:bs_style]
|
21
|
+
if bs_style.to_s == "muted"
|
22
|
+
" muted"
|
23
|
+
else
|
24
|
+
" text-#{bs_style}"
|
25
|
+
end
|
26
|
+
else
|
27
|
+
""
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def action_style_class
|
32
|
+
if action_style = options[:action_style]
|
33
|
+
" act".tap do |cls|
|
34
|
+
unless action_style.to_s == "default"
|
35
|
+
cls << " act-#{action_style}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
else
|
39
|
+
""
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def append_style (key, value)
|
44
|
+
if value
|
45
|
+
@style ||= ""
|
46
|
+
|
47
|
+
unless @style.end_with?(";")
|
48
|
+
@style << ";"
|
49
|
+
end
|
50
|
+
|
51
|
+
@style << " "
|
52
|
+
|
53
|
+
@style << "#{key}: #{value};"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def handle_size
|
58
|
+
if size = options[:size]
|
59
|
+
size = size.to_s
|
60
|
+
|
61
|
+
if size.to_i > 0
|
62
|
+
size << "px"
|
63
|
+
end
|
64
|
+
|
65
|
+
append_style("font-size", size)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def html_attributes
|
70
|
+
handle_size
|
71
|
+
|
72
|
+
if color = options[:color]
|
73
|
+
append_style(:color, color)
|
74
|
+
end
|
75
|
+
|
76
|
+
attrs = { class: cls }
|
77
|
+
attrs[:style] = @style if @style.present?
|
78
|
+
|
79
|
+
if tooltip?
|
80
|
+
if tooltip_position?
|
81
|
+
attrs[:"data-placement"] = options[:tooltip_position]
|
82
|
+
end
|
83
|
+
|
84
|
+
attrs[:"data-toggle"] = "tooltip"
|
85
|
+
attrs[:title] = options[:tooltip]
|
86
|
+
end
|
87
|
+
|
88
|
+
attrs.map { |k, v| "#{k}=\"#{v}\"" }.join(" ")
|
89
|
+
end
|
90
|
+
|
91
|
+
def expected
|
92
|
+
@render_icon_expected ||= "<i #{html_attributes}></i>"
|
93
|
+
end
|
94
|
+
|
95
|
+
def got
|
96
|
+
@got ||= helper.iconic_icon(icon, options)
|
97
|
+
end
|
98
|
+
|
99
|
+
def failure_message (is_not)
|
100
|
+
ex = is_not ? "expected not" : "expected"
|
101
|
+
"#{ex}: #{expected}\n got: #{got}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def bs_style?
|
105
|
+
options[:bs_style]
|
106
|
+
end
|
107
|
+
|
108
|
+
def action_style?
|
109
|
+
options[:action_style]
|
110
|
+
end
|
111
|
+
|
112
|
+
def color?
|
113
|
+
options[:color]
|
114
|
+
end
|
115
|
+
|
116
|
+
def size?
|
117
|
+
options[:size]
|
118
|
+
end
|
119
|
+
|
120
|
+
def tooltip?
|
121
|
+
options.key?(:tooltip)
|
122
|
+
end
|
123
|
+
|
124
|
+
def tooltip_position?
|
125
|
+
options.key?(:tooltip_position)
|
126
|
+
end
|
127
|
+
|
128
|
+
chain :inverted do |invert|
|
129
|
+
options[:invert] = invert
|
130
|
+
@invert_set = true
|
131
|
+
end
|
132
|
+
|
133
|
+
chain :with_class do |cls|
|
134
|
+
options[:class] = cls
|
135
|
+
end
|
136
|
+
|
137
|
+
chain :with_action_style do |cls|
|
138
|
+
options[:action_style] = cls
|
139
|
+
end
|
140
|
+
|
141
|
+
chain :with_bs_style do |cls|
|
142
|
+
options[:bs_style] = cls
|
143
|
+
end
|
144
|
+
|
145
|
+
chain :with_size do |size|
|
146
|
+
options[:size]
|
147
|
+
end
|
148
|
+
|
149
|
+
chain :with_color do |color|
|
150
|
+
options[:color]
|
151
|
+
end
|
152
|
+
|
153
|
+
chain :with_tooltip do |tooltip|
|
154
|
+
options[:tooltip] = tooltip
|
155
|
+
end
|
156
|
+
|
157
|
+
chain :with_tooltip_position do |tooltip_position|
|
158
|
+
options[:tooltip_position] = tooltip_position
|
159
|
+
end
|
160
|
+
|
161
|
+
match do
|
162
|
+
@icon = icon
|
163
|
+
expected == got
|
164
|
+
end
|
165
|
+
|
166
|
+
failure_message_for_should do
|
167
|
+
failure_message(false)
|
168
|
+
end
|
169
|
+
|
170
|
+
failure_message_for_should_not do
|
171
|
+
failure_message(true)
|
172
|
+
end
|
173
|
+
|
174
|
+
description do
|
175
|
+
# ext = invert? ? "inverted " : ""
|
176
|
+
# "render an icon with the #{ext}style: #{icon}"
|
177
|
+
|
178
|
+
desc = "render an iconic icon '#{icon}'"
|
179
|
+
descs = []
|
180
|
+
descs << "with the Bootstrap style: #{options[:bs_style]}" if bs_style?
|
181
|
+
descs << "with the action link style: #{options[:action_style]}" if action_style?
|
182
|
+
descs << "with the color: #{options[:color]}" if color?
|
183
|
+
descs << "with the size: #{options[:size]}" if size?
|
184
|
+
|
185
|
+
descs << "with the '#{options[:tooltip]}' tooltip" if tooltip?
|
186
|
+
descs << "with the '#{options[:tooltip_position]}' tooltip position" if tooltip_position?
|
187
|
+
|
188
|
+
desc << " " if descs.any?
|
189
|
+
desc << descs.to_sentence
|
190
|
+
end
|
191
|
+
end
|
@@ -9,7 +9,7 @@ RSpec::Matchers.define :render_bs_button_to do |text|
|
|
9
9
|
|
10
10
|
def cls
|
11
11
|
@cls ||= begin
|
12
|
-
cls = "btn"
|
12
|
+
cls = extra_class.present? ? "#{extra_class} btn" : "btn"
|
13
13
|
cls << " btn-#{options[:style]}" if style?
|
14
14
|
cls << " btn-#{options[:size]}" if size?
|
15
15
|
cls
|
@@ -35,8 +35,23 @@ RSpec::Matchers.define :render_bs_button_to do |text|
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def html_attributes
|
39
|
+
attrs = { href: url, class: cls }
|
40
|
+
|
41
|
+
if tooltip?
|
42
|
+
if tooltip_position?
|
43
|
+
attrs[:"data-placement"] = options[:tooltip_position]
|
44
|
+
end
|
45
|
+
|
46
|
+
attrs[:"data-toggle"] = "tooltip"
|
47
|
+
attrs[:title] = options[:tooltip]
|
48
|
+
end
|
49
|
+
|
50
|
+
attrs.map { |k, v| "#{k}=\"#{v}\"" }.join(" ")
|
51
|
+
end
|
52
|
+
|
38
53
|
def expected
|
39
|
-
@render_button_expected ||= "<a
|
54
|
+
@render_button_expected ||= "<a #{html_attributes}>#{text_with_icon}</a>"
|
40
55
|
end
|
41
56
|
|
42
57
|
def got
|
@@ -76,6 +91,18 @@ RSpec::Matchers.define :render_bs_button_to do |text|
|
|
76
91
|
@icon_position_set
|
77
92
|
end
|
78
93
|
|
94
|
+
def tooltip?
|
95
|
+
options.key?(:tooltip)
|
96
|
+
end
|
97
|
+
|
98
|
+
def tooltip_position?
|
99
|
+
options.key?(:tooltip_position)
|
100
|
+
end
|
101
|
+
|
102
|
+
def extra_class
|
103
|
+
options[:class]
|
104
|
+
end
|
105
|
+
|
79
106
|
chain :to do |url|
|
80
107
|
@url = url
|
81
108
|
end
|
@@ -102,7 +129,19 @@ RSpec::Matchers.define :render_bs_button_to do |text|
|
|
102
129
|
|
103
130
|
chain :with_icon_position do |icon_position|
|
104
131
|
options[:icon_position] = icon_position
|
105
|
-
@
|
132
|
+
@icon_position_set = true
|
133
|
+
end
|
134
|
+
|
135
|
+
chain :with_class do |cls|
|
136
|
+
options[:class] = cls
|
137
|
+
end
|
138
|
+
|
139
|
+
chain :with_tooltip do |tooltip|
|
140
|
+
options[:tooltip] = tooltip
|
141
|
+
end
|
142
|
+
|
143
|
+
chain :with_tooltip_position do |tooltip_position|
|
144
|
+
options[:tooltip_position] = tooltip_position
|
106
145
|
end
|
107
146
|
|
108
147
|
match do
|
@@ -128,6 +167,8 @@ RSpec::Matchers.define :render_bs_button_to do |text|
|
|
128
167
|
|
129
168
|
descs << "with the #{ext}icon: #{options[:icon]}" if icon?
|
130
169
|
descs << "with the icon_position: #{options[:icon_position]}" if icon_position?
|
170
|
+
descs << "with the '#{options[:tooltip]}' tooltip" if tooltip?
|
171
|
+
descs << "with the '#{options[:tooltip_position]}' tooltip position" if tooltip_position?
|
131
172
|
|
132
173
|
desc << " " if descs.any?
|
133
174
|
desc << descs.to_sentence
|