Class: Garterbelt::Text

Inherits:
Renderer show all
Defined in:
lib/renderers/text.rb

Direct Known Subclasses

Comment

Instance Attribute Summary collapse

Attributes inherited from Renderer

#escape, #style, #view

Instance Method Summary collapse

Methods inherited from Renderer

#indent, #level, #output, #output=

Constructor Details

#initialize(opts) ⇒ Text

Returns a new instance of Text.



5
6
7
8
# File 'lib/renderers/text.rb', line 5

def initialize(opts)
  super
  self.content = opts[:content] || ''
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



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

def content
  @content
end

Instance Method Details

#escaped_contentObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/renderers/text.rb', line 21

def escaped_content
  if escape
    str = ERB::Util.h(content)
    if style == :pretty
      str = str.wrap(Garterbelt.wrap_length, :indent => indent)
    end
    str
  else
    content
  end
end

#line_endObject



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

def line_end
  style == :compact ? '' : super
end

#raise_with_block_contentObject

Raises:

  • (ArgumentError)


10
11
12
# File 'lib/renderers/text.rb', line 10

def raise_with_block_content
  raise ArgumentError, "#{self.class} does not take block content" if self.content.is_a?(Proc)
end

#renderObject



14
15
16
17
18
19
# File 'lib/renderers/text.rb', line 14

def render
  raise_with_block_content
  str = template
  output << str
  str
end

#templateObject



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

def template
  "#{escaped_content}#{line_end}"
end