Class: Wee::Renderer

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

Overview

Base class of all Renderer classes.

Direct Known Subclasses

HtmlCanvas

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session = nil, request = nil, response = nil, callbacks = nil, document = nil, current_component = nil) ⇒ Renderer

Returns a new instance of Renderer.



14
15
16
17
18
19
20
21
# File 'lib/wee/renderer.rb', line 14

def initialize(session=nil, request=nil, response=nil, callbacks=nil, document=nil, current_component=nil)
  @session = session
  @request = request
  @response = response
  @callbacks = callbacks
  @document = document
  @current_component = current_component
end

Instance Attribute Details

#callbacksObject

Returns the value of attribute callbacks.



10
11
12
# File 'lib/wee/renderer.rb', line 10

def callbacks
  @callbacks
end

#current_componentObject

Returns the value of attribute current_component.



12
13
14
# File 'lib/wee/renderer.rb', line 12

def current_component
  @current_component
end

#documentObject

Returns the value of attribute document.



11
12
13
# File 'lib/wee/renderer.rb', line 11

def document
  @document
end

#requestObject

Returns the value of attribute request.



8
9
10
# File 'lib/wee/renderer.rb', line 8

def request
  @request
end

#responseObject

Returns the value of attribute response.



9
10
11
# File 'lib/wee/renderer.rb', line 9

def response
  @response
end

#sessionObject

Returns the value of attribute session.



7
8
9
# File 'lib/wee/renderer.rb', line 7

def session
  @session
end

Instance Method Details

#closeObject

Subclass responsibility.



60
61
# File 'lib/wee/renderer.rb', line 60

def close
end

#render(component) ⇒ Object



45
46
47
48
49
# File 'lib/wee/renderer.rb', line 45

def render(component)
  close
  component.decoration.render_on(self)
  nil
end

#render_decoration(decoration) ⇒ Object



51
52
53
54
55
# File 'lib/wee/renderer.rb', line 51

def render_decoration(decoration)
  close
  decoration.render_on(self)
  nil
end

#with(component) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/wee/renderer.rb', line 23

def with(component)
  rclass = component.renderer_class
  if rclass == self
    # reuse renderer
    old_component = @current_component 
    begin
      @current_component = component
      yield self
    ensure
      @current_component = old_component
    end
  else
    close
    r = rclass.new(@session, @request, @response, @callbacks, @document, component)
    begin
      yield r
    ensure
      r.close
    end
  end
end