Class: Garterbelt::Renderer

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

Direct Known Subclasses

Cache, ClosedTag, Text

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Renderer

Returns a new instance of Renderer.



6
7
8
9
10
# File 'lib/renderers/renderer.rb', line 6

def initialize(opts)
  self.view = opts[:view] || raise(ArgumentError, ":view required in initialization options")
  self.style = opts.delete(:render_style)
  self.escape = view._escape
end

Instance Attribute Details

#escapeObject

Returns the value of attribute escape.



3
4
5
# File 'lib/renderers/renderer.rb', line 3

def escape
  @escape
end

#styleObject



25
26
27
# File 'lib/renderers/renderer.rb', line 25

def style
  @style ||= view.render_style
end

#viewObject

Returns the value of attribute view.



3
4
5
# File 'lib/renderers/renderer.rb', line 3

def view
  @view
end

Instance Method Details

#indentObject



29
30
31
# File 'lib/renderers/renderer.rb', line 29

def indent
  style == :minified ? "" : ' '*level*2
end

#levelObject



21
22
23
# File 'lib/renderers/renderer.rb', line 21

def level 
  view._level
end

#line_endObject



33
34
35
# File 'lib/renderers/renderer.rb', line 33

def line_end
  style == :minified ?  "" : "\n"
end

#outputObject

Rendering ———————————————–



13
14
15
# File 'lib/renderers/renderer.rb', line 13

def output
  view.output
end

#output=(alt_output) ⇒ Object



17
18
19
# File 'lib/renderers/renderer.rb', line 17

def output=(alt_output)
  view.output = alt_output
end

#renderObject

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/renderers/renderer.rb', line 37

def render
  raise NotImplementedError, "Subclasses must implement #render"
end