Sha256: 6e7b57d940bb3af4d5ce1d27fa30736dc88fb433c1b0eb8f88eaf55a72b24d51

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

# Ruby interface to HTML Tidy Library Project (http://tidy.sf.net)
#
# = Usage
#
#   $TIDYLIB = '/usr/lib/tidylib.so'
#   require 'rubygems'
#   require_gem 'tidy'
#   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
#
module Tidy

  require 'dl/import'
  require 'dl/struct'
  require 'tidy/tidybuf'
  require 'tidy/tidyerr'
  require 'tidy/tidylib'
  require 'tidy/tidyobj'
  require 'tidy/tidyopt'

  module_function

  # Return a Tidyobj instance
  #
  def new(options=nil)
    Tidyobj.new(options)
  end
  
  # With no block, open is a synonym for Tidy.new .
  # If a block is present, it is passed aTidy as a parameter.
  # aTidyObj.release is ensured at end of the block
  #
  def open(options=nil)
    tidy = Tidy.new(options)
    if block_given?
      begin
        yield tidy
      ensure
        tidy.release
      end
    else
      tidy
    end
  end
  
  # Convert to boolean.
  # 0, false and nil return false, anything else true
  #
  def to_b(value)
    return false if [0,false,nil].include?(value)
    true
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tidy-1.0.1 lib/tidy.rb
tidy-1.0.0 lib/tidy.rb