Class: Weaver::ModalDialog

Inherits:
Object
  • Object
show all
Defined in:
lib/weaver/element_types/modal_dialog.rb

Overview

Modal dialog feature

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, anchors, id, &block) ⇒ ModalDialog

Returns a new instance of ModalDialog.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/weaver/element_types/modal_dialog.rb', line 6

def initialize(page, anchors, id, &block)
  @page = page
  @anchors = anchors
  @id = id || @page.create_anchor('modal')

  @header_content = Elements.new(@page, @anchors)
  @body_content = Elements.new(@page, @anchors)
  @footer_content = Elements.new(@page, @anchors)

  instance_eval(&block) if block
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



18
19
20
# File 'lib/weaver/element_types/modal_dialog.rb', line 18

def id
  @id
end

Instance Method Details

#body(&block) ⇒ Object



24
25
26
# File 'lib/weaver/element_types/modal_dialog.rb', line 24

def body(&block)
  @body_content.instance_eval(&block)
end


28
29
30
# File 'lib/weaver/element_types/modal_dialog.rb', line 28

def footer(&block)
  @footer_content.instance_eval(&block)
end

#generateObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/weaver/element_types/modal_dialog.rb', line 32

def generate
  elem = Elements.new(@page, @anchors)

  id = @id
  header_content = @header_content
  body_content = @body_content
  footer_content = @footer_content

  elem.instance_eval do
    div class: 'modal fade', id: id, tabindex: -1, role: 'dialog' do
      div class: 'modal-dialog', role: 'document' do
        div class: 'modal-content' do
          div class: 'modal-header' do
            button '×', type: 'button', class: 'close', "data-dismiss": 'modal', "aria-label": 'Close'
            text header_content.generate
          end
          div class: 'modal-body' do
            text body_content.generate
          end
          div class: 'modal-footer' do
            text footer_content.generate
          end
        end
      end
    end
  end

  elem.generate
end

#header(&block) ⇒ Object



20
21
22
# File 'lib/weaver/element_types/modal_dialog.rb', line 20

def header(&block)
  @header_content.instance_eval(&block)
end