Module: Bootstrap::ModalHelper
- Defined in:
- app/helpers/bootstrap/modal_helper.rb
Overview
Rails helper for producing Bootstrap modal dialogs
Instance Method Summary collapse
-
#modal(options = {}) ⇒ Object
Returns a Bootstrap modal dialog.
- #modal_alert(*args, &block) ⇒ Object
-
#modal_body(*args, &block) ⇒ Object
Returns a DIV for Bootstrap modal body.
- #modal_confirm(*args, &block) ⇒ Object
-
#modal_footer(*args, &block) ⇒ Object
Returns a DIV for Bootstrap modal footer Defaults to including #modal_footer_close_button.
-
#modal_footer_close_button(*args) ⇒ Object
Returns a close button for Bootstrap modal footer.
- #modal_footer_ok_button(*args) ⇒ Object
-
#modal_header(*args, &block) ⇒ Object
Returns a DIV for Bootstrap modal header.
-
#modal_header_close_button(show = true) ⇒ Object
Returns a Bootstrap modal close button.
-
#modal_trigger(text, options = {}) ⇒ Object
Returns an A tag to trigger (open) a Boostrap modal.
Instance Method Details
#modal(options = {}) ⇒ Object
Returns a Bootstrap modal dialog
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/bootstrap/modal_helper.rb', line 16 def modal(={}) = () .has_key?(:id) or raise(ArgumentError, "missing :id option") = ensure_class(, %w(modal fade)) .merge!(tabindex: "-1", role: "dialog") content_tag(:div, ) do content_tag(:div, class: "modal-dialog") do content_tag(:div, class: "modal-content") do yield end end end end |
#modal_alert(*args, &block) ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'app/helpers/bootstrap/modal_helper.rb', line 104 def modal_alert(*args, &block) = (args.) header = .delete(:header) || "Alert" modal() do modal_header(header) + modal_body(*args, &block) + end end |
#modal_body(*args, &block) ⇒ Object
Returns a DIV for Bootstrap modal body
48 49 50 51 52 53 54 55 56 |
# File 'app/helpers/bootstrap/modal_helper.rb', line 48 def modal_body(*args, &block) = (args.) = ensure_class(, 'modal-body') content = block_given? ? capture(&block) : args.shift content_tag(:div, ) do content end end |
#modal_confirm(*args, &block) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/helpers/bootstrap/modal_helper.rb', line 115 def modal_confirm(*args, &block) = (args.) header = .delete(:header) || "Confirmation" modal() do modal_header(header) + modal_body(*args, &block) + do (icon('remove', 'Cancel')) + (icon('ok', :white, 'Ok'), :primary) end end end |
#modal_footer(*args, &block) ⇒ Object
Returns a DIV for Bootstrap modal footer Defaults to including #modal_footer_close_button.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/helpers/bootstrap/modal_helper.rb', line 60 def (*args, &block) = (args.) = ensure_class(, 'modal-footer') content = if block_given? capture(&block) elsif args.size > 0 args.shift else end content_tag(:div, ) do content end end |
#modal_footer_close_button(*args) ⇒ Object
Returns a close button for Bootstrap modal footer.
86 87 88 89 90 91 92 93 |
# File 'app/helpers/bootstrap/modal_helper.rb', line 86 def (*args) = (args.) = ensure_class(, 'modal-close modal-footer-close') .merge!(data: {dismiss: 'modal'}) args.unshift("Close") if args.empty? (*args, ) end |
#modal_footer_ok_button(*args) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'app/helpers/bootstrap/modal_helper.rb', line 95 def (*args) = (args.) = ensure_class(, 'modal-footer-ok') .merge!(data: {dismiss: 'modal'}) args.unshift("Ok") if args.empty? (*args, ) end |
#modal_header(*args, &block) ⇒ Object
Returns a DIV for Bootstrap modal header
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/helpers/bootstrap/modal_helper.rb', line 32 def modal_header(*args, &block) = (args.) = ensure_class(, 'modal-header') show_close = .delete(:close) != false content = block_given? ? capture(&block) : args.shift content_tag(:div, ) do (show_close) + content_tag(:h4, class: "modal-title") do content end end end |
#modal_header_close_button(show = true) ⇒ Object
Returns a Bootstrap modal close button
78 79 80 81 82 83 |
# File 'app/helpers/bootstrap/modal_helper.rb', line 78 def (show=true) return ''.html_safe unless show (type: 'button', class: 'close', data: {dismiss: 'modal'}) do content_tag(:span, "×".html_safe) end end |
#modal_trigger(text, options = {}) ⇒ Object
Returns an A tag to trigger (open) a Boostrap modal
6 7 8 9 10 11 12 13 |
# File 'app/helpers/bootstrap/modal_helper.rb', line 6 def modal_trigger(text, ={}) = () href = .delete(:href) or raise(ArgumentError, 'missing :href option') .merge!(role: 'button', href: href, data: { toggle: 'modal'}) = ensure_class(, 'btn') content_tag(:a, text, ) end |