bh 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -1
  3. data/CHANGELOG.md +19 -0
  4. data/README.md +51 -18
  5. data/bh.gemspec +13 -9
  6. data/examples/middleman/.gitignore +18 -0
  7. data/examples/middleman/Gemfile +6 -0
  8. data/examples/middleman/config.rb +1 -0
  9. data/examples/middleman/source/index.html.erb +158 -0
  10. data/examples/padrino/Gemfile +9 -0
  11. data/examples/padrino/app/app.rb +16 -0
  12. data/examples/padrino/app/views/index.html.erb +155 -0
  13. data/examples/padrino/config.ru +5 -0
  14. data/examples/padrino/config/apps.rb +5 -0
  15. data/examples/padrino/config/boot.rb +8 -0
  16. data/examples/rails/.gitignore +12 -0
  17. data/examples/rails/Gemfile +5 -0
  18. data/examples/rails/app/controllers/application_controller.rb +6 -0
  19. data/examples/rails/app/controllers/users_controller.rb +2 -0
  20. data/examples/rails/app/models/user.rb +15 -0
  21. data/examples/rails/app/views/application/index.html.erb +160 -0
  22. data/examples/rails/bin/rails +4 -0
  23. data/examples/rails/config.ru +4 -0
  24. data/examples/rails/config/application.rb +12 -0
  25. data/examples/rails/config/boot.rb +3 -0
  26. data/examples/rails/config/environment.rb +5 -0
  27. data/examples/rails/config/environments/development.rb +7 -0
  28. data/examples/rails/config/routes.rb +4 -0
  29. data/examples/rails/config/secrets.yml +22 -0
  30. data/examples/rails/log/.keep +0 -0
  31. data/gemfiles/Gemfile.rails-3.x +2 -0
  32. data/gemfiles/Gemfile.rails-4.x +2 -0
  33. data/lib/bh.rb +15 -4
  34. data/lib/bh/classes/alert_box.rb +35 -0
  35. data/lib/bh/classes/base.rb +125 -0
  36. data/lib/bh/classes/button.rb +58 -0
  37. data/lib/bh/classes/button_to.rb +33 -0
  38. data/lib/bh/classes/cdn.rb +35 -0
  39. data/lib/bh/classes/dropdown.rb +56 -0
  40. data/lib/bh/classes/icon.rb +34 -0
  41. data/lib/bh/classes/link_to.rb +22 -0
  42. data/lib/bh/classes/modal.rb +68 -0
  43. data/lib/bh/classes/nav.rb +37 -0
  44. data/lib/bh/classes/navbar.rb +78 -0
  45. data/lib/bh/classes/panel.rb +72 -0
  46. data/lib/bh/classes/panel_row.rb +13 -0
  47. data/lib/bh/classes/progress_bar.rb +89 -0
  48. data/lib/bh/classes/stack.rb +19 -0
  49. data/lib/bh/classes/vertical.rb +27 -0
  50. data/lib/bh/core_ext/middleman.rb +24 -0
  51. data/lib/bh/core_ext/padrino.rb +25 -0
  52. data/lib/bh/core_ext/rails/base_helper.rb +21 -0
  53. data/lib/bh/{helpers → core_ext/rails}/form/base_helper.rb +3 -1
  54. data/lib/bh/{helpers → core_ext/rails}/form/check_box_helper.rb +1 -1
  55. data/lib/bh/{helpers → core_ext/rails}/form/field_helper.rb +1 -1
  56. data/lib/bh/{helpers → core_ext/rails}/form/fields_for_helper.rb +1 -1
  57. data/lib/bh/{helpers → core_ext/rails}/form/fieldset_helper.rb +1 -1
  58. data/lib/bh/{helpers → core_ext/rails}/form/file_field_helper.rb +1 -1
  59. data/lib/bh/{helpers → core_ext/rails}/form/legend_helper.rb +1 -1
  60. data/lib/bh/{helpers → core_ext/rails}/form/radio_button_helper.rb +1 -1
  61. data/lib/bh/{helpers → core_ext/rails}/form/select_helper.rb +1 -1
  62. data/lib/bh/{helpers → core_ext/rails}/form/static_control_helper.rb +1 -1
  63. data/lib/bh/{helpers → core_ext/rails}/form/submit_helper.rb +1 -1
  64. data/lib/bh/{form_builders → core_ext/rails}/form_builder.rb +11 -10
  65. data/lib/bh/core_ext/rails/form_for_helper.rb +32 -0
  66. data/lib/bh/core_ext/railtie.rb +27 -0
  67. data/lib/bh/helpers/alert_box_helper.rb +40 -0
  68. data/lib/bh/helpers/button_helper.rb +35 -58
  69. data/lib/bh/helpers/button_to_helper.rb +48 -10
  70. data/lib/bh/helpers/cdn_helper.rb +11 -35
  71. data/lib/bh/helpers/dropdown_helper.rb +29 -62
  72. data/lib/bh/helpers/glyphicon_helper.rb +7 -13
  73. data/lib/bh/helpers/horizontal_helper.rb +35 -0
  74. data/lib/bh/helpers/icon_helper.rb +15 -29
  75. data/lib/bh/helpers/link_to_helper.rb +52 -41
  76. data/lib/bh/helpers/modal_helper.rb +49 -79
  77. data/lib/bh/helpers/nav_helper.rb +25 -40
  78. data/lib/bh/helpers/navbar_helper.rb +36 -170
  79. data/lib/bh/helpers/panel_helper.rb +45 -72
  80. data/lib/bh/helpers/panel_row_helper.rb +20 -38
  81. data/lib/bh/helpers/progress_bar_helper.rb +48 -59
  82. data/lib/bh/helpers/vertical_helper.rb +33 -0
  83. data/lib/bh/version.rb +1 -1
  84. data/lib/bh/views/bh/_alert_dismiss_button.html +4 -0
  85. data/lib/bh/views/bh/_dropdown.html.erb +5 -5
  86. data/lib/bh/views/bh/_dropdown_split.html.erb +5 -5
  87. data/lib/bh/views/bh/_modal.html.erb +5 -8
  88. data/lib/bh/views/bh/_navbar.html.erb +5 -0
  89. data/spec/padrino/button_to_helper.rb +35 -0
  90. data/spec/padrino_spec.rb +28 -0
  91. data/spec/rails/button_to_helper.rb +31 -0
  92. data/spec/{helpers → rails}/form/check_box_helper_spec.rb +3 -3
  93. data/spec/{helpers → rails}/form/field_helper_spec.rb +3 -3
  94. data/spec/{helpers → rails}/form/fields_for_helper_spec.rb +3 -3
  95. data/spec/{helpers → rails}/form/fieldset_helper_spec.rb +3 -3
  96. data/spec/{helpers → rails}/form/file_field_helper_spec.rb +3 -3
  97. data/spec/{helpers → rails}/form/legend_helper_spec.rb +3 -3
  98. data/spec/{helpers → rails}/form/radio_button_helper_spec.rb +3 -3
  99. data/spec/{helpers → rails}/form/select_helper_spec.rb +3 -3
  100. data/spec/{helpers → rails}/form/static_control_helper_spec.rb +3 -3
  101. data/spec/{helpers → rails}/form/submit_helper_spec.rb +3 -3
  102. data/spec/{helpers → rails}/form_for_helper_spec.rb +3 -3
  103. data/spec/rails_helper.rb +25 -0
  104. data/spec/rails_spec.rb +28 -0
  105. data/spec/shared/alert_box_helper.rb +62 -0
  106. data/spec/shared/button_helper.rb +52 -0
  107. data/spec/shared/button_to_helper.rb +42 -0
  108. data/spec/shared/cdn_helper.rb +36 -0
  109. data/spec/shared/dropdown_helper.rb +112 -0
  110. data/spec/shared/glyphicon_helper.rb +21 -0
  111. data/spec/shared/horizontal_helper.rb +37 -0
  112. data/spec/shared/icon_helper.rb +31 -0
  113. data/spec/shared/link_to_helper.rb +62 -0
  114. data/spec/shared/modal_helper.rb +104 -0
  115. data/spec/shared/nav_helper.rb +49 -0
  116. data/spec/shared/navbar_helper.rb +63 -0
  117. data/spec/shared/panel_helper.rb +76 -0
  118. data/spec/shared/panel_row_helper.rb +21 -0
  119. data/spec/shared/progress_bar_helper.rb +103 -0
  120. data/spec/shared/vertical_helper.rb +43 -0
  121. data/spec/spec_helper.rb +6 -29
  122. data/spec/support/matchers.rb +38 -0
  123. data/spec/support/padrino.rb +33 -0
  124. data/spec/support/rails.rb +27 -0
  125. metadata +183 -94
  126. data/config.rb +0 -6
  127. data/lib/bh/helpers/alert_helper.rb +0 -77
  128. data/lib/bh/helpers/base_helper.rb +0 -39
  129. data/lib/bh/helpers/form_for_helper.rb +0 -30
  130. data/lib/bh/middleman.rb +0 -39
  131. data/lib/bh/railtie.rb +0 -42
  132. data/spec/dummy/index.html.erb +0 -60
  133. data/spec/dummy/layouts/default.erb +0 -17
  134. data/spec/helpers/alert_helper_spec.rb +0 -84
  135. data/spec/helpers/button_helper_spec.rb +0 -100
  136. data/spec/helpers/button_to_helper_spec.rb +0 -25
  137. data/spec/helpers/cdn_helper_spec.rb +0 -100
  138. data/spec/helpers/dropdown_helper_spec.rb +0 -146
  139. data/spec/helpers/glyphicon_helper_spec.rb +0 -21
  140. data/spec/helpers/icon_helper_spec.rb +0 -45
  141. data/spec/helpers/link_to_helper_spec.rb +0 -124
  142. data/spec/helpers/modal_helper_spec.rb +0 -133
  143. data/spec/helpers/nav_helper_spec.rb +0 -53
  144. data/spec/helpers/navbar_helper_spec.rb +0 -194
  145. data/spec/helpers/panel_helper_spec.rb +0 -95
  146. data/spec/helpers/panel_row_helper_spec.rb +0 -27
  147. data/spec/helpers/progress_bar_helper_spec.rb +0 -114
@@ -1,80 +1,53 @@
1
- require 'bh/helpers/base_helper'
1
+ require 'bh/classes/panel'
2
+ require 'bh/classes/panel_row'
3
+ require 'bh/classes/stack'
2
4
 
3
5
  module Bh
4
- # Provides methods to include panels.
5
- # @see http://getbootstrap.com/components/#panels
6
- module PanelHelper
7
- include BaseHelper
6
+ module Helpers
7
+ # Displays a Bootstrap-styled panel.
8
+ # @see http://getbootstrap.com/components/#panels
9
+ # @return [String] the HTML to display a Bootstrap-styled panel.
10
+ # @overload panel(body, options = {})
11
+ # @param [#to_s] body the content to display as the panel body.
12
+ # @param [Hash] options the options for the panel. Any option not
13
+ # listed below is passed as an HTML attribute to the panel’s `<div>`.
14
+ # @option options [#to_s] :title the text to display as the panel title.
15
+ # @option options [#to_s] :heading the text to display as the panel
16
+ # heading.
17
+ # @option options [#to_s] :body the text to display as the panel body.
18
+ # Using this option is equivalent to passing the body as an argument.
19
+ # @option options [#to_s] :context (#to_s) (:default) the contextual
20
+ # alternative to apply to the panel heading and border. Can be
21
+ # `:danger`, `:info`, `:primary`, `:success` or `:warning`.
22
+ # @option options [#to_s] :tag (#to_s) (:div) the HTML tag to wrap the
23
+ # panel into.
24
+ # @example Display an informative panel with plain-text content.
25
+ # panel 'You accepted the Terms of service.', context: :success
26
+ # @overload panel(options = {}, &block)
27
+ # @param [Hash] options the options for the panel (see above).
28
+ # @yieldreturn [#to_s] the content to display in the panel.
29
+ # @example Display a panel with HTML content.
30
+ # panel title: 'Thanks' do
31
+ # content_tag :div, class: 'panel-body' do
32
+ # content_tag :em, 'ou accepted the Terms of service.'
33
+ # end
34
+ # end
35
+ def panel(*args, &block)
36
+ panel = Bh::Panel.new self, *args, &block
37
+ panel.extract! :body, :context, :title, :heading, :tag
8
38
 
9
- # Returns an HTML block tag that follows the Bootstrap documentation
10
- # on how to display *panels*.
11
- #
12
- # The content of the panel can either be passed as the first parameter (in
13
- # which case, the options are the second parameter), or as a block (in
14
- # which case, the options are the first paramter).
15
- # @example An panel with plain-text content passed as the first parameter.
16
- # panel 'Your profile was updated!', context: :info, title: 'Profile'
17
- # @example A panel with HTML content passed as a block.
18
- # panel context: :info, title: 'Profile'
19
- # content_tag :strong, "Your profile was updated!"
20
- # end
21
- #
22
- # @return [String] an HTML block tag for a panel.
23
- # @param [String] content_or_options_with_block the content to display in
24
- # the panel.
25
- # @param [Hash] options the display options for the panel.
26
- # @option options [#to_s] :context (:default) the contextual alternative to
27
- # apply to the panel depending on its importance. Can be :default,
28
- # :primary, :success, :info, :warning or :danger.
29
- # @option options [#to_s] :body if present, the panel will include the
30
- # provided text wrapped in a 'panel-body' block, for proper padding
31
- # @see http://getbootstrap.com/components/#panels-basic
32
- # @option options [#to_s] :heading if present, the panel will include a
33
- # heading with the provided text.
34
- # @option options [#to_s] :title if present, the panel will include a
35
- # heading with the provided text wrapped in a 'panel-title' block, for
36
- # proper title styling and link coloring.
37
- # @option options [#to_s] :tag (:div) the HTML tag to wrap the panel in.
38
- # @see http://getbootstrap.com/components/#panels-heading
39
- def panel(content_or_options_with_block = nil, options = nil, &block)
40
- if block_given?
41
- panel_string capture(&block), content_or_options_with_block || {}
42
- elsif content_or_options_with_block.is_a?(Hash) && options.nil?
43
- panel_string nil, content_or_options_with_block
44
- else
45
- panel_string content_or_options_with_block, options || {}
46
- end
47
- end
48
-
49
- private
50
-
51
- def panel_string(content = nil, options = {})
52
- content = prepend_optional_body_to content, options
53
- content = prepend_optional_heading_to content, options
54
- tag = options.fetch :tag, :div
55
- content_tag tag, content, class: panel_class(options[:context])
56
- end
39
+ panel.append_class! :panel
40
+ panel.append_class! panel.context_class
41
+ panel.merge_html! panel.body
42
+ panel.prepend_html! panel.heading
57
43
 
58
- def panel_class(context = nil)
59
- valid_contexts = %w(primary success info warning danger)
60
- context = context_for context, valid: valid_contexts
61
- "panel panel-#{context}"
62
- end
63
-
64
- def prepend_optional_body_to(content, options = {})
65
- body = options[:body]
66
- body = content_tag :div, body, class: 'panel-body' if body
67
- safe_join [body, content].compact
68
- end
69
-
70
- def prepend_optional_heading_to(content, options = {})
71
- title = if options[:title]
72
- content_tag :h3, options[:title], class: 'panel-title'
73
- elsif options[:heading]
74
- options[:heading]
44
+ if panel_row = Bh::Stack.find(Bh::PanelRow)
45
+ container = Bh::Base.new(self) { panel.content_tag panel.tag }
46
+ container.append_class! panel_row.column_class
47
+ container.render_tag :div
48
+ else
49
+ panel.render_tag panel.tag
75
50
  end
76
- heading = content_tag :div, title, class: 'panel-heading' if title
77
- safe_join [heading, content].compact
78
51
  end
79
52
  end
80
53
  end
@@ -1,46 +1,28 @@
1
- require 'bh/helpers/panel_helper'
1
+ require 'bh/classes/panel_row'
2
2
 
3
3
  module Bh
4
- # Provides methods to include multiple panels in a row.
5
- # @see http://getbootstrap.com/css/#grid
6
- # @see http://getbootstrap.com/components/#panels
7
- module PanelRowHelper
8
- include PanelHelper # for panel
9
-
10
- # Returns an HTML block tag that follows the Bootstrap documentation
11
- # on how to display a *row*, passing column options to each panel in
12
- # the row.
13
- #
14
- # @return [String] an HTML block tag for a row of panels.
15
- # @param [Hash] options the display options for the row of panels.
16
- # @option options [#to_s] :column_class the class to apply to the column
17
- # <div> that wraps every panel in the row. Useful to specify a grid size
18
- # for the column such as 'col-sm-4' to indicate how many columns of the
19
- # row each panel should occupy.
20
- # @see http://getbootstrap.com/css/#grid
4
+ module Helpers
5
+ # Wraps a set of Bootstrap-styled panels in a row.
21
6
  # @see http://getbootstrap.com/components/#panels
7
+ # @see http://getbootstrap.com/css/#grid
8
+ # @return [String] the HTML to display a row of Bootstrap-styled panels.
9
+ # @param [Hash] options the options for the row. Any option not
10
+ # listed below is passed as an HTML attribute to the row’s `<div>`.
11
+ # @option options [#to_s] :column_class the class to wrap each panel with.
12
+ # Useful to specify a grid size for the column such as 'col-sm-4' to
13
+ # indicate how many columns of the row each panel should occupy.
14
+ # @yieldreturn [#to_s] the panels to display in a row.
15
+ # @example Display a row of two panels with the same width.
16
+ # panel_row column_class: 'col-sm-6' do
17
+ # panel 'Panel #1', context: :success
18
+ # panel 'Panel #2', context: :info
19
+ # end
22
20
  def panel_row(options = {}, &block)
23
- content_tag :div, class: 'row' do
24
- capture_panel_row(options, &block) if block_given?
25
- end
26
- end
27
-
28
- private
29
-
30
- # Overrides PanelHelper +panel+ to be able to add a column <div> around
31
- # each panel in a row, to make it fit inside the panel row.
32
- def panel(*args, &block)
33
- panel = super *args, &block
34
- if @panel_column_class
35
- content_tag :div, panel, class: @panel_column_class
36
- else
37
- panel
38
- end
39
- end
21
+ panel_row = Bh::PanelRow.new self, options, &block
22
+ panel_row.extract! :column_class
40
23
 
41
- def capture_panel_row(options = {}, &block)
42
- @panel_column_class = options[:column_class]
43
- capture(&block).tap{ @panel_column_class = nil }
24
+ panel_row.append_class! :row
25
+ panel_row.render_tag :div
44
26
  end
45
27
  end
46
28
  end
@@ -1,66 +1,55 @@
1
- require 'bh/helpers/base_helper'
1
+ require 'bh/classes/progress_bar'
2
2
 
3
3
  module Bh
4
- # Provides methods to include progress bars.
5
- # @see http://getbootstrap.com/components/#progress
6
- module ProgressBarHelper
7
- include BaseHelper
8
-
9
- # Returns an HTML block tag that follows the Bootstrap documentation
10
- # on how to display *progress bars*.
11
- # @param [Hash, Array<Hash>] options the display options for the progress
12
- # bar(s). When options is an Array, a group of stacked progress bars
13
- # is displayed, with the options specified in each item of the array.
14
- # @option options [Boolean, #to_s] :label (false) the label to display
15
- # on top of the progress bar. If set to false, the label is hidden. If
16
- # set to true, the label is generated from the percentage value. Any
17
- # other provided value is used directly as the label.
18
- # @option options [Boolean] :striped (false) whether to display a striped
19
- # version of the progress bar (rather than solid color).
20
- # @option options [Boolean] :animated (false) whether to display an
21
- # animated version of the progress bar (rather than solid color).
22
- # @option options [#to_s] :context (:default) the contextual alternative to
23
- # apply to the progress bar depending on its importance. Can be
24
- # `:success`, `:info`, `:warning` or `:danger`.
25
- def progress_bar(options = {})
26
- content_tag :div, class: :progress do
27
- safe_join Array.wrap(options).map{|bar| progress_bar_string bar}, "\n"
28
- end
29
- end
30
-
31
- private
32
-
33
- def progress_bar_string(options = {})
34
- percentage = options.fetch :percentage, 0
35
-
36
- attributes = {}.tap do |attrs|
37
- attrs[:class] = progress_bar_class(options)
38
- attrs[:role] = 'progressbar'
39
- attrs[:style] = "width: #{percentage}%"
40
- attrs['aria-valuenow'] = percentage
41
- attrs['aria-valuemin'] = 0
42
- attrs['aria-valuemax'] = 100
4
+ module Helpers
5
+ # Displays one or more Bootstrap-styled progress bars.
6
+ # @see http://getbootstrap.com/components/#progress
7
+ # @return [String] the HTML to display Bootstrap-styled progress bars.
8
+ # @overload progress_bar(bar_options = {}, container_options = {})
9
+ # @param [Hash] bar_options the options to display a single progress bar.
10
+ # Any option not listed below is passed as an HTML attribute to the
11
+ # bar’s `<div>`.
12
+ # @option bar_options [Boolean, #to_s] :label (false) the label to display
13
+ # on top of the progress bar. If set to false, the label is hidden. If
14
+ # set to true, the label is generated from the percentage value. Any
15
+ # other provided value is used directly as the label.
16
+ # @option bar_options [Boolean] :striped (false) whether to display a
17
+ # striped version of the progress bar (rather than solid color).
18
+ # @option bar_options [Boolean] :animated (false) whether to display an
19
+ # animated version of the progress bar (rather than solid color).
20
+ # @option bar_options [#to_s] :context (:default) the contextual
21
+ # alternative to apply to the progress bar. Can be `:success`, `:info`,
22
+ # `:warning` or `:danger`.
23
+ # @param [Hash] container_options the options to pass as HTML attributes
24
+ # to the container’s `<div>`.
25
+ # @example Display a 30% warning progress bar.
26
+ # progress_bar percentage: 30, context: :warning
27
+ # @overload progress_bar(stacked_bars_options = [], container_options = {})
28
+ # @param [Hash] stacked_bars_options an array of bar_options (see above).
29
+ # When an array is provided, a group of stacked progress bars is
30
+ # displayed, each one matching the corresponding bar options.
31
+ # @param [Hash] container_options the options to pass as HTML attributes
32
+ # to the container’s `<div>`.
33
+ # @example Display two stacked progress bars.
34
+ # progress_bar [{percentage: 30, context: :warning}, {percentage: 20}]
35
+ def progress_bar(args = nil, container_options = {})
36
+ progress_bars = Array.wrap(args).map do |options|
37
+ progress_bar = Bh::ProgressBar.new self, nil, options
38
+ progress_bar.extract! :percentage, :context, :striped, :animated, :label
39
+
40
+ progress_bar.merge! progress_bar.aria_values
41
+ progress_bar.append_class! :'progress-bar'
42
+ progress_bar.append_class! progress_bar.context_class
43
+ progress_bar.append_class! progress_bar.striped_class
44
+ progress_bar.append_class! progress_bar.animated_class
45
+ progress_bar.merge! progress_bar.values
46
+ progress_bar.prepend_html! progress_bar.label
47
+ progress_bar
43
48
  end
44
49
 
45
- content_tag :div, progress_bar_label(percentage, options), attributes
46
- end
47
-
48
- def progress_bar_label(percentage, options = {})
49
- text = "#{percentage}%#{" (#{options[:context]})" if options[:context]}"
50
- case options.fetch(:label, false)
51
- when true then text
52
- when false then content_tag(:span, text, class: 'sr-only')
53
- else options[:label]
54
- end
55
- end
56
-
57
- def progress_bar_class(options = {})
58
- valid_contexts = %w(success info warning danger)
59
- context = context_for options[:context], valid: valid_contexts
60
- context = context.in?(valid_contexts) ? "progress-bar-#{context}" : nil
61
- striped = 'progress-bar-striped' if options[:striped]
62
- animated = 'progress-bar-striped active' if options[:animated]
63
- ['progress-bar', context, striped, animated].compact.join ' '
50
+ container = Bh::Base.new self, progress_bars, container_options
51
+ container.append_class! :progress
52
+ container.render_tag :div
64
53
  end
65
54
  end
66
55
  end
@@ -0,0 +1,33 @@
1
+ require 'bh/classes/navbar'
2
+ require 'bh/classes/vertical'
3
+
4
+ module Bh
5
+ module Helpers
6
+ # Displays the non-collapsable portion of a Bootstrap-styled navbar.
7
+ # @see http://getbootstrap.com/components/#navbar
8
+ # @return [String] the HTML to display the non-collapsable portion of a
9
+ # Bootstrap-styled navbar.
10
+ # @overload vertical(content, options = {})
11
+ # @param [#to_s] content the non-collapsable content to display in the
12
+ # navbar.
13
+ # @param [Hash] options the options to pass to the wrapping `<div>`.
14
+ # @overload vertical(options = {}, &block)
15
+ # @param [Hash] options the options to pass to the wrapping `<div>`.
16
+ # @yieldreturn [#to_s] the non-collapsable content to display in the
17
+ # navbar.
18
+ # @example Display a navbar a non-collapsable links.
19
+ # navbar do
20
+ # vertical do
21
+ # link_to 'Home', '/'
22
+ # end
23
+ # end
24
+ def vertical(*args, &block)
25
+ if navbar = Bh::Stack.find(Bh::Navbar)
26
+ vertical = Bh::Vertical.new self, *args, &block
27
+ vertical.append_class! :'navbar-header'
28
+ vertical.prepend_html! vertical.toggle_button(navbar.id)
29
+ vertical.render_tag :div
30
+ end
31
+ end
32
+ end
33
+ end
data/lib/bh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bh
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -0,0 +1,4 @@
1
+ <button type="button" class="close" data-dismiss="alert">
2
+ <span aria-hidden="true">&times;</span>
3
+ <span class="sr-only">Close</span>
4
+ </button>
@@ -1,9 +1,9 @@
1
- <div class="<%= div_class %>">
2
- <button class="dropdown-toggle <%= button_class %>" type="button" id="label-<%= id %>" data-toggle="dropdown">
3
- <%= caption %>
1
+ <div class="<%= div[:class] %>">
2
+ <button class="dropdown-toggle <%= button[:class] %>" type="button" id="<%= button[:id] %>" data-toggle="dropdown">
3
+ <%= button[:caption] %>
4
4
  <span class="caret"></span>
5
5
  </button>
6
- <ul class="<%= list_class %>" role="menu" aria-labelledby="label-<%= id %>">
7
- <%= yield %>
6
+ <ul class="<%= ul[:class] %>" role="menu" aria-labelledby="<%= button[:id] %>">
7
+ <%= content %>
8
8
  </ul>
9
9
  </div>
@@ -1,10 +1,10 @@
1
- <div class="<%= div_class %>">
2
- <button type="button" class="<%= button_class %>"><%= caption %></button>
3
- <button class="dropdown-toggle <%= button_class %>" type="button" id="label-<%= id %>" data-toggle="dropdown">
1
+ <div class="<%= div[:class] %>">
2
+ <button type="button" class="<%= button[:class] %>"><%= button[:caption] %></button>
3
+ <button class="dropdown-toggle <%= button[:class] %>" type="button" id="<%= button[:id] %>" data-toggle="dropdown">
4
4
  <span class="caret"></span>
5
5
  <span class="sr-only">Toggle Dropdown</span>
6
6
  </button>
7
- <ul class="<%= list_class %>" role="menu" aria-labelledby="label-<%= id %>">
8
- <%= yield %>
7
+ <ul class="<%= ul[:class] %>" role="menu" aria-labelledby="<%= button[:id] %>">
8
+ <%= content %>
9
9
  </ul>
10
10
  </div>
@@ -1,17 +1,14 @@
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 %>">
1
+ <button class="<%= button[:class] %>" data-toggle="modal" data-target="#<%= div[:id] %>"><%= button[:caption] %></button>
2
+ <div class="modal fade" id="<%= div[:id] %>" tabindex="-1" role="dialog" aria-labelledby="label-<%= div[:id] %>" aria-hidden="true">
3
+ <div class="<%= div[:class] %>">
6
4
  <div class="modal-content">
7
5
  <div class="modal-header">
8
6
  <button type="button" class="close" data-dismiss="modal">
9
7
  <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
10
8
  </button>
11
- <h4 class="modal-title" id="label-<%= id %>"><%= title %></h4>
9
+ <h4 class="modal-title" id="label-<%= div[:id] %>"><%= div[:title] %></h4>
12
10
  </div>
13
- <%= body %>
14
- <%= yield %>
11
+ <%= content %>
15
12
  </div>
16
13
  </div>
17
14
  </div>
@@ -0,0 +1,5 @@
1
+ <nav class="<%= navigation[:class] %>" role="navigation">
2
+ <div class="<%= div[:class] %>">
3
+ <%= content %>
4
+ </div>
5
+ </nav>
@@ -0,0 +1,35 @@
1
+ shared_examples_for 'the button_to helper (Padrino)' do
2
+ all_tests_pass_with 'no button_to options (Padrino)'
3
+ all_tests_pass_with 'only extra button_to options (Padrino)'
4
+ all_tests_pass_with 'extra button_to options (Padrino)'
5
+ all_tests_pass_for 'the button_to helper'
6
+ end
7
+
8
+ #--
9
+
10
+ shared_examples_for 'no button_to options (Padrino)' do
11
+ specify 'uses the original button_to helper' do
12
+ html = '<form action="/" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" /><input type="submit" value="content" /></form>'
13
+ expect(:button_to).to generate html
14
+
15
+ # @note: Only Padrino >= 0.13.0 renders the content of the block as a
16
+ # <button> so the exact content is only partially tested here.
17
+ expect(bh.button_to('/'){ 'content' }).to include 'content'
18
+ end
19
+ end
20
+
21
+ shared_examples_for 'only extra button_to options (Padrino)' do
22
+ specify 'uses the original button_to helper' do
23
+ options = {class: 'big', id: 'my-form', submit_options: {class: 'important', data: {value: 1}, id: 'my-button_to'}}
24
+ html = '<form action="/" accept-charset="UTF-8" class="big" id="my-form" method="post"><input type="hidden" name="authenticity_token" /><input type="submit" value="content" class="important" data-value="1" id="my-button_to" /></form>'
25
+ expect(button_to: options).to generate html
26
+ end
27
+ end
28
+
29
+ shared_examples_for 'extra button_to options (Padrino)' do
30
+ specify 'passes the options to the form and the submit_options to the button' do
31
+ options = {context: :default, class: 'big', id: 'my-form', submit_options: {class: 'important', data: {value: 1}, id: 'my-button_to'}}
32
+ html = '<form action="/" accept-charset="UTF-8" class="big" id="my-form" method="post"><input type="hidden" name="authenticity_token" /><input type="submit" value="content" class="important btn btn-default" data-value="1" id="my-button_to" /></form>'
33
+ expect(button_to: options).to generate html
34
+ end
35
+ end