Class: Weaver::Panel

Inherits:
Elements show all
Defined in:
lib/weaver/element_types/panel.rb

Instance Method Summary collapse

Methods inherited from Elements

#_button, #accordion, #background, #badge, #big_button, #big_embossed_button, #block_button, #breadcrumb, #center, #circle_button, #col, #crossfade_image, #embossed_button, #gallery, #half, #hyperlink, #ibox, #icon, #image, #jumbotron, #math, #method_missing, #modal, #normal_button, #on_page_load, #outline_button, #p, #panel, #quarter, #request_css, #request_js, #root, #rounded_button, #row, #small_button, #syntax, #table, #table_from_hashes, #table_from_source, #tabs, #text, #third, #tiny_button, #twothirds, #wform, #widget, #write_script_once

Constructor Details

#initialize(page, anchors, options = {}) ⇒ Panel

Returns a new instance of Panel.



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

def initialize(page, anchors, options = {})
  super(page, anchors)
  @title = nil
  @footer = nil
  @type = :ibox
  @body = true
  @extra = nil
  @min_height = nil
  @page = page
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Weaver::Elements

Instance Method Details

#body(hasBody) ⇒ Object



96
97
98
# File 'lib/weaver/element_types/panel.rb', line 96

def body(hasBody)
  @body = hasBody
end

#extra(&block) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/weaver/element_types/panel.rb', line 109

def extra(&block)
  if block
    elem = Elements.new(@page, @anchors)
    elem.instance_eval(&block)
    @extra = elem.generate
  end
end


117
118
119
120
121
122
123
124
# File 'lib/weaver/element_types/panel.rb', line 117

def footer(footer = nil, &block)
  @footer = footer
  if block
    elem = Elements.new(@page, @anchors)
    elem.instance_eval(&block)
    @footer = elem.generate
  end
end

#generateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/weaver/element_types/panel.rb', line 17

def generate
  inner = super

  types =
    {
      ibox: { outer: 'ibox float-e-margins', header: 'ibox-title', body: 'ibox-content', footer: 'ibox-footer' },
      panel: { outer: 'panel panel-default', header: 'panel-heading', body: 'panel-body', footer: 'panel-footer' },
      primary: { outer: 'panel panel-primary', header: 'panel-heading', body: 'panel-body', footer: 'panel-footer' },
      success: { outer: 'panel panel-success', header: 'panel-heading', body: 'panel-body', footer: 'panel-footer' },
      info: { outer: 'panel panel-info', header: 'panel-heading', body: 'panel-body', footer: 'panel-footer' },
      warning: { outer: 'panel panel-warning', header: 'panel-heading', body: 'panel-body', footer: 'panel-footer' },
      danger: { outer: 'panel panel-danger', header: 'panel-heading', body: 'panel-body', footer: 'panel-footer' },
      blank: { outer: 'panel blank-panel', header: 'panel-heading', body: 'panel-body', footer: 'panel-footer' }
    }

  title = @title
  footer = @footer
  hasBody = @body
  extra = @extra
  options = @options
  classNames = types[@type]
  min_height = @min_height

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

  outer_class = classNames[:outer]

  outer_class = 'ibox collapsed' if options[:collapsed]

  elem.instance_eval do
    div class: outer_class do
      if title
        div class: classNames[:header] do
          h5 title

          div class: 'ibox-tools' do
            if options[:collapsible] || options[:collapsed]
              a class: 'collapse-link' do
                icon :"chevron-up"
              end
            end
            if options[:expandable]
              a class: 'fullscreen-link' do
                icon :expand
              end
            end
            if options[:closable]
              a class: 'close-link' do
                icon :times
              end
            end
          end
        end
      end
      if hasBody
        div class: classNames[:body], style: "min-height: #{min_height}px" do
          text inner
        end
      end
      text extra if extra
      if footer
        div class: classNames[:footer] do
          text footer
        end
      end
    end
  end

  elem.generate
end

#min_height(val) ⇒ Object



88
89
90
# File 'lib/weaver/element_types/panel.rb', line 88

def min_height(val)
  @min_height = val
end

#title(title = nil, &block) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/weaver/element_types/panel.rb', line 100

def title(title = nil, &block)
  @title = title
  if block
    elem = Elements.new(@page, @anchors)
    elem.instance_eval(&block)
    @title = elem.generate
  end
end

#type(aType) ⇒ Object



92
93
94
# File 'lib/weaver/element_types/panel.rb', line 92

def type(aType)
  @type = aType
end