Sha256: ae0349b97d48dbd00cb6e2f2c078810cc7386a1acf4c9851cdb9aa503a754fc8

Contents?: true

Size: 780 Bytes

Versions: 1

Compression:

Stored size: 780 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.0.9 lib/renderers/text.rb