bh 1.0.1 → 1.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.
@@ -12,26 +12,42 @@ describe 'fields_for' do
12
12
  let(:title) { nil }
13
13
  let(:fields_block) { Proc.new {|f| f.text_field :street } }
14
14
 
15
- specify 'adds a <fieldset> that looks like a Bootstrap panel' do
16
- expect(form).to include 'fieldset class="panel panel-default">'
17
- end
15
+ describe 'with the :fieldset option' do
16
+ specify 'not set, wraps the fields in a <fieldset> styled like a panel' do
17
+ expect(form).to include 'fieldset class="panel panel-default">'
18
+ end
18
19
 
19
- context 'given a title option, uses the provided title' do
20
- let(:options) { {title: 'Your address'} }
21
- it { expect(form).to include '<div class="panel-heading">Your address</div>' }
22
- end
20
+ describe 'set to true, wraps the fields in a <fieldset> styled like a panel' do
21
+ let(:options) { {fieldset: true} }
22
+ it { expect(form).to include 'fieldset class="panel panel-default">' }
23
+ end
23
24
 
24
- specify 'not given a title, generates one from the field name' do
25
- expect(form).to include '<div class="panel-heading">Address</div>'
25
+ describe 'set to false, does not wrap the fields in a <fieldset>' do
26
+ let(:options) { {fieldset: false} }
27
+ it { expect(form).not_to include 'fieldset' }
28
+ end
26
29
  end
27
30
 
28
- specify 'given no layout, inherits the layout options of the parent form' do
29
- expect(form).to match %r{<div class="form-group"><label for.+?>Street</label>}
31
+ describe 'with the :title option' do
32
+ specify 'not set, generates a title from the field name' do
33
+ expect(form).to include '<div class="panel-heading">Address</div>'
34
+ end
35
+
36
+ context 'set to a value, uses the value as the panel title' do
37
+ let(:options) { {title: 'Your address'} }
38
+ it { expect(form).to include '<div class="panel-heading">Your address</div>' }
39
+ end
30
40
  end
31
41
 
32
- context 'given a layout, uses its own layout' do
33
- let(:options) { {layout: :horizontal} }
34
- it { expect(form).to match %r{<div class="form-group"><label class="col-sm-3 control-label" for.+?>Street</label>} }
42
+ describe 'with the :layout option' do
43
+ specify 'not set, inherits the layout options of the parent form' do
44
+ expect(form).to match %r{<div class="form-group"><label for.+?>Street</label>}
45
+ end
46
+
47
+ context 'set to a value, uses the value as the layout' do
48
+ let(:options) { {layout: :horizontal} }
49
+ it { expect(form).to match %r{<div class="form-group"><label class="col-sm-3 control-label" for.+?>Street</label>} }
50
+ end
35
51
  end
36
52
 
37
53
  context 'given a record object' do
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'bh/helpers/icon_helper'
3
+ include Bh::IconHelper
4
+
5
+ describe 'icon' do
6
+ context 'given the icon name' do
7
+ specify 'has underscores, returns the icon with dashes' do
8
+ expect(icon :zoom_in).to eq '<span class="glyphicon glyphicon-zoom-in"></span>'
9
+ end
10
+
11
+ specify 'has dashes, returns the icon with dashes' do
12
+ expect(icon 'zoom-out').to eq '<span class="glyphicon glyphicon-zoom-out"></span>'
13
+ end
14
+
15
+ specify 'is missing, returns an empty icon' do
16
+ expect(icon).to eq '<span class="glyphicon"></span>'
17
+ end
18
+ end
19
+
20
+ context 'given the :library option (underscored)' do
21
+ specify 'is glyphicon, shows a Glyphicons icon' do
22
+ expect(icon :heart, library: :glyphicon).to eq '<span class="glyphicon glyphicon-heart"></span>'
23
+ end
24
+
25
+ specify 'is font-awesome, shows a Font Awesome icon' do
26
+ expect(icon :heart, library: 'font-awesome').to eq '<span class="fa fa-heart"></span>'
27
+ end
28
+
29
+ specify 'is font_awesome, shows a Font Awesome icon' do
30
+ expect(icon :heart, library: :font_awesome).to eq '<span class="fa fa-heart"></span>'
31
+ end
32
+
33
+ specify 'is any other string, uses the string as a prefix' do
34
+ expect(icon :heart, library: :custom).to eq '<span class="custom custom-heart"></span>'
35
+ end
36
+
37
+ specify 'is missing, shows a Glyphicons icon' do
38
+ expect(icon :heart).to eq '<span class="glyphicon glyphicon-heart"></span>'
39
+ end
40
+ end
41
+
42
+ specify 'given extra options, passes the options to the <span>' do
43
+ expect(icon :ok, title: 'Approved').to eq '<span class="glyphicon glyphicon-ok" title="Approved"></span>'
44
+ end
45
+ end
@@ -2,11 +2,13 @@ require 'spec_helper'
2
2
  require 'action_dispatch'
