lib/renderers/text.rb in garterbelt-0.0.7 vs lib/renderers/text.rb in garterbelt-0.0.8

- old
+ new

@@ -2,24 +2,35 @@ class Text < Renderer attr_accessor :content, :escape def initialize(opts) super - raise ArgumentError, ":content option required for #{self.class} initialization" unless opts[:content] - self.content = opts[:content] + 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 - output << "#{indent}#{escaped_content}\n" + str = template + output << str + str end - def escaped_content - escape ? ERB::Util.h(content) : content + 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