class Charty::Layout

Public Class Methods

new(frontend, definition = :horizontal) click to toggle source
# File lib/charty/layout.rb, line 3
def initialize(frontend, definition = :horizontal)
  @frontend = frontend
  @layout = parse_definition(definition)
end

Public Instance Methods

<<(content) click to toggle source
# 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) click to toggle source
# 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="") click to toggle source
# File lib/charty/layout.rb, line 32
def render(filename="")
  @frontend.render_layout(@layout)
end