bh 0.0.3 → 0.0.4

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: fd20f354ba7792ddb18ca83618d77b0510bbc3c8
4
- data.tar.gz: 447b0f2f6e06aaabbba876616a29db1d2a4e577f
3
+ metadata.gz: 236887d8267590a9cfaf81696e3b3565e8aa7e0e
4
+ data.tar.gz: fdf3d185fc9586b453ef27daa4907a48732bc37b
5
5
  SHA512:
6
- metadata.gz: 0d18cd3d04c5d8f1af19bf3ead08f17e27045b4c592ba7e68ed72e9b1102ad9d922ae8f14036a69872aeceadedda75aebf3679704b03d1d6dcedb7762ee897dc
7
- data.tar.gz: b0de752c4c5cd633e5683f1cf6bba061cc16eea865165b12d7e5f5adaee5a33233ea28248431d5b4108f07aa768a4912cd22b0e2aa1a8cbe1b0e1542b881c733
6
+ metadata.gz: fd2c01c95a5821d9e1d3f45493a9c0bb29e76eceeb6f508b9e650ca6a567793354c6540eca6277aa36dc4592e3687aeb8746babb42ce54911078df368abad771
7
+ data.tar.gz: 13f142de14c3ddd20dbba55af3c270a57e49cd23d2379579ea336c63e90e63559656d101df64dffe60f7b7ef9e0a9614fb99ef4c2bac902ad6e3ef374b0bbe53
@@ -6,6 +6,13 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+ ## 0.0.4 - 2014-08-17
10
+
11
+ * [FEATURE] Add `modal`
12
+ * [FEATURE] Add `panel_row`
13
+ * [FEATURE] Add `panel`
14
+ * [FEATURE] Add `glyphicon`
15
+
9
16
  ## 0.0.3 - 2014-08-15
10
17
 
11
18
  * [FEATURE] Add `bootstrap_css`, `bootstrap_theme_css` and `bootstrap_js`
data/README.md CHANGED
@@ -46,7 +46,7 @@ How to install
46
46
 
47
47
  Bh is meant to be included in Rails apps by adding this line to the Gemfile:
48
48
 
49
- gem 'bh', '~> 0.0.3'
49
+ gem 'bh', '~> 0.0.4'
50
50
 
