Parent

Methods

Webby::Filters::Tidy

The Tidy filter is used to process HTML (or XHTML) through the tidy program and outpu nicely formatted and correct HTML (or XHTML).

Options can be passed to the tidy program via the Webby.site struct. Setting the tidy_options to the string of desired options will do the trick.

From a project's Rakefile, include the following line (or one that's more to your liking):

SITE.tidy_options = "-indent -wrap 80 -utf8"

Public Class Methods

new( html ) click to toggle source

Create a new filter that will process the given html through the tidy program.

# File lib/webby/filters/tidy.rb, line 32
def initialize( str )
  @log = ::Logging::Logger[self]
  @str = str

  # create a temporary file for holding any error messages
  # from the tidy program
  @err = Tempfile.new('tidy_err')
  @err.close
end

Public Instance Methods

process => formatted html click to toggle source

Process the original HTML text string passed to the filter when it was created and output Tidy formatted HTML or XHTML.

# File lib/webby/filters/tidy.rb, line 48
def process
  cmd = "tidy %s -q -f #{@err.path}" % ::Webby.site.tidy_options
  out = IO.popen(cmd, 'r+') do |tidy|
    tidy.write @str
    tidy.close_write
    tidy.read
  end

  if File.size(@err.path) != 0
    @log.warn File.read(@err.path).strip
  end

  return out
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.