module Tidy
Ruby interface to HTML Tidy Library Project (tidy.sf.net).
Usage¶ ↑
require 'tidy' Tidy.path = '/usr/lib/tidylib.so' html = '<html><title>title</title>Body</html>' xml = Tidy.open(:show_warnings=>true) do |tidy| tidy.options.output_xml = true puts tidy.options.show_warnings xml = tidy.clean(html) puts tidy.errors puts tidy.diagnostics xml end puts xml
- Author
-
Kevin Howe
- License
-
Distributes under the same terms as Ruby
Public Instance Methods
new(options=nil)
click to toggle source
Return a Tidyobj instance.
# File lib/tidy.rb, line 35 def new(options=nil) Tidyobj.new(options) end
open(options=nil) { |tidy| ... }
click to toggle source
With no block, open is a synonym for #new. If a block is present, it is passed aTidy as a parameter. aTidyObj.release is ensured at end of the block.
# File lib/tidy.rb, line 54 def open(options=nil) raise "Tidy.path was not specified." unless @path tidy = Tidy.new(options) if block_given? begin yield tidy ensure tidy.release end else tidy end end
path()
click to toggle source
Path to Tidylib.
# File lib/tidy.rb, line 41 def path() @path end
path=(path)
click to toggle source
Set the path to Tidylib (automatically loads the library).
# File lib/tidy.rb, line 45 def path=(path) Tidylib.load(path) @path = path end
to_b(value)
click to toggle source
Convert to boolean. 0, false and nil return false, anything else true.
# File lib/tidy.rb, line 71 def to_b(value) [0,false,nil].include?(value) ? false : true end