class Temple::HTML::Pretty

def compile(exp)

def compile(exp)
  [:multi, preamble, compile!(exp)]
end

def indent

Return indentation if not in pre tag
def indent
  "\n" + (options[:indent] || '') * @indent
end

def initialize(opts = {})

def initialize(opts = {})
  super
  @last = nil
  @indent = 0
  @pretty = options[:pretty]
end

def on_dynamic(content)

def on_dynamic(content)
  @last = nil
  [:dynamic, @pretty ? "Temple::Utils.indent((#{content}), #{indent.inspect}, _temple_pre_tags)" : content]
end

def on_html_comment(content)

def on_html_comment(content)
  return super unless @pretty
  [:multi, [:static, indent], super]
end

def on_html_doctype(type)

def on_html_doctype(type)
  @last = 'doctype'
  super
end

def on_html_tag(name, attrs, closed, content)

def on_html_tag(name, attrs, closed, content)
  return super unless @pretty
  closed ||= options[:autoclose].include?(name)
  raise "Closed tag #{name} has content" if closed && !empty_exp?(content)
  @pretty = false
  result = [:multi, [:static, "#{tag_indent(name)}<#{name}"], compile!(attrs)]
  result << [:static, ' /'] if closed && xhtml?
  result << [:static, '>']
  @last = name
  @pretty = !options[:pre_tags].include?(name)
  @indent += 1
  result << compile!(content)
  @indent -= 1
  result << [:static, "#{tag_indent(name)}</#{name}>"] if !closed
  @last = name
  @pretty = true
  result
end

def on_static(content)

def on_static(content)
  @last = nil
  [:static, @pretty ? content.gsub("\n", indent) : content]
end

def preamble

def preamble
  regexp = options[:pre_tags].map {|t| "<#{t}" }.join('|')
  [:block, "_temple_pre_tags = /#{regexp}/"]
end

def tag_indent(name)

Return indentation before tag
def tag_indent(name)
  @last && (options[:indent_tags].include?(@last) || options[:indent_tags].include?(name)) ? indent : ''
end