class Rote::Filters::Tidy
Post filter that runs HTML Tidy
on the laid-out page to correct and clean up HTML in the output. This filter can be used with any of the asXXXX formats supported by Tidy
.
Note that this filter requires the 'tidy' command, and should be added to the post_filters
array, in contrast to most of the other filters which are page filters.
If 'tidy' isn't in your path you'll need to specify it here or via a TIDYCMD environment variable.
Attributes
format[RW]
tidycmd[RW]
tidyopts[RW]
Public Class Methods
new(format = :xhtml, tidycmd = nil, tidyopts = '-q')
click to toggle source
Create a new filter instance, using the specified output format, and optionally a custom 'tidy' command and options.
# File lib/rote/filters/tidy.rb 27 def initialize(format = :xhtml, tidycmd = nil, tidyopts = '-q') 28 @tidycmd = tidycmd || ENV['TIDYCMD'] || (RUBY_PLATFORM =~ /mswin/ ? 'tidy.exe' : 'tidy') 29 # TODO windows 'tidy.exe' correct? 30 31 @tidyopts = tidyopts 32 @format = format 33 end
Public Instance Methods
filter(text, page)
click to toggle source
# File lib/rote/filters/tidy.rb 37 def filter(text, page) 38 # TODO need to properly capture and log warnings here 39 result = IO.popen("#{@tidycmd} #{self.tidyopts} -f tidy.log -as#{self.format}","r+") do |fp| 40 Thread.new { fp.write(text); fp.close_write } 41 fp.read 42 end 43 44 if $?.exitstatus < 2 45 result 46 else 47 warn 'Tidy command failed (exitstatus: $?)' 48 text 49 end 50 end