3
3
 
4
4
  require 'bh/helpers/alert_helper'
5
+ require 'bh/helpers/dropdown_helper'
5
6
  require 'bh/helpers/link_to_helper'
6
7
  require 'bh/helpers/nav_helper'
7
8
  require 'bh/helpers/navbar_helper'
8
9
 
9
10
  include Bh::AlertHelper
11
+ include Bh::DropdownHelper
10
12
  include Bh::LinkToHelper
11
13
  include Bh::NavHelper
12
14
  include Bh::NavbarHelper
@@ -55,6 +57,17 @@ describe 'link_to' do
55
57
  it { expect(html).to include 'li class="active"' }
56
58
  end
57
59
  end
60
+
61
+ context 'inside a dropdown' do
62
+ let(:views_folder) { File.expand_path('../../../lib/bh/views', __FILE__) }
63
+ let(:lookup_context) { ActionView::LookupContext.new views_folder }
64
+ let(:view_renderer) { ActionView::Renderer.new lookup_context }
65
+ let(:html) { dropdown('Menu') { link } }
66
+
67
+ specify 'surrounds the link in a list item, and adds role, tabindex' do
68
+ expect(html).to include '<li role="presentation"><a href="/" role="menuitem" tabindex="-1">Home</a></li>'
69
+ end
70
+ end
58
71
  end
59
72
 
60
73
  context 'used with a block' do
@@ -96,5 +109,16 @@ describe 'link_to' do
96
109
  it { expect(html).to include 'li class="active"' }
97
110
  end
98
111
  end
112
+
113
+ context 'inside a dropdown' do
114
+ let(:views_folder) { File.expand_path('../../../lib/bh/views', __FILE__) }
115
+ let(:lookup_context) { ActionView::LookupContext.new views_folder }
116
+ let(:view_renderer) { ActionView::Renderer.new lookup_context }
117
+ let(:html) { dropdown('Menu') { link } }
118
+
119
+ specify 'surrounds the link in a list item, and adds role, tabindex' do
120
+ expect(html).to include '<li role="presentation"><a href="/" role="menuitem" tabindex="-1">Home</a></li>'
121
+ end
122
+ end
99
123
  end
100
124
  end
