Class: Aureus::Components::Box

Inherits:
Renderable show all
Defined in:
lib/aureus/components/box.rb

Instance Method Summary collapse

Methods inherited from Renderable

#compact, #compact_render, #content_tag, #init

Constructor Details

#initialize(title, options, &block) ⇒ Box

Returns a new instance of Box.



4
5
6
7
8
9
10
# File 'lib/aureus/components/box.rb', line 4

def initialize(title, options, &block)
  init options, for: :text, centered: false
  init_haml_helpers
  @title = title
  @buttons = Array.new
  @content = capture_haml(self, &block)
end

Instance Method Details

#button(content) ⇒ Object



20
21
22
# File 'lib/aureus/components/box.rb', line 20

def button(content)
  @buttons << content
end

#content(&block) ⇒ Object



12
13
14
# File 'lib/aureus/components/box.rb', line 12

def content(&block)
  @new_content = capture_haml(&block)
end

#foot(&block) ⇒ Object



16
17
18
# File 'lib/aureus/components/box.rb', line 16

def foot(&block)
  @foot = capture_haml &block
end

#renderObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aureus/components/box.rb', line 24

def render
  title = ('h3', compact(('span', @title), @buttons.join))
  classes = ['box']
  classes << 'centered' if @options[:centered]
  @content = @new_content if !@new_content.nil?
   'div', class: classes.join(' ') do
    case @options[:for]
      when :form
        @content = ('ul', @content, class: 'content')
    end
    footer = @foot.nil? ? '' : ('div', @foot, class: 'foot')
    compact title, ('div', @content), footer
  end
end