Class: Tidyobj
- Inherits:
-
Object
- Object
- Tidyobj
- Defined in:
- lib/tidy/tidyobj.rb
Overview
Ruby interface to Tidylib.
Instance Attribute Summary collapse
-
#diagnostics ⇒ Object
readonly
Diagnostics Buffer (Array of String).
-
#doc ⇒ Object
readonly
Access the tidy instance.
-
#errors ⇒ Object
readonly
Error Buffer (Array of Tidyerr).
-
#options ⇒ Object
readonly
Options interface (Tidyopt).
Instance Method Summary collapse
-
#clean(str) ⇒ Object
Clean and Repair.
-
#initialize(options = nil) ⇒ Tidyobj
constructor
Construct a new instance.
-
#load_config(file) ⇒ Object
Load a tidy config file.
-
#release ⇒ Object
Clear the tidy instance.
Constructor Details
#initialize(options = nil) ⇒ Tidyobj
Construct a new instance. Receives a hash of options to be set.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tidy/tidyobj.rb', line 24 def initialize(=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 .nil? .each { |name, value| Tidylib.opt_parse_value(@doc, name, value) } end end |
Instance Attribute Details
#diagnostics ⇒ Object (readonly)
Diagnostics Buffer (Array of String).
7 8 9 |
# File 'lib/tidy/tidyobj.rb', line 7 def diagnostics @diagnostics end |
#doc ⇒ Object (readonly)
Access the tidy instance.
11 12 13 |
# File 'lib/tidy/tidyobj.rb', line 11 def doc @doc end |
#errors ⇒ Object (readonly)
Error Buffer (Array of Tidyerr).
15 16 17 |
# File 'lib/tidy/tidyobj.rb', line 15 def errors @errors end |
#options ⇒ Object (readonly)
Options interface (Tidyopt).
19 20 21 |
# File 'lib/tidy/tidyobj.rb', line 19 def @options end |
Instance Method Details
#clean(str) ⇒ Object
Clean and Repair.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# 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) ⇒ Object
Load a tidy config file.
71 72 73 74 75 76 77 78 79 |
# 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 |