Class: Argyle::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/argyle/renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(style_container) ⇒ Renderer

Returns a new instance of Renderer.

Parameters:



4
5
6
7
8
9
# File 'lib/argyle/renderer.rb', line 4

def initialize(style_container)
  @style_container = style_container
  @views = {}

  set_view(Argyle::Component::Text, Argyle::View::Text)
end

Instance Method Details

#render(page) ⇒ Object

Parameters:

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/argyle/renderer.rb', line 29

def render(page)
  windows = page.layout.windows

  page.components.each_value do |component|
    component_class = component.class
    area = component.area

    unless @views.include?(component_class)
      raise Argyle::Error::NotFound.new("View not found fo component #{component_class}")
    end

    raise Argyle::Error::NotFound.new("Window not found for area: #{area}") unless windows.include?(area)

    @views[component_class].render(windows[area], component)
  end

  windows.each_value(&:refresh)
end

#set_view(component_klass, view_klass) ⇒ Object

Parameters:

Raises:



17
18
19
20
21
22
# File 'lib/argyle/renderer.rb', line 17

def set_view(component_klass, view_klass)
  Argyle::Assert.klass(Argyle::Component::Base, component_klass)
  Argyle::Assert.klass(Argyle::View::Base, view_klass)

  @views[component_klass] = view_klass.new(@style_container)
end