Class: Spark::ModalHelper::ModalPanel

Inherits:
Helper
  • Object
show all
Defined in:
app/helpers/spark/modal_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ModalPanel

Returns a new instance of ModalPanel.



5
6
7
8
9
# File 'app/helpers/spark/modal_helper.rb', line 5

def initialize( options = {} )
  @options = add_class( options, 'modal-panel' )
  @options = Spark::Helpers.set_aria_keys( @options )
  @options = ({ 'aria-modal'=> true, 'aria-hidden'=> true }).merge(@options)
end

Instance Method Details

#display(body) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/spark/modal_helper.rb', line 11

def display( body )
  if first_header = body.scan(/\A<header.+?\/header>/m).first
    body = body.sub( first_header, '' ).html_safe
    first_header = first_header.html_safe
  end

  if last_footer = body.scan(/<footer.+?\/footer>\z/m).first
    body = body.sub(last_footer, '').html_safe
    last_footer = last_footer.html_safe
  end

  ( :section, @options ) do
    concat first_header
    concat ( :div, class: 'modal-panel-content' ) {
      concat body
    }
    concat last_footer
  end
end


42
43
44
45
46
47
48
# File 'app/helpers/spark/modal_helper.rb', line 42

def footer( options = {}, &block )
  options = add_class options, "modal-panel-footer"

  ( :footer, options ) {
    concat capture( &block ).html_safe if block_given?
  }
end

#header(text = nil, options = {}, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/spark/modal_helper.rb', line 31

def header( text = nil, options = {}, &block )
  options, text = text, nil if text.is_a? Hash

  options = add_class( options, "modal-panel-header" )

  ( :header, options ) {
    concat ( :h4, text, class: 'modal-panel-title' ) if text
    concat capture( &block ).html_safe if block_given?
  }
end