Module: ModalHelper

Defined in:
app/helpers/modal_helper.rb

Instance Method Summary collapse

Instance Method Details

#close_button(dismiss) ⇒ Object



36
37
38
# File 'app/helpers/modal_helper.rb', line 36

def close_button(dismiss)
   :button, "×".html_safe, :class => "close", "data-dismiss" => "#{dismiss}", "aria-hidden" => "true"
end


28
29
30
# File 'app/helpers/modal_helper.rb', line 28

def modal_body(options = {}, &block)
   :div, options, :class => 'modal-body', &block
end


52
53
54
55
56
# File 'app/helpers/modal_helper.rb', line 52

def modal_cancel_button content, options = {}
  default_options = { :class => "btn btn-default", :data => { dismiss: "modal" } }

   :button, content, default_options.merge(options)
end

modals have a header, a body, a footer for options.



4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/modal_helper.rb', line 4

def modal_dialog(options = {}, &block)
   :div, :id => options[:id], :class => "modal fade", :role => "dialog" do
     :div, class: 'modal-dialog' do
       :div, class: 'modal-content' do
        modal_header(options[:header]) +
        modal_body(options[:body]) +
        modal_footer(options[:footer])
      end
    end
  end
end


32
33
34
# File 'app/helpers/modal_helper.rb', line 32

def modal_footer(options = {}, &block)
 :div, options, :class => 'modal-footer', &block
end


16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/modal_helper.rb', line 16

def modal_header(options = {}, &block)
  dismiss = options.delete(:dismiss) || 'modal'
   :div, :class => 'modal-header' do
    if options[:show_close]
      close_button(dismiss) +
      (:h4, options[:title], :class => 'modal-title', &block)
    else
      (:h4, options[:title], :class => 'modal-title', &block)
    end
  end
end


40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/modal_helper.rb', line 40

def modal_toggle(content_or_options = nil, options = {}, &block)
  if block_given?
    options = content_or_options if content_or_options.is_a?(Hash)
    default_options = { :class => 'btn', "data-toggle" => "modal", "data-target" => options.delete[:dialog] }.merge(options)

     :a, nil, default_options, true, &block
  else
    default_options = { :class => 'btn', "data-toggle" => "modal", "data-target" => options.delete(:dialog) }.merge(options)
     :a, content_or_options, default_options, true
  end
end