@@ -0,0 +1,114 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'bh/helpers/progress_bar_helper'
5
+
6
+ include Bh::ProgressBarHelper
7
+
8
+ describe 'progress_bar' do
9
+ context 'without options' do
10
+ let(:html) { progress_bar }
11
+
12
+ it 'displays an empty progress bar' do
13
+ expect(html).to include '<div class="progress">'
14
+ end
15
+ end
16
+
17
+ context 'with a hash of options' do
18
+ let(:html) { progress_bar options.merge(percentage: 30) }
19
+ let(:options) { {} }
20
+
21
+ it 'displays one progress bar for the given value' do
22
+ expect(html).to include '<div aria-valuemax="100" aria-valuemin="0" aria-valuenow="30" class="progress-bar" role="progressbar" style="width: 30%">'
23
+ end
24
+
25
+ describe 'given the :label option' do
26
+ specify 'is not set, hides the label' do
27
+ expect(html).to include '<span class="sr-only">30%</span>'
28
+ end
29
+
30
+ context 'is set to false, hides the label' do
31
+ let(:options) { {label: false }}
32
+ it { expect(html).to include '<span class="sr-only">30%</span>' }
33
+ end
34
+
35
+ context 'is set to true, displays a label matching the percentage' do
36
+ let(:options) { {label: true }}
37
+ it { expect(html).to include '30%</div>' }
38
+ end
39
+
40
+ context 'is a string, displays the string as the label' do
41
+ let(:options) { {label: "Thirty percent" }}
42
+ it { expect(html).to include 'Thirty percent</div>' }
43
+ end
44
+ end
45
+
46
+ describe 'given the :context option' do
47
+ specify 'is not set, shows a default bar' do
48
+ expect(html).to include 'class="progress-bar"'
49
+ end
50
+
51
+ context 'is set to :success, shows a "success" bar' do
52
+ let(:options) { {context: :success} }
53
+ it { expect(html).to include 'class="progress-bar progress-bar-success"' }
54
+ end
55
+
56
+ context 'is set to :info, shows a "info" bar' do
57
+ let(:options) { {context: :info} }
58
+ it { expect(html).to include 'class="progress-bar progress-bar-info"' }
59
+ end
60
+
61
+ context 'is set to :warning, shows a "warning" bar' do
62
+ let(:options) { {context: :warning} }
63
+ it { expect(html).to include 'class="progress-bar progress-bar-warning"' }
64
+ end
65
+
66
+ context 'is set to :danger, shows a "danger" bar' do
67
+ let(:options) { {context: :danger} }
68
+ it { expect(html).to include 'class="progress-bar progress-bar-danger"' }
69
+ end
70
+ end
71
+
72
+ describe 'given the :striped option' do
73
+ specify 'is not set, shows a solid color bar' do
74
+ expect(html).to include 'class="progress-bar"'
75
+ end
76
+
77
+ context 'is set to false, shows a solid color bar' do
78
+ let(:options) { {striped: false} }
79
+ it { expect(html).to include 'class="progress-bar"' }
80
+ end
81
+
82
+ context 'is set to true, shows a striped color bar' do
83
+ let(:options) { {striped: true} }
84
+ it { expect(html).to include 'class="progress-bar progress-bar-striped"' }
85
+ end
86
+ end
87
+
88
+ describe 'given the :animated option' do
89
+ specify 'is not set, shows a static color bar' do
90
+ expect(html).to include 'class="progress-bar"'
91
+ end
92
+
93
+ context 'is set to false, shows a static color bar' do
94
+ let(:options) { {animated: false} }
95
+ it { expect(html).to include 'class="progress-bar"' }
96
+ end
97
+
98
+ context 'is set to true, shows an animated color bar' do
99
+ let(:options) { {animated: true} }
100
+ it { expect(html).to include 'class="progress-bar progress-bar-striped active"' }
101
+ end
102
+ end
103
+ end
104
+
105
+ context 'with an array of options' do
106
+ let(:html) { progress_bar [options_bar_1, options_bar_2] }
107
+ let(:options_bar_1) { {percentage: 20, context: :success, label: true} }
108
+ let(:options_bar_2) { {percentage: 30, animated: true, label: 'Current'} }
109
+
110
+ it 'displays a group of stacked progress bars with their options' do
111
+ expect(html).to match %r{^<div class="progress"><div.+aria-valuenow="20" class="progress-bar progress-bar-success".+style="width: 20%">20% \(success\)</div>\n<div.+aria-valuenow="30" class="progress-bar progress-bar-striped active".+style="width: 30%">Current</div></div>$}m
112
+ end
113
+ end
114
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bh
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-14 00:00:00.000000000 Z
11
+ date: 2014-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: middleman-core
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: Bh - Bootstrap Helpers
126
140
  email:
127
141
  - claudio@fullscreen.net
@@ -132,20 +146,24 @@ files:
132
146
  - ".gitignore"
133
147
  - ".rspec"
134
148
  - ".travis.yml"
149
+ - ".yardopts"
135
150
  - CHANGELOG.md
136
151
  - Gemfile
137
152
  - MIT-LICENSE
138
153
  - README.md
139
154
  - Rakefile
140
155
  - bh.gemspec
156
+ - config.rb
141
157
  - gemfiles/Gemfile.rails-3.x
142
158
  - gemfiles/Gemfile.rails-4.x
143
159
  - lib/bh.rb
144
160
  - lib/bh/form_builders/form_builder.rb
145
161
  - lib/bh/helpers/alert_helper.rb
146
162
  - lib/bh/helpers/base_helper.rb
163
+ - lib/bh/helpers/button_helper.rb
147
164
  - lib/bh/helpers/button_to_helper.rb
148
165
  - lib/bh/helpers/cdn_helper.rb
166
+ - lib/bh/helpers/dropdown_helper.rb
149
167
  - lib/bh/helpers/form/base_helper.rb
150
168
  - lib/bh/helpers/form/check_box_helper.rb