51
51
  Since the gem follows [Semantic Versioning](http://semver.org),
52
52
  indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
@@ -208,6 +208,289 @@ over HTTP scheme:
208
208
  <link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.css" media="screen" rel="stylesheet" type="text/css" />
209
209
  ```
210
210
 
211
+ GlyphiconHelper
212
+ ===============
213
+
214
+ To display [glyphicons](http://getbootstrap.com/components/#glyphicons),
215
+ you can use the
216
+ [glyphicon](http://rubydoc.info/github/Fullscreen/bh/master/Bh/GlyphiconHelper) helper.
217
+ Here are some examples.
218
+
219
+ Display the "zoom in" icon
220
+ --------------------------
221
+
222
+ ```erb
223
+ <%= glyphicon :ok, title: 'Approved' %>
224
+ ```
225
+
226
+ will generate the HTML to render an "ok" icon with the "Approved" title:
227
+
228
+ ```html
229
+ <span class="glyphicon glyphicon-ok" title="Approved"></span>
230
+ ```
231
+
232
+ ![glyphicon](https://cloud.githubusercontent.com/assets/7408595/3941608/64219c82-2537-11e4-8e86-27d4a62b1c06.png)
233
+
234
+
235
+ PanelHelper
236
+ ===========
237
+
238
+ To include [Boostrap panels](http://getbootstrap.com/components/#panels)
239
+ in your Rails views, you can use the
240
+ [panel](http://rubydoc.info/github/Fullscreen/bh/master/Bh/PanelHelper) helper.
241
+ Here are some examples.
242
+
243
+ Basic panel
244
+ -----------
245
+
246
+ ```erb
247
+ <%= panel body: 'You accepted the Terms of service.' %>
248
+ ```
249
+
250
+ will generate the HTML to render a basic panel:
251
+
252
+ ```html
253
+ <div class="panel panel-default">
254
+ <div class="panel-body">You accepted the Terms of service.</div>
255
+ </div>
256
+ ```
257
+ ![panel-basic](https://cloud.githubusercontent.com/assets/7408595/3941817/da52bd6c-2543-11e4-87ae-eb1c7ed9df68.png)
258
+
259
+ Panel with heading
260
+ ------------------
261
+
262
+ ```erb
263
+ <%= panel body: 'You accepted the Terms of service.', heading: 'Congratulations' %>
264
+ ```
265
+
266
+ will generate the HTML to render a panel with a heading:
267
+
268
+ ```html
269
+ <div class="panel panel-default">
270
+ <div class="panel-heading">Congratulations</div>
271
+ <div class="panel-body">You accepted the Terms of service.</div>
272
+ </div>
273
+ ```
274
+
275
+ ![panel-heading](https://cloud.githubusercontent.com/assets/7408595/3941820/da58db3e-2543-11e4-811f-f7da4ffce77d.png)
276
+
277
+ Panel with title
278
+ ------------------
279
+
280
+ ```erb
281
+ <%= panel body: 'You accepted the Terms of service.', title: 'Congratulations' %>
282
+ ```
283
+
284
+ will generate the HTML to render a panel with a title:
285
+
286
+ ```html
287
+ <div class="panel panel-default">
288
+ <div class="panel-heading">
289
+ <h3 class="panel-title">Congratulations</h3>
290
+ </div>
291
+ <div class="panel-body">You accepted the Terms of service.</div>
292
+ </div>
293
+ ```
294
+
295
+ ![panel-title](https://cloud.githubusercontent.com/assets/7408595/3941816/da52b894-2543-11e4-99b8-4b6ffd47c167.png)
296
+
297
+ Contextual panel
298
+ -----------------
299
+
300
+ ```erb
301
+ <%= panel body: 'You accepted the Terms of service.', title: 'Congratulations', context: :success %>
302
+ ```
303
+
304
+ will generate the HTML to render a "success" panel (green background):
305
+
306
+ ```html
307
+ <div class="panel panel-success">
308
+ <div class="panel-heading">
309
+ <h3 class="panel-title">Congratulations</h3>
310
+ </div>
311
+ <div class="panel-body">You accepted the Terms of service.</div>
312
+ </div>
313
+ ```
314
+
315
+ Available contexts are `:default` (default), `:primary`, `:success`, `:info`,
316
+ `:warning` and `:danger`.
317
+
318
+ ![panel-context](https://cloud.githubusercontent.com/assets/7408595/3941818/da562ba0-2543-11e4-87ce-54e143538219.png)
319
+
320
+ Complex panels
321
+ --------------
322
+
323
+ ```erb
324
+ <%= panel do %>
325
+ <div class='panel-body'>You accepted the Terms of service. <%= glyphicon :ok %></div>
326
+ <div class='panel-footer'><h4>Thanks</h4></div>
327
+ <% end %>
328
+ ```
329
+
330
+ will generate the HTML to render a panel with HTML body and footer:
331
+
332
+ ```html
333
+ <div class="panel panel-default">
334
+ <div class="panel-body">
335
+ You accepted the Terms of service.
336
+ <span class="glyphicon glyphicon-ok"></span>
337
+ </div>
338
+ <div class="panel-footer"><h4>Thanks</h4></div>
339
+ </div>
340
+ ```
341
+
342
+ ![panel-complex](https://cloud.githubusercontent.com/assets/7408595/3941819/da569586-2543-11e4-8640-3f0a72077aca.png)
343
+
344
+
345
+ PanelRowHelper
346
+ ==============
347
+
348
+ To include a row of [Boostrap panels](http://getbootstrap.com/components/#panels)
349
+ in your Rails views, you can use the
350
+ [panel_row](http://rubydoc.info/github/Fullscreen/bh/master/Bh/PanelRowHelper) helper.
351
+ Here are some examples.
352
+
353
+ Basic row of panels
354
+ -------------------
355
+
356
+ ```erb
357
+ <%= panel_row column_class: 'col-sm-4' do %>
358
+ <%= panel body: 'Panel #1' %>
359
+ <%= panel body: 'Panel #2' %>
360
+ <%= panel body: 'Panel #3' %>
361
+ <% end %>
362
+ ```
363
+
364
+ will generate the HTML to render a row of three basic panels:
365
+
366
+ ```html
367
+ <div class="row">
368
+ <div class="col-sm-4">
369
+ <div class="panel panel-default"><div class="panel-body">Panel #1</div></div>
370
+ </div>
371
+ <div class="col-sm-4">
372
+ <div class="panel panel-default"><div class="panel-body">Panel #2</div></div>
373
+ </div>
374
+ <div class="col-sm-4">
375
+ <div class="panel panel-default"><div class="panel-body">Panel #3</div></div>
376
+ </div>
377
+ </div>
378
+ ```
379
+
380
+ ![panel-row-basic](https://cloud.githubusercontent.com/assets/7408595/3942060/48967f30-2552-11e4-8b9c-a647d1569d5c.png)
381
+
382
+ Complex row of panels
383
+ ---------------------
384
+
385
+ ```erb
386
+ <%= panel_row column_class: 'col-sm-4' do %>
387
+ <%= panel title: 'User', context: :info do %>
388
+ <div class='panel-body'><%= glyphicon :user %> John Smith</div>
389
+ <% end %>
390
+ <%= panel title: 'Phone' do %>
391
+ <div class='panel-body'><%= glyphicon :earphone %> 323-555-5555</div>
392
+ <% end %>
393
+ <%= panel title: 'City' do %>
394
+ <div class='panel-body'><%= glyphicon :record %> Los Angeles, CA</div>
395
+ <% end %>
396
+ <% end %>
397
+ ```
398
+
399
+ will generate the HTML to render a row of three panels with title and HTML body:
400
+
401
+ ```html
402
+ <div class="row">
403
+ <div class="col-sm-4"><div class="panel panel-info">
404
+ <div class="panel-heading"><h3 class="panel-title">User</h3></div>
405
+ <div class="panel-body"><span class="glyphicon glyphicon-user"></span> John Smith</div>
406
+ </div></div>
407
+ <div class="col-sm-4"><div class="panel panel-default">
408
+ <div class="panel-heading"><h3 class="panel-title">Phone</h3></div>
409
+ <div class="panel-body"><span class="glyphicon glyphicon-earphone"></span> 323-555-5555</div>
410
+ </div></div>
411
+ <div class="col-sm-4"><div class="panel panel-default">
412
+ <div class="panel-heading"><h3 class="panel-title">City</h3></div>
413
+ <div class="panel-body"><span class="glyphicon glyphicon-record"></span> Los Angeles, CA</div>
414
+ </div></div>
415
+ </div>
416
+ ```
417
+
418
+ ![panel-row-complex](https://cloud.githubusercontent.com/assets/7408595/3942061/489d1bc4-2552-11e4-9b00-d724b7c2c908.png)
419
+
420
+ ModalHelper
421
+ ===========
422
+
423
+ To include [Boostrap modals](http://getbootstrap.com/javascript/#modals)
424
+ in your Rails views, you can use the
425
+ [modal](http://rubydoc.info/github/Fullscreen/bh/master/Bh/ModalHelper) helper.
426
+ Here are some examples.
427
+
428
+ Basic modal
429
+ -----------
430
+
431
+ ```erb
432
+ <%= modal title: 'Terms of service', body: 'Do what you want!' %>
433
+ ```
434
+
435
+ will generate the HTML to render a button that toggles a model when clicked:
436
+
437
+ ```html
438
+ <button class="btn btn-default" data-toggle="modal" data-target="#modal-8684506463">
439
+ Terms of service
440
+ </button>
441
+ <div class="modal fade" id="modal-8684506463" tabindex="-1" role="dialog" aria-labelledby="label-modal-8684506463" aria-hidden="true" style="display: none;">
442
+ <div class="modal-dialog">
443
+ <div class="modal-content">
444
+ <div class="modal-header">
445
+ <button type="button" class="close" data-dismiss="modal">
446
+ <span aria-hidden="true">×</span><span class="sr-only">Close</span>
447
+ </button>
448
+ <h4 class="modal-title" id="label-modal-8684506463">Terms of service</h4>
449
+ </div>
450
+ <div class="modal-body">Do what you want!</div>
451
+ </div>
452
+ </div>
453
+ </div>
454
+ ```
455
+
456
+ ![modal-basic](https://cloud.githubusercontent.com/assets/7408595/3943921/b471d3c2-25d8-11e4-9b40-d8bab38ba572.png)
457
+
458
+ Complex modal
459
+ -------------
460
+
461
+ ```erb
462
+ <%= modal title: 'Terms of service', size: :small, button: {caption: 'Continue', size: :large, context: :info} do %>
463
+ Please accept the Terms of service.
464
+ <div class="modal-footer"><button type="button" class="btn btn-primary">Accept</button></div>
465
+ <% end %>
466
+ ```
467
+
468
+ will generate the HTML to render a large, "info" button (blue background) with
469
+ the caption "Continue" that toggles a small modal with a title and HTML content:
470
+
471
+ ```html
472
+ <button class="btn btn-info btn-lg" data-toggle="modal" data-target="#modal-8022670096">
473
+ Continue
474
+ </button>
475
+ <div class="modal fade in" id="modal-8022670096" tabindex="-1" role="dialog" aria-labelledby="label-modal-8022670096" aria-hidden="false" style="display: block;">
476
+ <div class="modal-dialog modal-sm">
477
+ <div class="modal-content">
478
+ <div class="modal-header">
479
+ <button type="button" class="close" data-dismiss="modal">
480
+ <span aria-hidden="true">×</span><span class="sr-only">Close</span>
481
+ </button>
482
+ <h4 class="modal-title" id="label-modal-8022670096">Terms of service</h4>
483
+ </div>
484
+ Please accept the Terms of service.
485
+ <div class="modal-footer"><button type="button" class="btn btn-primary">Accept</button></div>
486
+ </div>
487
+ </div>
488
+ </div>
489
+ ```
490
+
491
+ ![modal-complex](https://cloud.githubusercontent.com/assets/7408595/3943922/b47620a8-25d8-11e4-9e0c-803d8a104bff.png)
492
+
493
+
211
494
  How to release new versions
212
495
  ===========================
213
496
 
@@ -5,6 +5,7 @@ module Bh
5
5
  include ActionView::Helpers::TagHelper # for content_tag
6
6
  include ActionView::Context # for capture
7
7
  include ActionView::Helpers::OutputSafetyHelper # for safe_join
8
+
8
9
  # Returns an HTML block tag that follows the Bootstrap documentation
9
10
  # on how to display *alert boxes*.
10
11
  # Alert boxes provide contextual feedback messages for typical user
@@ -18,19 +19,19 @@ module Bh
18
19
  # alert 'User updated successfully', dismissible: true
19
20
  # @example An alert with an HTML message passed as a block.
20
21
  # alert_box dismissible: true do
21
- # <strong>Hooray!</strong> User updated successfully
22
+ # content_tag :strong, "User updated successfully"
22
23
  # end
23
24
  #
24
25
  # @return [String] an HTML block tag for an alert.
25
26
  # @param [String] message_or_options_with_block the message to display in
26
27
  # the alert.
27
28
  # @param [Hash] options the options for the alert box.
28
- # @option options [Boolean] :dismissible whether to display an '×' to the
29
- # right of the alert than can be clicked to dismiss the alert.
30
- # @option options [Symbol] :context the contextual class to apply to the
31
- # alert depending on its importance. Can be :success, :info, :warning,
32
- # or :danger. Defaults to :info.
33
- # @option options [Symbol] :priority if the alert box is used to show a
29
+ # @option options [Boolean] :dismissible (false) whether to display an '×'
30
+ # to the right of the alert than can be clicked to dismiss the alert.
31
+ # @option options [#to_s] :context (:info) the contextual alternative to
32
+ # apply to the alert depending on its importance. Can be :success, :info,
33
+ # :warning or :danger.
34
+ # @option options [#to_s] :priority if the alert box is used to show a
34
35
  # Rails flash message, the priority of the message. Can be :alert
35
36
  # or :notice.
36
37
  def alert_box(message_or_options_with_block = nil, options = nil, &block)
@@ -0,0 +1,24 @@
1
+ require 'action_view'
2
+
3
+ module Bh
4
+ # Provides methods to include Glyphicons.
5
+ # @see http://getbootstrap.com/components/#glyphicons
6
+ module GlyphiconHelper
7
+ include ActionView::Helpers::TagHelper # for content_tag
8
+
9
+ # Returns an HTML block tag that follows the Bootstrap documentation
10
+ # on how to display *glyphicons*.
11
+ # @return [String] an HTML block tag for a glyphicon.
12
+ # @param [#to_s] the name of the icon to display, with either dashes or
13
+ # underscores to separate multiple words.
14
+ # @example Display the "zoom in" glyphicon
15
+ # glyphicon :zoom_in
16
+ # @example Display the "zoom out" glyphicon
17
+ # glyphicon 'zoom-out'
18
+ def glyphicon(name = nil, options = {})
19
+ glyphicon_class = "glyphicon-#{name.to_s.gsub '_', '-'}" if name
20
+ klass = ['glyphicon', glyphicon_class].compact.join ' '
21
+ content_tag :span, nil, options.merge(class: klass)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,93 @@
1
+ require 'action_view'
2
+
3
+ module Bh
4
+ # Provides methods to include modals.
5
+ # @see http://getbootstrap.com/javascript/#modals
6
+ module ModalHelper
7
+ include ActionView::Helpers, ActionView::Context
8
+
9
+
10
+ # Returns an HTML block tag that follows the Bootstrap documentation
11
+ # on how to display *modals*.
12
+ #
13
+ # The content of the modal can either be passed as the first parameter (in
14
+ # which case, the options are the second parameter), or as a block (in
15
+ # which case, the options are the first paramter).
16
+ # @example An modal with plain-text content passed as the first parameter.
17
+ # modal 'Your profile was updated!', context: :info, title: 'Profile'
18
+ # @example A panel with HTML content passed as a block.
19
+ # modal context: :info, title: 'Profile' do
20
+ # content_tag :div, "Your profile was updated!", class: 'modal-footer'
21
+ # end
22
+ #
23
+ # @return [String] an HTML block tag for a panel.
24
+ # @param [String] content_or_options_with_block the content to display in
25
+ # the panel.
26
+ # @param [Hash] options the display options for the panel.
27
+ # @option options [#to_s] :title ('Modal') the title to display inside the modal.
28
+ # @option options [#to_s] :body if present, the panel will include the
29
+ # provided text wrapped in a 'modal-body' block, for proper padding
30
+ # @option options [#to_s] :size the size of the modal.
31
+ # @option options [Hash] :button the options for the "toggle" button.
32
+ # * :caption (#to_s) ('Modal') the caption for the "toggle" button.
33
+ # * :context (#to_s) (:default) the context for the "toggle" button,
34
+ # which determines the button color
35
+ # * :size (#to_s) the size of the "toggle" button.
36
+ # @see http://getbootstrap.com/javascript/#modals
37
+ def modal(content_or_options_with_block = nil, options = nil, &block)
38
+ if block_given?
39
+ modal_string content_or_options_with_block, &block
40
+ elsif content_or_options_with_block.is_a?(Hash) && options.nil?
41
+ modal_string content_or_options_with_block, &Proc.new { nil }
42
+ else
43
+ modal_string options, &Proc.new { content_or_options_with_block }
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def modal_string(options = nil, &block)
50
+ options ||= {}
51
+ options[:id] ||= "modal-#{rand 10**10}"
52
+ options[:title] ||= 'Modal'
53
+ options[:body] = modal_body options[:body]
54
+ options[:dialog_class] ||= dialog_class options[:size]
55
+ options[:button] ||= {}
56
+ options[:button][:caption] ||= options[:title]
57
+ options[:button][:class] ||= button_class options[:button]
58
+ render layout: 'bh/modal', locals: options, &block
59
+ end
60
+
61
+ def button_class(options = {})
62
+ context = case options[:context].to_s
63
+ when 'primary' then :primary
64
+ when 'success' then :success
65
+ when 'info' then :info
66
+ when 'warning' then :warning
67
+ when 'danger' then :danger
68
+ when 'link' then :link
69
+ else 'default'
70
+ end
71
+
72
+ size = case options[:size].to_s
73
+ when 'lg', 'large' then 'btn-lg'
74
+ when 'sm', 'small' then 'btn-sm'
75
+ when 'xs', 'extra_small' then 'btn-xs'
76
+ end
77
+
78
+ ['btn', "btn-#{context}", size].compact.join ' '
79
+ end
80
+
81
+ def dialog_class(size = nil)
82
+ size_class = case size.to_s
83
+ when 'lg', 'large' then 'modal-lg'
84
+ when 'sm', 'small' then 'modal-sm'
85
+ end
86
+ ['modal-dialog', size_class].compact.join ' '
87
+ end
88
+
89
+ def modal_body(body = nil)
90
+ content_tag :div, body, class: 'modal-body' if body
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,86 @@
1
+ require 'action_view'
2
+
3
+ module Bh
4
+ # Provides methods to include panels.
5
+ # @see http://getbootstrap.com/components/#panels
6
+ module PanelHelper
7
+ include ActionView::Helpers::TagHelper # for content_tag
8
+ include ActionView::Context # for capture
9
+ include ActionView::Helpers::OutputSafetyHelper # for safe_join
10
+
11
+ # Returns an HTML block tag that follows the Bootstrap documentation
12
+ # on how to display *panels*.
13
+ #
14
+ # The content of the panel can either be passed as the first parameter (in
15
+ # which case, the options are the second parameter), or as a block (in
16
+ # which case, the options are the first paramter).
17
+ # @example An panel with plain-text content passed as the first parameter.
18
+ # panel 'Your profile was updated!', context: :info, title: 'Profile'
19
+ # @example A panel with HTML content passed as a block.
20
+ # panel context: :info, title: 'Profile'
21
+ # content_tag :strong, "Your profile was updated!"
22
+ # end
23
+ #
24
+ # @return [String] an HTML block tag for a panel.
25
+ # @param [String] content_or_options_with_block the content to display in
26
+ # the panel.
27
+ # @param [Hash] options the display options for the panel.
28
+ # @option options [#to_s] :context (:default) the contextual alternative to
29
+ # apply to the panel depending on its importance. Can be :default,
30
+ # :primary, :success, :info, :warning or :danger.
31
+ # @option options [#to_s] :body if present, the panel will include the
32
+ # provided text wrapped in a 'panel-body' block, for proper padding
33
+ # @see http://getbootstrap.com/components/#panels-basic
34
+ # @option options [#to_s] :heading if present, the panel will include a
35
+ # heading with the provided text.
36
+ # @option options [#to_s] :title if present, the panel will include a
37
+ # heading with the provided text wrapped in a 'panel-title' block, for
38
+ # proper title styling and link coloring.
39
+ # @see http://getbootstrap.com/components/#panels-heading
40
+ def panel(content_or_options_with_block = nil, options = nil, &block)
41
+ if block_given?
42
+ panel_string capture(&block), content_or_options_with_block || {}
43
+ elsif content_or_options_with_block.is_a?(Hash) && options.nil?
44
+ panel_string nil, content_or_options_with_block
45
+ else
46
+ panel_string content_or_options_with_block, options || {}
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def panel_string(content = nil, options = {})
53
+ content = prepend_optional_body_to content, options
54
+ content = prepend_optional_heading_to content, options
55
+ content_tag :div, content, class: panel_class(options[:context])
56
+ end
57
+
58
+ def panel_class(context = nil)
59
+ context = case context.to_s
60
+ when 'primary' then :primary
61
+ when 'success' then :success
62
+ when 'info' then :info
63
+ when 'warning' then :warning
64
+ when 'danger' then :danger
65
+ else 'default'
66
+ end
67
+ "panel panel-#{context}"
68
+ end
69
+
70
+ def prepend_optional_body_to(content, options = {})
71
+ body = options[:body]
72
+ body = content_tag :div, body, class: 'panel-body' if body
73
+ safe_join [body, content].compact
74
+ end
75
+
76
+ def prepend_optional_heading_to(content, options = {})
77
+ title = if options[:title]
78
+ content_tag :h3, options[:title], class: 'panel-title'
79
+ elsif options[:heading]
80
+ options[:heading]
81
+ end
82
+ heading = content_tag :div, title, class: 'panel-heading' if title
83
+ safe_join [heading, content].compact
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,50 @@
1
+ require 'action_view'
2
+ require 'bh/helpers/panel_helper'
3
+
4
+ module Bh
5
+ # Provides methods to include multiple panels in a row.
6
+ # @see http://getbootstrap.com/css/#grid
7
+ # @see http://getbootstrap.com/components/#panels
8
+ module PanelRowHelper
9
+ include ActionView::Helpers::TagHelper # for content_tag
10
+ include ActionView::Context # for capture
11
+ include ActionView::Helpers::OutputSafetyHelper # for safe_join
12
+ include Bh::PanelHelper # for panel
13
+
14
+ # Returns an HTML block tag that follows the Bootstrap documentation
15
+ # on how to display a *row*, passing column options to each panel in
16
+ # the row.
17
+ #
18
+ # @return [String] an HTML block tag for a row of panels.
19
+ # @param [Hash] options the display options for the row of panels.
20
+ # @option options [#to_s] :column_class the class to apply to the column
21
+ # <div> that wraps every panel in the row. Useful to specify a grid size
22
+ # for the column such as 'col-sm-4' to indicate how many columns of the
23
+ # row each panel should occupy.
24
+ # @see http://getbootstrap.com/css/#grid
25
+ # @see http://getbootstrap.com/components/#panels
26
+ def panel_row(options = {}, &block)
27
+ content_tag :div, class: 'row' do
28
+ capture_panel_row(options, &block) if block_given?
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ # Overrides PanelHelper +panel+ to be able to add a column <div> around
35
+ # each panel in a row, to make it fit inside the panel row.
36
+ def panel(*args, &block)
37
+ panel = super *args, &block
38
+ if @panel_column_class
39
+ content_tag :div, panel, class: @panel_column_class
40
+ else
41
+ panel
42
+ end
43
+ end
44
+
45
+ def capture_panel_row(options = {}, &block)
46
+ @panel_column_class = options[:column_class]
47
+ capture(&block).tap{ @panel_column_class = nil }
48
+ end
49
+ end
50
+ end
@@ -3,6 +3,7 @@ require 'action_view'
3
3
  module Bh
4
4
  module UrlHelper
5
5
  include ActionView::Helpers::UrlHelper # for link_to
6
+
6
7
  # Overrides ActionView +link_to+ to be able to add the 'alert_link' class
7
8
  # to the link in case the link is inside of an alert.
8
9
  # @see http://getbootstrap.com/components/#alerts-links
@@ -1,5 +1,9 @@
1
1
  require 'bh/helpers/alert_helper'
2
2
  require 'bh/helpers/cdn_helper'
3
+ require 'bh/helpers/glyphicon_helper'
4
+ require 'bh/helpers/modal_helper'
5
+ require 'bh/helpers/panel_helper'
6
+ require 'bh/helpers/panel_row_helper'
3
7
  require 'bh/helpers/url_helper'
4
8
 
5
9
  module Bh
@@ -7,7 +11,16 @@ module Bh
7
11
  initializer 'bh.add_helpers' do
8
12
  ActionView::Base.send :include, AlertHelper
9
13
  ActionView::Base.send :include, CdnHelper
14
+ ActionView::Base.send :include, GlyphiconHelper
15
+ ActionView::Base.send :include, ModalHelper
16
+ ActionView::Base.send :include, PanelHelper
17
+ ActionView::Base.send :include, PanelRowHelper
10
18
  ActionView::Base.send :include, UrlHelper
11
19
  end
20
+
21
+ initializer 'bh.add_views' do |app|
22
+ views_path = File.dirname(__FILE__) + "/views"
23
+ ActionController::Base.prepend_view_path views_path
24
+ end
12
25
  end
13
26
  end
@@ -1,3 +1,3 @@
1
1
  module Bh
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -0,0 +1,17 @@
1
+ <button class="<%= button[:class] %>" data-toggle="modal" data-target="#<%= id %>">
2
+ <%= button[:caption] %>
3
+ </button>
4
+ <div class="modal fade" id="<%= id %>" tabindex="-1" role="dialog" aria-labelledby="label-<%= id %>" aria-hidden="true">
5
+ <div class="<%= dialog_class %>">
6
+ <div class="modal-content">
7
+ <div class="modal-header">
8
+ <button type="button" class="close" data-dismiss="modal">
9
+ <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
10
+ </button>
11
+ <h4 class="modal-title" id="label-<%= id %>"><%= title %></h4>
12
+ </div>
13
+ <%= body %>
14
+ <%= yield %>
15
+ </div>
16
+ </div>
17
+ </div>
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'bh/helpers/glyphicon_helper'
3
+ include Bh::GlyphiconHelper
4
+
5
+ describe 'glyphicon' do
6
+ specify 'given an icon name with underscores, returns the icon' do
7
+ expect(glyphicon :zoom_in).to eq '<span class="glyphicon glyphicon-zoom-in"></span>'
8
+ end
9
+
10
+ specify 'given an icon name with dashes, returns the icon' do
11
+ expect(glyphicon 'zoom-out').to eq '<span class="glyphicon glyphicon-zoom-out"></span>'
12
+ end
13
+
14
+ specify 'given no icon name, returns an empty icon' do
15
+ expect(glyphicon).to eq '<span class="glyphicon"></span>'
16
+ end
17
+
18
+ specify 'given extra options, passes the options to the <span>' do
19
+ expect(glyphicon :ok, title: 'Approved').to eq '<span class="glyphicon glyphicon-ok" title="Approved"></span>'
20
+ end
21
+ end
@@ -0,0 +1,133 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'action_dispatch'
5
+ require 'bh/helpers/modal_helper'
6
+ include Bh::ModalHelper
7
+
8
+ describe 'modal' do
9
+ let(:views_folder) { File.expand_path('../../../lib/bh/views', __FILE__) }
10
+ let(:lookup_context) { ActionView::LookupContext.new views_folder }
11
+ let(:view_renderer) { ActionView::Renderer.new lookup_context }
12
+ describe 'accepts as parameters:' do
13
+ let(:behave) { include 'content' }
14
+
15
+ specify 'a string (content)' do
16
+ expect(modal 'content').to behave
17
+ end
18
+
19
+ specify 'a hash (options)' do
20
+ expect(modal body: 'content').to behave
21
+ end
22
+
23
+ specify 'a block (content)' do
24
+ expect(modal { 'content' }).to behave
25
+ end
26
+
27
+ specify 'a string (content) + a hash (options)' do
28
+ expect(modal 'content', context: :danger).to behave
29
+ end
30
+
31
+ specify 'a hash (options) + a block (content)' do
32
+ expect(modal(context: :danger) { 'content' }).to behave
33
+ end
34
+ end
35
+
36
+ describe 'with the :button option' do
37
+ let(:html) { modal 'content', button: button_options }
38
+
39
+ describe 'with the :context option' do
40
+ let(:button_options) { {context: context} }
41
+
42
+ describe 'set to :primary, shows a "primary" toggle button' do
43
+ let(:context) { :primary }
44
+ it { expect(html).to include 'btn-primary' }
45
+ end
46
+
47
+ describe 'set to :success, shows a "success" toggle button' do
48
+ let(:context) { :success }
49
+ it { expect(html).to include 'btn-success' }
50
+ end
51
+
52
+ describe 'set to :info, shows a "info" toggle button' do
53
+ let(:context) { :info }
54
+ it { expect(html).to include 'btn-info' }
55
+ end
56
+
57
+ describe 'set to :warning, shows a "warning" toggle button' do
58
+ let(:context) { :warning }
59
+ it { expect(html).to include 'btn-warning' }
60
+ end
61
+
62
+ describe 'set to :danger, shows a "danger" toggle button' do
63
+ let(:context) { :danger }
64
+ it { expect(html).to include 'btn-danger' }
65
+ end
66
+
67
+ describe 'set to :link, shows a "link" toggle button' do
68
+ let(:context) { :link }
69
+ it { expect(html).to include 'btn-link' }
70
+ end
71
+
72
+ describe 'set to any other value, shows a "default" toggle button' do
73
+ let(:context) { :unknown }
74
+ it { expect(html).to include 'btn-default' }
75
+ end
76
+ end
77
+
78
+ describe 'without the :context option, shows a "default" toggle button' do
79
+ let(:button_options) { {} }
80
+ it { expect(html).to include 'btn-default' }
81
+ end
82
+
83
+ describe 'with the :size option' do
84
+ let(:button_options) { {size: size} }
85
+
86
+ describe 'set to :large, shows a large toggle button' do
87
+ let(:size) { :large }
88
+ it { expect(html).to include 'btn-lg' }
89
+ end
90
+
91
+ describe 'set to :small, shows a small toggle button' do
92
+ let(:size) { :small }
93
+ it { expect(html).to include 'btn-sm' }
94
+ end
95
+
96
+ describe 'set to :extra_small, shows an extra-small toggle button' do
97
+ let(:size) { :extra_small }
98
+ it { expect(html).to include 'btn-xs' }
99
+ end
100
+ end
101
+
102
+ describe 'with the :caption option, shows the caption on the button' do
103
+ let(:button_options) { {caption: 'Call to action'} }
104
+ it { expect(html).to include 'Call to action' }
105
+ end
106
+ end
107
+
108
+ describe 'with the :size option' do
109
+ let(:html) { modal 'content', size: size }
110
+
111
+ describe 'set to :large, shows a large modal' do
112
+ let(:size) { :large }
113
+ it { expect(html).to include 'modal-dialog modal-lg' }
114
+ end
115
+
116
+ describe 'set to :small, shows a small modal' do
117
+ let(:size) { :small }
118
+ it { expect(html).to include 'modal-dialog modal-sm' }
119
+ end
120
+ end
121
+
122
+ describe 'with the :body option' do
123
+ specify 'includes its value in the modal body' do
124
+ expect(modal body: 'Your profile was updated', title: 'Profile').to include '<div class="modal-body">Your profile was updated</div>'
125
+ end
126
+ end
127
+
128
+ describe 'with the :title option' do
129
+ specify 'includes its value as a title in the modal heading' do
130
+ expect(modal 'content', title: 'Profile').to include 'Profile</h4>'
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,89 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'bh/helpers/panel_helper'
5
+ include Bh::PanelHelper
6
+
7
+ describe 'panel' do
8
+ describe 'accepts as parameters:' do
9
+ let(:behave) { include 'content' }
10
+
11
+ specify 'a string (content)' do
12
+ expect(panel 'content').to behave
13
+ end
14
+
15
+ specify 'a hash (options)' do
16
+ expect(panel body: 'content').to behave
17
+ end
18
+
19
+ specify 'a block (content)' do
20
+ expect(panel { 'content' }).to behave
21
+ end
22
+
23
+ specify 'a string (content) + a hash (options)' do
24
+ expect(panel 'content', context: :danger).to behave
25
+ end
26
+
27
+ specify 'a hash (options) + a block (content)' do
28
+ expect(panel(context: :danger) { 'content' }).to behave
29
+ end
30
+ end
31
+
32
+ describe 'with the :context option' do
33
+ specify 'set to :default, shows a "default" panel' do
34
+ expect(panel 'content', context: :default).to include 'panel-default'
35
+ end
36
+
37
+ specify 'set to :primary, shows a "primary" panel' do
38
+ expect(panel 'content', context: :primary).to include 'panel-primary'
39
+ end
40
+
41
+ specify 'set to :success, shows a "success" panel' do
42
+ expect(panel 'content', context: :success).to include 'panel-success'
43
+ end
44
+
45
+ specify 'set to :info, shows a "info" panel' do
46
+ expect(panel 'content', context: :info).to include 'panel-info'
47
+ end
48
+
49
+ specify 'set to :warning, shows a "warning" panel' do
50
+ expect(panel 'content', context: :warning).to include 'panel-warning'
51
+ end
52
+
53
+ specify 'set to :danger, shows a "danger" panel' do
54
+ expect(panel 'content', context: :danger).to include 'panel-danger'
55
+ end
56
+
57
+ specify 'set to any other value, shows an "default" panel' do
58
+ expect(panel 'content', context: :unknown).to include 'panel-default'
59
+ end
60
+
61
+ specify 'not set, shows an "default" panel' do
62
+ expect(panel 'content').to include 'panel-default'
63
+ end
64
+ end
65
+
66
+ describe 'with the :body option' do
67
+ specify 'includes its value in the panel body' do
68
+ expect(panel 'content', body: 'Your profile was updated', title: 'Profile').to include '<div class="panel-body">Your profile was updated</div>'
69
+ end
70
+ end
71
+
72
+ describe 'with the :heading option' do
73
+ specify 'includes its value in the panel heading' do
74
+ expect(panel 'content', heading: 'Profile').to include '<div class="panel-heading">Profile</div>'
75
+ end
76
+ end
77
+
78
+ describe 'with the :title option' do
79
+ specify 'includes its value as a title in the panel heading' do
80
+ expect(panel 'content', title: 'Profile').to include '<div class="panel-heading"><h3 class="panel-title">Profile</h3></div>'
81
+ end
82
+ end
83
+
84
+ describe 'without the :heading or the :title option' do
85
+ specify 'does not include the panel heading' do
86
+ expect(panel 'content').not_to include 'panel-heading'
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'bh/helpers/panel_row_helper'
5
+ include Bh::PanelRowHelper
6
+
7
+ describe 'panel_row' do
8
+ describe 'without a block' do
9
+ specify 'shows an empty row' do
10
+ expect(panel_row).to include '<div class="row">'
11
+ end
12
+ end
13
+
14
+ describe 'with a block' do
15
+ describe 'that does not include panels' do
16
+ specify 'shows the content of the block in a row' do
17
+ expect(panel_row { 'content' }).to include 'content'
18
+ end
19
+ end
20
+
21
+ describe 'that includes panels and the :column_class option' do
22
+ specify 'wraps each panel in a column <div> with the given class' do
23
+ expect(panel_row(column_class: 'col-sm-12') { panel body: 'content' }).to include '<div class="col-sm-12">'
24
+ end
25
+ end
26
+ end
27
+ 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: 0.0.3
4
+ version: 0.0.4
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-08-16 00:00:00.000000000 Z
11
+ date: 2014-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -130,11 +130,20 @@ files:
130
130
  - lib/bh.rb
131
131
  - lib/bh/helpers/alert_helper.rb
132
132
  - lib/bh/helpers/cdn_helper.rb
133
+ - lib/bh/helpers/glyphicon_helper.rb
134
+ - lib/bh/helpers/modal_helper.rb
135
+ - lib/bh/helpers/panel_helper.rb
136
+ - lib/bh/helpers/panel_row_helper.rb
133
137
  - lib/bh/helpers/url_helper.rb
134
138
  - lib/bh/railtie.rb
135
139
  - lib/bh/version.rb
140
+ - lib/bh/views/bh/_modal.html.erb
136
141
  - spec/helpers/alert_helper_spec.rb
137
142
  - spec/helpers/cdn_helper_spec.rb
143
+ - spec/helpers/glyphicon_helper_spec.rb
144
+ - spec/helpers/modal_helper_spec.rb
145
+ - spec/helpers/panel_helper_spec.rb
146
+ - spec/helpers/panel_row_helper_spec.rb
138
147
  - spec/helpers/url_helper_spec.rb
139
148
  - spec/spec_helper.rb
140
149
  homepage: http://github.com/Fullscreen/bh
@@ -165,6 +174,10 @@ summary: Bh provides a set of powerful helpers that streamlines the use of Boots
165
174
  test_files:
166
175
  - spec/helpers/alert_helper_spec.rb
167
176
  - spec/helpers/cdn_helper_spec.rb
177
+ - spec/helpers/glyphicon_helper_spec.rb
178
+ - spec/helpers/modal_helper_spec.rb
179
+ - spec/helpers/panel_helper_spec.rb
180
+ - spec/helpers/panel_row_helper_spec.rb
168
181
  - spec/helpers/url_helper_spec.rb
169
182
  - spec/spec_helper.rb
170
183
  has_rdoc: