Class: Charty::Layout

Inherits:
Object
  • Object
show all
Defined in:
lib/charty/layout.rb

Instance Method Summary collapse

Constructor Details

#initialize(frontend, definition = :horizontal) ⇒ Layout

Returns a new instance of Layout


3
4
5
6
# File 'lib/charty/layout.rb', line 3

def initialize(frontend, definition = :horizontal)
  @frontend = frontend
  @layout = parse_definition(definition)
end

Instance Method Details

#<<(content) ⇒ Object


23
24
25
26
27
28
29
30
# File 'lib/charty/layout.rb', line 23

def <<(content)
  if content.respond_to?(:each)
    content.each {|c| self << c }
  else
    @layout << content
  end
  nil
end

#parse_definition(definition) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/charty/layout.rb', line 8

def parse_definition(definition)
  case definition
  when :horizontal
    ArrayLayout.new
  when :vertical
    ArrayLayout.new(:vertical)
  else
    if match = definition.to_s.match(/\Agrid(\d+)x(\d+)\z/)
      num_cols = match[1].to_i
      num_rows = match[2].to_i
      GridLayout.new(num_cols, num_rows)
    end
  end
end

#render(filename = "") ⇒ Object


32
33
34
# File 'lib/charty/layout.rb', line 32

def render(filename="")
  @frontend.render_layout(@layout)
end