Module: Bootstrap::ButtonHelper
- Defined in:
- app/helpers/bootstrap/button_helper.rb
Overview
Helper for producing Twitter Bootstrap buttons OR links that look like buttons.
See:
Constant Summary collapse
- InvalidButtonModifierError =
Class.new(StandardError)
- BUTTON_TYPES =
%w(default primary info success warning danger inverse link)
- BUTTON_SIZES =
%w(default large small mini)
- BUTTON_OTHERS =
%w(
- BUTTON_ALL =
BUTTON_TYPES + BUTTON_SIZES + BUTTON_OTHERS
Instance Method Summary collapse
-
#button(*args) ⇒ String
Returns <button> or <a> styled as Bootstrap button.
-
#button_group(options = {}) { ... } ⇒ String
Returns a Bootstrap button group.
-
#button_toolbar(options = {}) { ... } ⇒ String
Returns a Bootstrap button toolbar.
-
#validate_button_types_and_sizes(types_and_sizes) ⇒ Object
Ensures each entry in types_and_sizes is a valid button modifier.
Instance Method Details
#button(text, options = {}) ⇒ String #button(text, type, options = {}) ⇒ String #button(text, size, options = {}) ⇒ String #button(text, type, size, options = {}) ⇒ String
Returns <button> or <a> styled as Bootstrap button
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/bootstrap/button_helper.rb', line 78 def (*args) = (args.) text = args.shift href = .delete(:url) = (, args) text = yield if block_given? if href.present? link_to(text, href, ) else content_tag(:button, text, ) end end |
#button_group(options = {}) { ... } ⇒ String
Returns a Bootstrap button group
116 117 118 119 120 121 122 123 |
# File 'app/helpers/bootstrap/button_helper.rb', line 116 def (={}) = () = ensure_class(, 'btn-group') content_tag(:div, ) do yield end end |
#button_toolbar(options = {}) { ... } ⇒ String
Returns a Bootstrap button toolbar
100 101 102 103 104 105 106 107 |
# File 'app/helpers/bootstrap/button_helper.rb', line 100 def (={}) = () = ensure_class(, 'btn-toolbar') content_tag(:div, ) do yield end end |
#validate_button_types_and_sizes(types_and_sizes) ⇒ Object
Ensures each entry in types_and_sizes is a valid button modifier.
129 130 131 |
# File 'app/helpers/bootstrap/button_helper.rb', line 129 def (types_and_sizes) types_and_sizes.each { |e| raise(InvalidButtonModifierError, e.inspect) unless BUTTON_ALL.include?(e.to_s) } end |