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(block)
- 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 |
# File 'app/helpers/bootstrap/button_helper.rb', line 78 def (*args) text = args.shift = (args.) href = .delete(:url) = (, args) if href.present? link_to(text, href, ) else content_tag(:button, text, ) end end |
#button_group(options = {}) { ... } ⇒ String
Returns a Bootstrap button group
114 115 116 117 118 119 120 121 |
# File 'app/helpers/bootstrap/button_helper.rb', line 114 def (={}) = () = ensure_class(, 'btn-group') content_tag(:div, ) do yield end end |
#button_toolbar(options = {}) { ... } ⇒ String
Returns a Bootstrap button toolbar
98 99 100 101 102 103 104 105 |
# File 'app/helpers/bootstrap/button_helper.rb', line 98 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.
127 128 129 |
# File 'app/helpers/bootstrap/button_helper.rb', line 127 def (types_and_sizes) types_and_sizes.each { |e| raise(InvalidButtonModifierError, e.inspect) unless BUTTON_ALL.include?(e.to_s) } end |