Parent

Class/Module Index [+]

Quicksearch

Tidyobj

Ruby interface to Tidylib.

Attributes

diagnostics[R]

Diagnostics Buffer (Array of String).

doc[R]

Access the tidy instance.

errors[R]

Error Buffer (Array of Tidyerr).

options[R]

Options interface (Tidyopt).

Public Class Methods

new(options=nil) click to toggle source

Construct a new instance. Receives a hash of options to be set.

# File lib/tidy/tidyobj.rb, line 24
def initialize(options=nil)
  @diagnostics = Array.new
  @doc = Tidylib.create
  @errors = Array.new
  @errbuf = Tidybuf.new
  @outbuf = Tidybuf.new
  @options = Tidyopt.new(@doc)
  rc = Tidylib.set_error_buffer(@doc, @errbuf.struct)
  verify_severe(rc)
  unless options.nil?
    options.each { |name, value| Tidylib.opt_parse_value(@doc, name, value) }
  end
end

Public Instance Methods

clean(str) click to toggle source

Clean and Repair.

# File lib/tidy/tidyobj.rb, line 40
def clean(str)
  verify_doc
  rc = -1

  # Clean and repair the string.

  #

  rc = Tidylib.parse_string(@doc, str)                                               # Parse the input

  rc = Tidylib.clean_and_repair(@doc) if rc >= 0                                     # Tidy it up!

  rc = (Tidylib.opt_parse_value(@doc, :force_output, true) == 1 ? rc : -1) if rc > 1 # If error, force output

  rc = Tidylib.save_buffer(@doc, @outbuf.struct) if rc >= 0                          # Pretty Print

  verify_severe(rc)

  # Save and clear output/errors.

  #

  output = @outbuf.to_s
  @errors = @errbuf.to_a.collect { |e| Tidyerr.new(e) }
  @outbuf.free
  @errbuf.free
  
  # Save diagnostics.

  #

  rc = Tidylib.run_diagnostics(@doc)
  verify_severe(rc)
  @diagnostics = @errbuf.to_a
  @errbuf.free

  output
end
load_config(file) click to toggle source

Load a tidy config file.

# File lib/tidy/tidyobj.rb, line 71
def load_config(file)
  verify_doc
  rc = Tidylib.load_config(@doc, file)
  case rc
    when -1 then raise LoadError, "#{file} does not exist"
    when  1 then raise LoadError, "errors parsing #{file}"
  end
  rc
end
release() click to toggle source

Clear the tidy instance.

# File lib/tidy/tidyobj.rb, line 83
def release
  verify_doc
  Tidylib.release(@doc)
  @doc = nil
end

Protected Instance Methods

verify_doc() click to toggle source

Raise an error if the tidy document is invalid.

# File lib/tidy/tidyobj.rb, line 91
def verify_doc
  raise TypeError, 'Invalid Tidy document' unless @doc.class == DL::PtrData
end
verify_severe(rc) click to toggle source

Raise severe error based on tidy status value.

# File lib/tidy/tidyobj.rb, line 97
def verify_severe(rc)
  raise "A severe error (#{rc}) occurred.\n" if rc < 0
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.