Module: ModalHelper
- Includes:
- ActionView::Helpers, FormatHelper
- Defined in:
- app/helpers/modal_helper.rb
Instance Method Summary collapse
- #modal(options = {}, &block) ⇒ Object
- #modal_body(content_or_options = nil, options = {}, &block) ⇒ Object
- #modal_footer(content_or_options = nil, options = {}, &block) ⇒ Object
- #modal_header(content_or_options = nil, options = {}, &block) ⇒ Object
Methods included from FormatHelper
#prepend_class, #squeeze_n_strip
Instance Method Details
#modal(options = {}, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/modal_helper.rb', line 5 def modal(={}, &block) = .delete(:button) || {} caption = .delete(:caption) || 'Modal' modal_dialog_id = [:id] || "modal-#{SecureRandom.hex(3)}" [:data] = ([:data] || {}).merge({toggle: 'modal', target: "##{modal_dialog_id}"}) size = case .delete(:size).try(:to_sym) when :xsmall 'modal-sm' when :large 'modal-lg' else end prepend_class(, 'modal', 'fade') .merge!({id: modal_dialog_id, tabindex: -1, role: 'dialog', aria: {hidden: true}}) (( caption, ) + (content_tag :div, do content_tag :div, class: "modal-dialog #{size}" do content_tag :div, class: 'modal-content' do yield if block_given? end end end)).html_safe end |
#modal_body(content_or_options = nil, options = {}, &block) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/modal_helper.rb', line 45 def modal_body(=nil, ={}, &block) .is_a?(Hash) ? = : content = prepend_class(, 'modal-body') content_tag :div, do content.presence || capture(&block) end end |
#modal_footer(content_or_options = nil, options = {}, &block) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/modal_helper.rb', line 55 def (=nil, ={}, &block) .is_a?(Hash) ? = : content = prepend_class(, 'modal-footer') content_tag :div, do content.presence || capture(&block) end end |
#modal_header(content_or_options = nil, options = {}, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/modal_helper.rb', line 32 def modal_header(=nil, ={}, &block) .is_a?(Hash) ? = : content = prepend_class(, 'modal-title') content_tag :div, class: 'modal-header' do ("<button type='button' class='close' data-dismiss='modal'><span aria-hidden='true'>×</span></button>" + (content_tag :h3, do content.presence || capture(&block) end)).html_safe end end |