Sha256: af8d3a9e1b6384b13eebb087001e7032a2a3fb59b0c86cc45816e7aaa8ac0c97

Contents?: true

Size: 781 Bytes

Versions: 1

Compression:

Stored size: 781 Bytes

Contents

module Garterbelt
  class Text < Renderer
    attr_accessor :content, :escape
    
    def initialize(opts)
      super
      self.content = opts[:content] || ''
      self.escape = view._escape
    end
    
    def raise_with_block_content
      raise ArgumentError, "#{self.class} does not take block content" if self.content.is_a?(Proc)
    end
    
    def render
      raise_with_block_content
      str = template
      output << str
      str
    end
    
    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
    
    def template
      "#{escaped_content}#{line_end}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
garterbelt-0.1.0 lib/renderers/text.rb