Sha256: 8dac232df28d7ccc7899c10a877e1b7de92c1c1550858b747114ca5d6bccf03c

Contents?: true

Size: 791 Bytes

Versions: 1

Compression:

Stored size: 791 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 line_end
      [:pretty, :text].include?(style) ? "\n" : ''
    end
    
    def template
      str = escape ? ERB::Util.h(content) : content
      
      if style == :pretty 
        "#{str.wrap(Garterbelt.wrap_length, :indent => indent)}#{line_end}" 
      else 
        "#{str}#{line_end}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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