Module: Tidylib

Extended by:
DL::Importable
Defined in:
lib/tidy/tidylib.rb

Overview

Ruby wrapper for HTML Tidy Library Project (tidy.sf.net).

Class Method Summary collapse

Class Method Details

.buf_free(buf) ⇒ Object

tidyBufFree



34
35
36
# File 'lib/tidy/tidylib.rb', line 34

def buf_free(buf)
  tidyBufFree(buf)
end

.clean_and_repair(doc) ⇒ Object

tidyCleanAndRepair



46
47
48
# File 'lib/tidy/tidylib.rb', line 46

def clean_and_repair(doc)
  tidyCleanAndRepair(doc)
end

.createObject

tidyCreate



40
41
42
# File 'lib/tidy/tidylib.rb', line 40

def create
  tidyCreate
end

.load(path) ⇒ Object

Load the library.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tidy/tidylib.rb', line 11

def load(path)
  begin
    dlload(path)
  rescue
    raise LoadError, "Unable to load #{path}"
  end
  extern "void *tidyCreate()"
  extern "void tidyBufFree(void*)"
  extern "int tidyCleanAndRepair(void*)"
  extern "int tidyLoadConfig(void*, char*)"
  extern "int tidyOptGetIdForName(char*)"
  extern "char tidyOptGetValue(void*, unsigned int)"
  extern "int tidyOptParseValue(void*, char*, char*)"
  extern "int tidyParseString(void*, char*)"
  extern "void tidyRelease(void*)"
  extern "char* tidyReleaseDate()"
  extern "int tidyRunDiagnostics(void*)"
  extern "int tidySaveBuffer(void*, void*)"
  extern "int tidySetErrorBuffer(void*, void*)"
end

.load_config(doc, file) ⇒ Object

tidyLoadConfig



52
53
54
# File 'lib/tidy/tidylib.rb', line 52

def load_config(doc, file)
  tidyLoadConfig(doc, file.to_s)
end

.opt_get_value(doc, name) ⇒ Object

tidyOptGetValue (returns true/false instead of 1/0)



64
65
66
67
# File 'lib/tidy/tidylib.rb', line 64

def opt_get_value(doc, name)
  value = tidyOptGetValue(doc, tidyOptGetIdForName(translate_name(name)))
  Tidy.to_b(value)
end

.opt_parse_value(doc, name, value) ⇒ Object

tidyOptParseValue



58
59
60
# File 'lib/tidy/tidylib.rb', line 58

def opt_parse_value(doc, name, value)
  tidyOptParseValue(doc, translate_name(name), value.to_s)
end

.parse_string(doc, str) ⇒ Object

tidyParseString



71
72
73
# File 'lib/tidy/tidylib.rb', line 71

def parse_string(doc, str)
  tidyParseString(doc, str.to_s)
end

.release(doc) ⇒ Object

tidyRelease



77
78
79
# File 'lib/tidy/tidylib.rb', line 77

def release(doc)
  tidyRelease(doc)
end

.release_dateObject

tidyReleaseDate



83
84
85
# File 'lib/tidy/tidylib.rb', line 83

def release_date
  tidyReleaseDate
end

.run_diagnostics(doc) ⇒ Object

tidyRunDiagnostics



89
90
91
# File 'lib/tidy/tidylib.rb', line 89

def run_diagnostics(doc)
  tidyRunDiagnostics(doc)
end

.save_buffer(doc, buf) ⇒ Object

tidySaveBuffer



95
96
97
# File 'lib/tidy/tidylib.rb', line 95

def save_buffer(doc, buf)
  tidySaveBuffer(doc, buf)
end

.set_error_buffer(doc, buf) ⇒ Object

tidySetErrorBuffer



101
102
103
# File 'lib/tidy/tidylib.rb', line 101

def set_error_buffer(doc, buf)
  tidySetErrorBuffer(doc, buf)
end

.translate_name(name) ⇒ Object

Convert to string, replace underscores with dashes (:output_xml => ‘output-xml’).



107
108
109
# File 'lib/tidy/tidylib.rb', line 107

def translate_name(name)
  name.to_s.gsub('_', '-')
end