151
169
  - lib/bh/helpers/form/field_helper.rb
@@ -159,18 +177,27 @@ files:
159
177
  - lib/bh/helpers/form/submit_helper.rb
160
178
  - lib/bh/helpers/form_for_helper.rb
161
179
  - lib/bh/helpers/glyphicon_helper.rb
180
+ - lib/bh/helpers/icon_helper.rb
162
181
  - lib/bh/helpers/link_to_helper.rb
163
182
  - lib/bh/helpers/modal_helper.rb
164
183
  - lib/bh/helpers/nav_helper.rb
165
184
  - lib/bh/helpers/navbar_helper.rb
166
185
  - lib/bh/helpers/panel_helper.rb
167
186
  - lib/bh/helpers/panel_row_helper.rb
187
+ - lib/bh/helpers/progress_bar_helper.rb
188
+ - lib/bh/middleman.rb
168
189
  - lib/bh/railtie.rb
169
190
  - lib/bh/version.rb
191
+ - lib/bh/views/bh/_dropdown.html.erb
192
+ - lib/bh/views/bh/_dropdown_split.html.erb
170
193
  - lib/bh/views/bh/_modal.html.erb
194
+ - spec/dummy/index.html.erb
195
+ - spec/dummy/layouts/default.erb
171
196
  - spec/helpers/alert_helper_spec.rb
197
+ - spec/helpers/button_helper_spec.rb
172
198
  - spec/helpers/button_to_helper_spec.rb
173
199
  - spec/helpers/cdn_helper_spec.rb
200
+ - spec/helpers/dropdown_helper_spec.rb
174
201
  - spec/helpers/form/check_box_helper_spec.rb
175
202
  - spec/helpers/form/field_helper_spec.rb
176
203
  - spec/helpers/form/fields_for_helper_spec.rb
@@ -183,12 +210,14 @@ files:
183
210
  - spec/helpers/form/submit_helper_spec.rb
184
211
  - spec/helpers/form_for_helper_spec.rb
185
212
  - spec/helpers/glyphicon_helper_spec.rb
213
+ - spec/helpers/icon_helper_spec.rb
186
214
  - spec/helpers/link_to_helper_spec.rb
187
215
  - spec/helpers/modal_helper_spec.rb
188
216
  - spec/helpers/nav_helper_spec.rb
189
217
  - spec/helpers/navbar_helper_spec.rb
190
218
  - spec/helpers/panel_helper_spec.rb
191
219
  - spec/helpers/panel_row_helper_spec.rb
220
+ - spec/helpers/progress_bar_helper_spec.rb
192
221
  - spec/spec_helper.rb
193
222
  homepage: http://github.com/Fullscreen/bh
194
223
  licenses:
@@ -216,9 +245,13 @@ specification_version: 4
216
245
  summary: Bh provides a set of powerful helpers that streamlines the use of Bootstrap
217
246
  components in Rails views.
218
247
  test_files:
248
+ - spec/dummy/index.html.erb
249
+ - spec/dummy/layouts/default.erb
219
250
  - spec/helpers/alert_helper_spec.rb
251
+ - spec/helpers/button_helper_spec.rb
220
252
  - spec/helpers/button_to_helper_spec.rb
221
253
  - spec/helpers/cdn_helper_spec.rb
254
+ - spec/helpers/dropdown_helper_spec.rb
222
255
  - spec/helpers/form/check_box_helper_spec.rb
223
256
  - spec/helpers/form/field_helper_spec.rb
224
257
  - spec/helpers/form/fields_for_helper_spec.rb
@@ -231,11 +264,13 @@ test_files:
231
264
  - spec/helpers/form/submit_helper_spec.rb
232
265
  - spec/helpers/form_for_helper_spec.rb
233
266
  - spec/helpers/glyphicon_helper_spec.rb
267
+ - spec/helpers/icon_helper_spec.rb
234
268
  - spec/helpers/link_to_helper_spec.rb
235
269
  - spec/helpers/modal_helper_spec.rb
236
270
  - spec/helpers/nav_helper_spec.rb
237
271
  - spec/helpers/navbar_helper_spec.rb
238
272
  - spec/helpers/panel_helper_spec.rb
239
273
  - spec/helpers/panel_row_helper_spec.rb
274
+ - spec/helpers/progress_bar_helper_spec.rb
240
275
  - spec/spec_helper.rb
241
276
  has_rdoc: