bh 1.3.5 → 6.0.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.
Files changed (94) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +8 -138
  4. data/app/assets/stylesheets/bh.css +29 -0
  5. data/app/javascript/controllers/bh/theme_controller.js +17 -0
  6. data/app/views/bh/_grid.html.erb +6 -0
  7. data/app/views/bh/_table.html.erb +46 -0
  8. data/bh.gemspec +5 -31
  9. data/gemfiles/Gemfile.rails-3.x +0 -1
  10. data/lib/bh/bootstrap_helpers.rb +131 -0
  11. data/lib/bh/engine.rb +13 -0
  12. data/lib/bh/version.rb +3 -1
  13. data/lib/bh.rb +6 -14
  14. data/spec/spec_helper.rb +1 -1
  15. metadata +14 -298
  16. data/examples/middleman/.gitignore +0 -18
  17. data/examples/middleman/Gemfile +0 -6
  18. data/examples/middleman/config.rb +0 -1
  19. data/examples/middleman/source/index.html.erb +0 -158
  20. data/examples/padrino/Gemfile +0 -9
  21. data/examples/padrino/app/app.rb +0 -16
  22. data/examples/padrino/app/views/index.html.erb +0 -155
  23. data/examples/padrino/config/apps.rb +0 -5
  24. data/examples/padrino/config/boot.rb +0 -8
  25. data/examples/padrino/config.ru +0 -5
  26. data/examples/rails/.gitignore +0 -12
  27. data/examples/rails/Gemfile +0 -5
  28. data/examples/rails/app/controllers/application_controller.rb +0 -6
  29. data/examples/rails/app/controllers/users_controller.rb +0 -2
  30. data/examples/rails/app/models/user.rb +0 -15
  31. data/examples/rails/app/views/application/index.html.erb +0 -160
  32. data/examples/rails/bin/rails +0 -4
  33. data/examples/rails/config/application.rb +0 -12
  34. data/examples/rails/config/boot.rb +0 -3
  35. data/examples/rails/config/environment.rb +0 -5
  36. data/examples/rails/config/environments/development.rb +0 -7
  37. data/examples/rails/config/routes.rb +0 -4
  38. data/examples/rails/config/secrets.yml +0 -22
  39. data/examples/rails/config.ru +0 -4
  40. data/examples/rails/log/.keep +0 -0
  41. data/lib/bh/classes/alert_box.rb +0 -35
  42. data/lib/bh/classes/base.rb +0 -125
  43. data/lib/bh/classes/button.rb +0 -58
  44. data/lib/bh/classes/button_to.rb +0 -33
  45. data/lib/bh/classes/cdn.rb +0 -35
  46. data/lib/bh/classes/dropdown.rb +0 -56
  47. data/lib/bh/classes/icon.rb +0 -34
  48. data/lib/bh/classes/link_to.rb +0 -26
  49. data/lib/bh/classes/modal.rb +0 -68
  50. data/lib/bh/classes/nav.rb +0 -37
  51. data/lib/bh/classes/navbar.rb +0 -78
  52. data/lib/bh/classes/panel.rb +0 -72
  53. data/lib/bh/classes/panel_row.rb +0 -13
  54. data/lib/bh/classes/progress_bar.rb +0 -89
  55. data/lib/bh/classes/stack.rb +0 -19
  56. data/lib/bh/classes/vertical.rb +0 -27
  57. data/lib/bh/core_ext/middleman.rb +0 -24
  58. data/lib/bh/core_ext/padrino.rb +0 -25
  59. data/lib/bh/core_ext/rails/base_helper.rb +0 -21
  60. data/lib/bh/core_ext/rails/form/base_helper.rb +0 -150
  61. data/lib/bh/core_ext/rails/form/check_box_helper.rb +0 -35
  62. data/lib/bh/core_ext/rails/form/field_helper.rb +0 -15
  63. data/lib/bh/core_ext/rails/form/fields_for_helper.rb +0 -23
  64. data/lib/bh/core_ext/rails/form/fieldset_helper.rb +0 -16
  65. data/lib/bh/core_ext/rails/form/file_field_helper.rb +0 -15
  66. data/lib/bh/core_ext/rails/form/legend_helper.rb +0 -17
  67. data/lib/bh/core_ext/rails/form/radio_button_helper.rb +0 -19
  68. data/lib/bh/core_ext/rails/form/select_helper.rb +0 -16
  69. data/lib/bh/core_ext/rails/form/static_control_helper.rb +0 -43
  70. data/lib/bh/core_ext/rails/form/submit_helper.rb +0 -23
  71. data/lib/bh/core_ext/rails/form_builder.rb +0 -46
  72. data/lib/bh/core_ext/rails/form_for_helper.rb +0 -41
  73. data/lib/bh/core_ext/railtie.rb +0 -27
  74. data/lib/bh/helpers/alert_box_helper.rb +0 -40
  75. data/lib/bh/helpers/button_helper.rb +0 -40
  76. data/lib/bh/helpers/button_to_helper.rb +0 -65
  77. data/lib/bh/helpers/cdn_helper.rb +0 -46
  78. data/lib/bh/helpers/dropdown_helper.rb +0 -49
  79. data/lib/bh/helpers/glyphicon_helper.rb +0 -18
  80. data/lib/bh/helpers/horizontal_helper.rb +0 -35
  81. data/lib/bh/helpers/icon_helper.rb +0 -27
  82. data/lib/bh/helpers/link_to_helper.rb +0 -59
  83. data/lib/bh/helpers/modal_helper.rb +0 -55
  84. data/lib/bh/helpers/nav_helper.rb +0 -36
  85. data/lib/bh/helpers/navbar_helper.rb +0 -48
  86. data/lib/bh/helpers/panel_helper.rb +0 -53
  87. data/lib/bh/helpers/panel_row_helper.rb +0 -28
  88. data/lib/bh/helpers/progress_bar_helper.rb +0 -55
  89. data/lib/bh/helpers/vertical_helper.rb +0 -33
  90. data/lib/bh/views/bh/_alert_dismiss_button.html +0 -4
  91. data/lib/bh/views/bh/_dropdown.html.erb +0 -9
  92. data/lib/bh/views/bh/_dropdown_split.html.erb +0 -10
  93. data/lib/bh/views/bh/_modal.html.erb +0 -14
  94. data/lib/bh/views/bh/_navbar.html.erb +0 -5
@@ -1,25 +0,0 @@
1
- module Bh
2
- module Extensions
3
- # Makes Bootstrap helpers available in Padrino applications.
4
- #
5
- # To use Bh in a Padrino app you need 2 steps:
6
- #
7
- # - include bh in the Gemfile
8
- # - add `register Bh` in the `app.rb` file
9
- #
10
- # The following method adds `Bh` as one of the modules that can be registered
11
- # in a Padrino app, but you still need to register it manually in order to
12
- # make helpers available.
13
- module Padrino
14
- # Register Bh as a Padrino app.
15
- def registered(app)
16
- app.include Bh::Helpers
17
- end
18
- end
19
-
20
- Bh.framework = :padrino
21
- end
22
-
23
- # Allows to register Bh in a Padrino app simply with `register Bh`.
24
- extend Extensions::Padrino
25
- end
@@ -1,21 +0,0 @@
1
- require 'action_view'
2
-
3
- module Bh
4
- module Rails
5
- # @api private
6
- module BaseHelper
7
- include ActionView::Helpers::TagHelper # for content_tag
8
- include ActionView::Context # for capture
9
- include ActionView::Helpers::OutputSafetyHelper # for safe_join
10
- include ActionView::Helpers::RenderingHelper # for render
11
- include ActionView::Helpers::UrlHelper # for link_to
12
-
13
- private
14
-
15
- def append_class!(hash, new_class, attribute = :class)
16
- existing_class = hash[attribute]
17
- hash[attribute] = [existing_class, new_class].compact.join ' '
18
- end
19
- end
20
- end
21
- end
@@ -1,150 +0,0 @@
1
- require 'bh/core_ext/rails/base_helper'
2
- require 'bh/helpers/glyphicon_helper'
3
-
4
- module Bh
5
- module Form
6
- module BaseHelper
7
- include Bh::Rails::BaseHelper
8
- include Bh::Helpers
9
-
10
- private
11
-
12
- def base_field(method, field_type, options = {}, &block)
13
- errors = (object.errors[method] if object) || {}
14
- label = label_for method, errors, field_type, options
15
- field = field_container(options) do
16
- field_tags errors, field_type, options, &block
17
- end
18
- label_and_field = safe_join [label, field].compact
19
- label_and_field_container label_and_field, field_type, errors
20
- end
21
-
22
-
23
- def field_container(options = {}, &block)
24
- offset = options.delete :offset
25
- if horizontal_form?
26
- klass = [('col-sm-offset-3' if offset), 'col-sm-9']
27
- content_tag :div, class: klass.compact.join(' '), &block
28
- else
29
- yield
30
- end
31
- end
32
-
33
- def field_tags(errors, field_type, options = {}, &block)
34
- prefix, suffix = options.delete(:prefix), options.delete(:suffix)
35
- help_text = options.delete(:help)
36
- field = @template.capture(&block)
37
- tags = [field_in_group(field, prefix, suffix)]
38
- if show_error_icon?(field_type, errors, suffix) && !basic_form?
39
- tags << error_icon_tag
40
- end
41
- if errors.any? && show_error_help?
42
- tags << help_tag(errors.to_sentence)
43
- elsif help_text
44
- tags << help_tag(help_text)
45
- end
46
- safe_join tags
47
- end
48
-
49
- def field_in_group(field, prefix, suffix)
50
- input_group_container(prefix || suffix) do
51
- safe_join [input_addon(prefix), field, input_addon(suffix)].compact
52
- end
53
- end
54
-
55
- def input_addon(addon)
56
- content_tag :span, addon, class: 'input-group-addon' if addon
57
- end
58
-
59
- def input_group_container(has_addons, &block)
60
- if has_addons
61
- content_tag :div, class: 'input-group', &block
62
- else
63
- yield
64
- end
65
- end
66
-
67
- def label_and_field_container(label_and_field, field_type, errors = {})
68
- klass = ['form-group']
69
- klass << 'has-error' if errors.any?
70
- klass << 'has-feedback' if show_error_icon?(field_type, errors)
71
- content_tag :div, label_and_field, class: klass.join(' ')
72
- end
73
-
74
-
75
- def show_error_icon?(field_type, errors, suffix = nil)
76
- no_icon = %w(checkbox number_field radio_button select legend)
77
- hide = no_icon.include?(field_type.to_s)
78
- errors.any? && @options.fetch(:errors, {}).fetch(:icons, true) && !hide && suffix.nil?
79
- end
80
-
81
- def error_icon_tag
82
- glyphicon :remove, class: 'form-control-feedback'
83
- end
84
-
85
- def help_tag(help_text)
86
- klass = ['help-block', 'text-left']
87
- klass << 'sr-only' if inline_form?
88
- content_tag :span, help_text, class: klass.join(' ')
89
- end
90
-
91
- # Rails wraps the label in <div class='field_with_errors'> in case of
92
- # error, which messes up the error icon in Bootstrap basic forms unless
93
- # the icon is appended to the label itself, rather than at the end.
94
- def label_for(method, errors, field_type, options)
95
- if options.delete(:use_label) { true }
96
- args = [method, options.delete(:label), label_options(errors)]
97
- label(*args.compact).tap do |label|
98
- error_icon = show_error_icon? field_type, errors, options[:suffix]
99
- if (index = label =~ %r{</div>$}) && error_icon && basic_form?
100
- label.insert index, error_icon_tag
101
- end
102
- end
103
- end
104
- end
105
-
106
- def label_options(errors = {})
107
- klass = []
108
- klass << 'sr-only' if inline_form?
109
- klass << 'col-sm-3' if horizontal_form?
110
- klass << 'control-label' if horizontal_form?
111
- klass << 'control-label' if basic_form? && errors.any?
112
- {class: klass.join(' ')} if klass.any?
113
- end
114
-
115
- # Rails adds <div class='field_with_errors'> which messes up
116
- # Bootstrap inline form unless the label is inserted within
117
- # the div itself.
118
- def label_and_field(container_class, method, options = {}, &block)
119
- label = safe_join [' ' , options.delete(:label)]
120
- label_options = options.delete(:label_options) || {}
121
-
122
- label_and_field = @template.capture(&block)
123
- if index = label_and_field =~ %r{</div>$}
124
- label_and_field.insert index, label
125
- else
126
- label_and_field.concat label
127
- end
128
- content_tag :div, class: container_class do
129
- content_tag :label, label_and_field, label_options
130
- end
131
- end
132
-
133
- def show_error_help?
134
- @options.fetch(:errors, {}).fetch(:messages, :inline).to_s == 'inline'
135
- end
136
-
137
- def inline_form?
138
- ['inline', 'navbar'].include? @options[:layout].to_s
139
- end
140
-
141
- def horizontal_form?
142
- @options[:layout].to_s == 'horizontal'
143
- end
144
-
145
- def basic_form?
146
- !inline_form? && !horizontal_form?
147
- end
148
- end
149
- end
150
- end
@@ -1,35 +0,0 @@
1
- require 'bh/core_ext/rails/form/base_helper'
2
-
3
- module Bh
4
- module Form
5
- module CheckBoxHelper
6
- include BaseHelper
7
-
8
- def check_box(method, options = {}, checked_value = '1', unchecked_value = '0')
9
- block = -> { super method, options, checked_value, unchecked_value }
10
- if options.delete(:inline_label) { true }
11
- check_box_with_inline_label method, options, &block
12
- else
13
- check_box_with_block_label method, options, &block
14
- end
15
- end
16
-
17
- private
18
-
19
- def check_box_with_block_label(method, options = {}, &block)
20
- append_class! options, 'form-control' unless inline_form?
21
- append_class! options, 'checkbox' if horizontal_form?
22
- options[:label] ||= method.to_s.humanize
23
- base_field method, :checkbox, options, &block
24
- end
25
-
26
- def check_box_with_inline_label(method, options = {}, &block)
27
- options.merge! offset: true, use_label: false
28
- options[:label] ||= method.to_s.humanize
29
- base_field method, :checkbox, options do
30
- label_and_field 'checkbox', method, options, &block
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,15 +0,0 @@
1
- require 'bh/core_ext/rails/form/base_helper'
2
-
3
- module Bh
4
- module Form
5
- module FieldHelper
6
- include BaseHelper
7
-
8
- def field(method, field_type, options = {}, &block)
9
- options[:placeholder] ||= strip_tags(label method)
10
- append_class! options, 'form-control'
11
- base_field method, field_type, options, &block
12
- end
13
- end
14
- end
15
- end
@@ -1,23 +0,0 @@
1
- require 'bh/core_ext/rails/form/fieldset_helper'
2
-
3
- module Bh
4
- module Form
5
- module FieldsForHelper
6
- include BaseHelper
7
- include FieldsetHelper # for fieldset
8
-
9
- def fields_for(record_name, record_object = nil, fields_options = {}, &block)
10
- if record_object.is_a?(Hash) && record_object.extractable_options?
11
- record_object, fields_options = nil, record_object
12
- end
13
-
14
- fields_options[:layout] ||= @options[:layout]
15
- fields_options[:errors] ||= @options[:errors]
16
- title = fields_options.delete(:title) { record_name.to_s.humanize }
17
- wrap_in_fieldset = fields_options.fetch :fieldset, true
18
- fields = super record_name, record_object, fields_options, &block
19
- wrap_in_fieldset ? fieldset(title) { fields } : fields
20
- end
21
- end
22
- end
23
- end
@@ -1,16 +0,0 @@
1
- require 'bh/helpers/panel_helper'
2
-
3
- module Bh
4
- module Form
5
- module FieldsetHelper
6
- include BaseHelper
7
- include Bh::Helpers # for panel
8
-
9
- def fieldset(title = nil, &block)
10
- options = {tag: :fieldset, body: @template.capture(&block)}
11
- options[:heading] = title if title.present? && !inline_form?
12
- panel options
13
- end
14
- end
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- require 'bh/core_ext/rails/form/base_helper'
2
-
3
- module Bh
4
- module Form
5
- module FileFieldHelper
6
- include BaseHelper
7
-
8
- def file_field(method, options={})
9
- base_field method, :file, options do
10
- super method, options
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,17 +0,0 @@
1
- require 'bh/core_ext/rails/form/base_helper'
2
-
3
- module Bh
4
- module Form
5
- module LegendHelper
6
- include BaseHelper
7
-
8
- def legend(value, options = {})
9
- append_class! options, 'sr-only' if inline_form?
10
- text = content_tag :legend, value, options
11
- text = content_tag :div, text, class: 'col-sm-12' if horizontal_form?
12
- text = label_and_field_container(text, :legend) unless inline_form?
13
- text
14
- end
15
- end
16
- end
17
- end
@@ -1,19 +0,0 @@
1
- require 'bh/core_ext/rails/form/base_helper'
2
-
3
- module Bh
4
- module Form
5
- module RadioButtonHelper
6
- include BaseHelper
7
-
8
- def radio_button(method, tag_value, options = {})
9
- options.merge! offset: true, use_label: false
10
- options[:label] ||= tag_value
11
- base_field method, :radio_button, options do
12
- label_and_field 'radio', method, options do
13
- super method, tag_value, options
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,16 +0,0 @@
1
- require 'bh/core_ext/rails/form/base_helper'
2
-
3
- module Bh
4
- module Form
5
- module SelectHelper
6
- include BaseHelper
7
-
8
- def select(method, choices = nil, options = {}, html_options = {}, &block)
9
- append_class! html_options, 'form-control'
10
- base_field method, :select, options do
11
- super method, choices, options, html_options, &block
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,43 +0,0 @@
1
- require 'bh/core_ext/rails/form/base_helper'
2
-
3
- module Bh
4
- module Form
5
- module StaticControlHelper
6
- include BaseHelper
7
-
8
- def static_control(text_or_options_with_block = nil, options = {}, &block)
9
- text, options = if block_given?
10
- [@template.capture(&block), text_or_options_with_block]
11
- else
12
- [text_or_options_with_block, options]
13
- end
14
- static_control_string text, options || {}
15
- end
16
-
17
- private
18
-
19
- def static_control_string(text, options = {})
20
- content_tag :div, class: 'form-group' do
21
- if inline_form?
22
- label = content_tag :label, options[:label], class: 'sr-only' if options[:label]
23
- field = content_tag :p, text, class: 'form-control-static'
24
- safe_join [label, field].compact
25
- elsif horizontal_form?
26
- label = content_tag :label, options[:label], class: 'col-sm-3 control-label' if options[:label]
27
- field = content_tag :p, text, class: 'form-control-static'
28
- if options[:label]
29
- field = content_tag :div, field, class: 'col-sm-9'
30
- else
31
- field = content_tag :div, field, class: 'col-sm-9 col-sm-offset-3'
32
- end
33
- safe_join [label, field].compact
34
- else
35
- label = content_tag :label, options[:label] if options[:label]
36
- field = content_tag :p, text, class: 'form-control-static'
37
- safe_join [label, field].compact
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,23 +0,0 @@
1
- require 'bh/core_ext/rails/form/base_helper'
2
-
3
- module Bh
4
- module Form
5
- module SubmitHelper
6
- include BaseHelper
7
-
8
- def submit(value=nil, options={})
9
- context = options.delete(:context) || 'primary'
10
- append_class! options, "btn btn-#{context}"
11
- if horizontal_form?
12
- content_tag :div, class: 'form-group' do
13
- content_tag :div, class: 'col-sm-offset-3 col-sm-9' do
14
- super value, options
15
- end
16
- end
17
- else
18
- super value, options
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,46 +0,0 @@
1
- require 'bh/core_ext/rails/form/check_box_helper'
2
- require 'bh/core_ext/rails/form/field_helper'
3
- require 'bh/core_ext/rails/form/fieldset_helper'
4
- require 'bh/core_ext/rails/form/fields_for_helper'
5
- require 'bh/core_ext/rails/form/file_field_helper'
6
- require 'bh/core_ext/rails/form/legend_helper'
7
- require 'bh/core_ext/rails/form/radio_button_helper'
8
- require 'bh/core_ext/rails/form/select_helper'
9
- require 'bh/core_ext/rails/form/static_control_helper'
10
- require 'bh/core_ext/rails/form/submit_helper'
11
-
12
- module Bh
13
- # @api private
14
- class FormBuilder < ActionView::Helpers::FormBuilder
15
- include ActionView::Helpers::SanitizeHelper
16
- extend ActionView::Helpers::SanitizeHelper::ClassMethods
17
- include Form::CheckBoxHelper
18
- include Form::FieldHelper
19
- include Form::FieldsetHelper
20
- include Form::FieldsForHelper
21
- include Form::FileFieldHelper
22
- include Form::LegendHelper
23
- include Form::RadioButtonHelper
24
- include Form::SelectHelper
25
- include Form::StaticControlHelper
26
- include Form::SubmitHelper
27
-
28
- # @note: field_helpers are returned as symbols in ActionView 4 and as
29
- # strings in ActionView 3
30
- def self.textual_field_helpers
31
- non_textual_field_helpers = %w(label hidden_field range_field check_box
32
- file_field radio_button select submit fields_for label)
33
- field_helpers.map(&:to_s) - non_textual_field_helpers
34
- end
35
-
36
- # Use the same template for all the textual field helpers such as
37
- # email_field, password_field, etc.
38
- # Exclude the ones that should not have additional styles.
39
- # Do not show error icons on number_field not to cover the sliders.
40
- textual_field_helpers.each do |field_type|
41
- define_method field_type do |method, options = {}|
42
- field(method, field_type, options) { super method, options }
43
- end
44
- end
45
- end
46
- end
@@ -1,41 +0,0 @@
1
- require 'bh/core_ext/rails/base_helper'
2
- require 'bh/core_ext/rails/form_builder'
3
-
4
- module Bh
5
- module Rails
6
- module Helpers
7
- include BaseHelper
8
- include ActionView::Helpers::FormHelper # for form_for
9
-
10
- def form_for(record, options = {}, &block)
11
- options[:layout] ||= 'navbar' if Bh::Stack.find(Bh::Navbar)
12
- add_form_options!(options) if options[:layout]
13
- html = super record, options, &block
14
-
15
- if Bh::Stack.find(Bh::Nav)
16
- container = Bh::Base.new(self) { html }
17
- container.render_tag :li
18
- else
19
- html
20
- end
21
- end
22
-
23
- private
24
-
25
- def add_form_options!(options)
26
- options[:html] ||= {}
27
- options[:html].merge! role: 'form'
28
- append_class! options[:html], class_for(options[:layout])
29
- options.merge! builder: FormBuilder
30
- end
31
-
32
- def class_for(layout)
33
- case layout.to_s
34
- when 'navbar' then 'navbar-form'
35
- when 'inline' then 'form-inline'
36
- when 'horizontal' then 'form-horizontal'
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,27 +0,0 @@
1
- require 'bh/core_ext/rails/form_for_helper'
2
-
3
- module Bh
4
- module Extensions
5
- # Makes Bootstrap helpers available in Rails applications.
6
- #
7
- # To use Bh in a Rails app you need 1 step:
8
- #
9
- # - include bh in the Gemfile
10
- #
11
- # The current class is loaded during the initialization process, so
12
- # there is no need to manually require any other file.
13
- class Railtie < ::Rails::Railtie
14
- initializer 'bh.add_helpers' do
15
- ActionView::Base.send :include, Bh::Helpers
16
- ActionView::Base.send :include, Bh::Rails::Helpers
17
- end
18
-
19
- initializer 'bh.add_views' do |app|
20
- views_path = File.expand_path '../../views', __FILE__
21
- ActionController::Base.prepend_view_path views_path
22
- end
23
- end
24
- end
25
-
26
- Bh.framework = :rails
27
- end
@@ -1,40 +0,0 @@
1
- require 'bh/classes/alert_box'
2
-
3
- module Bh
4
- module Helpers
5
- # Displays a Bootstrap-styled alert message.
6
- # @see http://getbootstrap.com/components/#alerts
7
- # @return [String] the HTML to display a Bootstrap-styled alert message.
8
- # @overload alert_box(content, options = {})
9
- # @param [#to_s] content the content to display in the alert.
10
- # @param [Hash] options the options for the alert box. Any option not
11
- # listed below is passed as an HTML attribute to the alert’s `<div>`.
12
- # @option options [Boolean] :dismissible (false) whether to display an
13
- # '×' to the right of the box that can be clicked to dismiss the alert.
14
- # @option options [#to_s] :context (:info) the contextual alternative to
15
- # apply to the alert. Can be `:danger`, `:info`, `:success` or
16
- # `:warning`.
17
- # @option options [#to_s] :priority if set to one of the priority levels
18
- # of Rails flash contents, determines the context of the alert box.
19
- # Can be :alert or :notice.
20
- # @example Display a dismissible alert box with a plain-text content.
21
- # alert_box 'User updated successfully', dismissible: true
22
- # @overload alert_box(options = {}, &block)
23
- # @param [Hash] options the options for the alert box (see above).
24
- # @yieldreturn [#to_s] the content to display in the alert.
25
- # @example Display a success alert box with an HTML content.
26
- # alert_box context: :success do
27
- # content_tag :strong, 'User updated successfully'
28
- # end
29
- def alert_box(*args, &block)
30
- alert_box = Bh::AlertBox.new(self, *args, &block)
31
- alert_box.extract! :context, :priority, :dismissible
32
-
33
- alert_box.append_class! :alert
34
- alert_box.append_class! alert_box.context_class
35
- alert_box.merge! role: :alert
36
- alert_box.prepend_html! alert_box.dismissible_button
37
- alert_box.render_tag :div
38
- end
39
- end
40
- end
@@ -1,40 +0,0 @@
1
- require 'bh/classes/button'
2
-
3
- module Bh
4
- module Helpers
5
- # Displays a Bootstrap-styled button.
6
- # @see http://getbootstrap.com/css/#buttons
7
- # @return [String] the HTML to display a Bootstrap-styled button.
8
- # @overload button(caption, options = {})
9
- # @param [#to_s] caption the caption to display in the button.
10
- # @param [Hash] options the options for the button. Any option not
11
- # listed below is passed as an HTML attribute to the `<button>` tag.
12
- # @option options [#to_s] :context (:default) the contextual alternative
13
- # to apply to the button. Can be `:danger`, `:info`, `:link`,
14
- # `:primary`, `:success` or `:warning`.
15
- # @option options [#to_s] :size the size of the button.
16
- # Can be `:extra_small` (alias `:xs`), `:large` (alias `:lg`) or
17
- # `:small` (alias `:sm`).
18
- # @option options [#to_s] :layout if set to `:block`, span the button
19
- # for the full width of the parent.
20
- # @example Display a button styled as a link.
21
- # button 'Click here', context: :link
22
- # @overload button(options = {}, &block)
23
- # @param [Hash] options the options for the button (see above).
24
- # @yieldreturn [#to_s] the caption to display in the button.
25
- # @example Display a button with an HTML caption.
26
- # button do
27
- # content_tag :strong, 'Click here'
28
- # end
29
- def button(*args, &block)
30
- button = Bh::Button.new(self, *args, &block)
31
- button.extract! :context, :size, :layout
32
-
33
- button.append_class! :btn
34
- button.append_class! button.context_class
35
- button.append_class! button.size_class
36
- button.append_class! button.layout_class
37
- button.render_tag :button
38
- end
39
- end
40
- end