tidy 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +8 -0
- data/README.txt.en +7 -6
- data/VERSION +1 -1
- data/install.rb +11 -0
- data/lib/tidy.rb +21 -11
- data/lib/tidy/tidybuf.rb +8 -8
- data/lib/tidy/tidyerr.rb +5 -5
- data/lib/tidy/tidylib.rb +10 -14
- data/lib/tidy/tidyobj.rb +19 -19
- data/lib/tidy/tidyopt.rb +5 -5
- data/test/usage.rb +3 -3
- data/tidy.gemspec +14 -8
- metadata +16 -10
data/CHANGES
CHANGED
data/README.txt.en
CHANGED
@@ -13,13 +13,14 @@ Requirements
|
|
13
13
|
Install
|
14
14
|
-------
|
15
15
|
|
16
|
-
- Download library from http://tidy.sf.net (pre-compiled versions available)
|
16
|
+
- Download library from http://tidy.sf.net (pre-compiled versions available).
|
17
17
|
|
18
|
-
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
- Install files using one of the following:
|
19
|
+
|
20
|
+
$ gem install tidy-x-x-x.gem
|
21
|
+
$ ruby install.rb
|
22
|
+
|
23
|
+
- Open test/usage.rb, change Tidy.path to point to your compiled Tidy library, run.
|
23
24
|
|
24
25
|
Usage
|
25
26
|
-----
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/install.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'ftools'
|
3
|
+
|
4
|
+
# Install lib
|
5
|
+
dst_dir = Config::CONFIG['sitelibdir']
|
6
|
+
Dir.chdir('lib') {
|
7
|
+
Dir['**/*'].reject { |f| f =~ /\.(cvs|gem|svn)($|\/)/i or not File.file?(f) }.each { |file|
|
8
|
+
File.mkpath File.join(dst_dir, File.dirname(file)), true
|
9
|
+
File.install file, File.join(dst_dir, file), 0644, true
|
10
|
+
}
|
11
|
+
}
|
data/lib/tidy.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
# Ruby interface to HTML Tidy Library Project (http://tidy.sf.net)
|
1
|
+
# Ruby interface to HTML Tidy Library Project (http://tidy.sf.net).
|
2
2
|
#
|
3
|
-
# =
|
3
|
+
# =Usage
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# require_gem 'tidy'
|
5
|
+
# require 'tidy'
|
6
|
+
# Tidy.path = '/usr/lib/tidylib.so'
|
8
7
|
# html = '<html><title>title</title>Body</html>'
|
9
8
|
# xml = Tidy.open(:show_warnings=>true) do |tidy|
|
10
9
|
# tidy.options.output_xml = true
|
@@ -31,17 +30,29 @@ module Tidy
|
|
31
30
|
|
32
31
|
module_function
|
33
32
|
|
34
|
-
# Return a Tidyobj instance
|
33
|
+
# Return a Tidyobj instance.
|
35
34
|
#
|
36
35
|
def new(options=nil)
|
37
36
|
Tidyobj.new(options)
|
38
37
|
end
|
39
38
|
|
40
|
-
#
|
39
|
+
# Path to Tidylib.
|
40
|
+
#
|
41
|
+
def path() @path end
|
42
|
+
|
43
|
+
# Set the path to Tidylib (automatically loads the library).
|
44
|
+
#
|
45
|
+
def path=(path)
|
46
|
+
Tidylib.load(path)
|
47
|
+
@path = path
|
48
|
+
end
|
49
|
+
|
50
|
+
# With no block, open is a synonym for Tidy.new.
|
41
51
|
# If a block is present, it is passed aTidy as a parameter.
|
42
|
-
# aTidyObj.release is ensured at end of the block
|
52
|
+
# aTidyObj.release is ensured at end of the block.
|
43
53
|
#
|
44
54
|
def open(options=nil)
|
55
|
+
raise "Tidy.path was not specified." unless @path
|
45
56
|
tidy = Tidy.new(options)
|
46
57
|
if block_given?
|
47
58
|
begin
|
@@ -55,11 +66,10 @@ module Tidy
|
|
55
66
|
end
|
56
67
|
|
57
68
|
# Convert to boolean.
|
58
|
-
# 0, false and nil return false, anything else true
|
69
|
+
# 0, false and nil return false, anything else true.
|
59
70
|
#
|
60
71
|
def to_b(value)
|
61
|
-
|
62
|
-
true
|
72
|
+
[0,false,nil].include?(value) ? false : true
|
63
73
|
end
|
64
74
|
|
65
75
|
end
|
data/lib/tidy/tidybuf.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
# Buffer structure
|
1
|
+
# Buffer structure.
|
2
2
|
#
|
3
3
|
class Tidybuf
|
4
4
|
|
5
5
|
extend DL::Importable
|
6
6
|
|
7
|
-
# Access TidyBuffer instance
|
7
|
+
# Access TidyBuffer instance.
|
8
8
|
#
|
9
9
|
attr_reader(:struct)
|
10
10
|
|
11
|
-
# Mimic TidyBuffer
|
11
|
+
# Mimic TidyBuffer.
|
12
12
|
#
|
13
13
|
TidyBuffer = struct [
|
14
14
|
"byte* bp",
|
@@ -17,23 +17,23 @@ class Tidybuf
|
|
17
17
|
"uint next"
|
18
18
|
]
|
19
19
|
|
20
|
-
def initialize
|
20
|
+
def initialize
|
21
21
|
@struct = TidyBuffer.malloc
|
22
22
|
end
|
23
23
|
|
24
|
-
# Free current contents and zero out
|
24
|
+
# Free current contents and zero out.
|
25
25
|
#
|
26
|
-
def free
|
26
|
+
def free
|
27
27
|
Tidylib.buf_free(@struct)
|
28
28
|
end
|
29
29
|
|
30
|
-
# Convert to array
|
30
|
+
# Convert to array.
|
31
31
|
#
|
32
32
|
def to_a
|
33
33
|
to_s.split("\r\n")
|
34
34
|
end
|
35
35
|
|
36
|
-
# Convert to string
|
36
|
+
# Convert to string.
|
37
37
|
#
|
38
38
|
def to_s
|
39
39
|
@struct.bp.to_s
|
data/lib/tidy/tidyerr.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
# Parameterized error message
|
1
|
+
# Parameterized error message.
|
2
2
|
#
|
3
3
|
class Tidyerr < String
|
4
4
|
|
5
|
-
# Error parameter
|
5
|
+
# Error parameter.
|
6
6
|
#
|
7
7
|
attr_reader :severity, :line, :column, :message
|
8
8
|
|
9
|
-
# Create new instance
|
9
|
+
# Create new instance.
|
10
10
|
#
|
11
11
|
def initialize(error)
|
12
12
|
super(error.to_s)
|
13
13
|
parameterize
|
14
14
|
end
|
15
15
|
|
16
|
-
# Parse error message into parameters (where applicable)
|
16
|
+
# Parse error message into parameters (where applicable).
|
17
17
|
#
|
18
|
-
def parameterize
|
18
|
+
def parameterize
|
19
19
|
if to_str[0,4] == 'line'
|
20
20
|
tokens = to_str.split(' ', 7)
|
21
21
|
@severity = tokens[5][0,1] # W or E
|
data/lib/tidy/tidylib.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Ruby wrapper for HTML Tidy Library Project (http://tidy.sf.net)
|
1
|
+
# Ruby wrapper for HTML Tidy Library Project (http://tidy.sf.net).
|
2
2
|
#
|
3
3
|
module Tidylib
|
4
4
|
|
@@ -6,14 +6,13 @@ module Tidylib
|
|
6
6
|
|
7
7
|
module_function
|
8
8
|
|
9
|
-
# Load library
|
9
|
+
# Load the library.
|
10
10
|
#
|
11
|
-
def load()
|
12
|
-
raise LoadError, 'Tidy requires that $TIDYLIB be defined' if $TIDYLIB.nil?
|
11
|
+
def load(path)
|
13
12
|
begin
|
14
|
-
dlload(
|
13
|
+
dlload(path)
|
15
14
|
rescue
|
16
|
-
raise LoadError,
|
15
|
+
raise LoadError, "Unable to load #{path}"
|
17
16
|
end
|
18
17
|
extern "void *tidyCreate()"
|
19
18
|
extern "void tidyBufFree(void*)"
|
@@ -38,8 +37,8 @@ module Tidylib
|
|
38
37
|
|
39
38
|
# tidyCreate
|
40
39
|
#
|
41
|
-
def create
|
42
|
-
tidyCreate
|
40
|
+
def create
|
41
|
+
tidyCreate
|
43
42
|
end
|
44
43
|
|
45
44
|
# tidyCleanAndRepair
|
@@ -81,8 +80,8 @@ module Tidylib
|
|
81
80
|
|
82
81
|
# tidyReleaseDate
|
83
82
|
#
|
84
|
-
def release_date
|
85
|
-
tidyReleaseDate
|
83
|
+
def release_date
|
84
|
+
tidyReleaseDate
|
86
85
|
end
|
87
86
|
|
88
87
|
# tidyRunDiagnostics
|
@@ -103,13 +102,10 @@ module Tidylib
|
|
103
102
|
tidySetErrorBuffer(doc, buf)
|
104
103
|
end
|
105
104
|
|
106
|
-
# Convert to string
|
107
|
-
# :output_xml becomes 'output-xml'
|
105
|
+
# Convert to string, replace underscores with dashes (:output_xml => 'output-xml').
|
108
106
|
#
|
109
107
|
def translate_name(name)
|
110
108
|
name.to_s.gsub('_', '-')
|
111
109
|
end
|
112
110
|
|
113
111
|
end
|
114
|
-
|
115
|
-
Tidylib.load
|
data/lib/tidy/tidyobj.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
# Ruby interface to Tidylib
|
1
|
+
# Ruby interface to Tidylib.
|
2
2
|
#
|
3
3
|
class Tidyobj
|
4
4
|
|
5
|
-
# Diagnostics Buffer (Array of String)
|
5
|
+
# Diagnostics Buffer (Array of String).
|
6
6
|
#
|
7
7
|
attr_reader(:diagnostics)
|
8
8
|
|
9
|
-
# Access the tidy instance
|
9
|
+
# Access the tidy instance.
|
10
10
|
#
|
11
11
|
attr_reader(:doc)
|
12
12
|
|
13
|
-
# Error Buffer (Array of Tidyerr)
|
13
|
+
# Error Buffer (Array of Tidyerr).
|
14
14
|
#
|
15
15
|
attr_reader(:errors)
|
16
16
|
|
17
|
-
# Options interface (Tidyopt)
|
17
|
+
# Options interface (Tidyopt).
|
18
18
|
#
|
19
19
|
attr_reader(:options)
|
20
20
|
|
21
21
|
# Construct a new instance.
|
22
|
-
# Receives a hash of options to be set
|
22
|
+
# Receives a hash of options to be set.
|
23
23
|
#
|
24
24
|
def initialize(options=nil)
|
25
25
|
@diagnostics = Array.new
|
@@ -35,13 +35,13 @@ class Tidyobj
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
# Clean and Repair
|
38
|
+
# Clean and Repair.
|
39
39
|
#
|
40
40
|
def clean(str)
|
41
41
|
verify_doc
|
42
42
|
rc = -1
|
43
43
|
|
44
|
-
# Clean and repair the string
|
44
|
+
# Clean and repair the string.
|
45
45
|
#
|
46
46
|
rc = Tidylib.parse_string(@doc, str) # Parse the input
|
47
47
|
rc = Tidylib.clean_and_repair(@doc) if rc >= 0 # Tidy it up!
|
@@ -49,14 +49,14 @@ class Tidyobj
|
|
49
49
|
rc = Tidylib.save_buffer(@doc, @outbuf.struct) if rc >= 0 # Pretty Print
|
50
50
|
verify_severe(rc)
|
51
51
|
|
52
|
-
# Save and clear output/errors
|
52
|
+
# Save and clear output/errors.
|
53
53
|
#
|
54
54
|
output = @outbuf.to_s
|
55
55
|
@errors = @errbuf.to_a.collect { |e| Tidyerr.new(e) }
|
56
56
|
@outbuf.free
|
57
57
|
@errbuf.free
|
58
58
|
|
59
|
-
# Save diagnostics
|
59
|
+
# Save diagnostics.
|
60
60
|
#
|
61
61
|
rc = Tidylib.run_diagnostics(@doc)
|
62
62
|
verify_severe(rc)
|
@@ -66,36 +66,36 @@ class Tidyobj
|
|
66
66
|
output
|
67
67
|
end
|
68
68
|
|
69
|
-
# Load a tidy config file
|
69
|
+
# Load a tidy config file.
|
70
70
|
#
|
71
71
|
def load_config(file)
|
72
72
|
verify_doc
|
73
73
|
rc = Tidylib.load_config(@doc, file)
|
74
74
|
case rc
|
75
|
-
when -1 then raise LoadError,
|
76
|
-
when 1 then raise LoadError,
|
75
|
+
when -1 then raise LoadError, "#{file} does not exist"
|
76
|
+
when 1 then raise LoadError, "errors parsing #{file}"
|
77
77
|
end
|
78
78
|
rc
|
79
79
|
end
|
80
80
|
|
81
|
-
# Clear the tidy instance
|
81
|
+
# Clear the tidy instance.
|
82
82
|
#
|
83
|
-
def release
|
83
|
+
def release
|
84
84
|
verify_doc
|
85
85
|
Tidylib.release(@doc)
|
86
86
|
@doc = nil
|
87
87
|
end
|
88
88
|
|
89
|
-
# Raise an error if the tidy document is invalid
|
89
|
+
# Raise an error if the tidy document is invalid.
|
90
90
|
#
|
91
|
-
def verify_doc
|
91
|
+
def verify_doc
|
92
92
|
raise TypeError, 'Invalid Tidy document' unless @doc.class == DL::PtrData
|
93
93
|
end
|
94
94
|
|
95
|
-
# Raise severe error based on tidy status value
|
95
|
+
# Raise severe error based on tidy status value.
|
96
96
|
#
|
97
97
|
def verify_severe(rc)
|
98
|
-
raise
|
98
|
+
raise "A severe error (#{rc}) occurred.\n" if rc < 0
|
99
99
|
end
|
100
100
|
|
101
101
|
protected :verify_doc, :verify_severe
|
data/lib/tidy/tidyopt.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
# Ruby interface to Tidylib options
|
1
|
+
# Ruby interface to Tidylib options.
|
2
2
|
#
|
3
3
|
class Tidyopt
|
4
4
|
|
5
|
-
# Construct a new instance
|
5
|
+
# Construct a new instance.
|
6
6
|
#
|
7
7
|
def initialize(doc)
|
8
8
|
@doc = doc
|
9
9
|
end
|
10
10
|
|
11
|
-
# Reader for options (Hash syntax)
|
11
|
+
# Reader for options (Hash syntax).
|
12
12
|
#
|
13
13
|
def [](name)
|
14
14
|
Tidylib.opt_get_value(@doc, name)
|
15
15
|
end
|
16
16
|
|
17
|
-
# Writer for options (Hash syntax)
|
17
|
+
# Writer for options (Hash syntax).
|
18
18
|
#
|
19
19
|
def []=(name, value)
|
20
20
|
Tidylib.opt_parse_value(@doc, name, value)
|
21
21
|
end
|
22
22
|
|
23
|
-
# Reader/Writer for options (Object syntax)
|
23
|
+
# Reader/Writer for options (Object syntax).
|
24
24
|
#
|
25
25
|
def method_missing(name, value=:none, *args)
|
26
26
|
name = name.to_s.gsub('=', '')
|
data/test/usage.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
$
|
2
|
-
require '
|
3
|
-
|
1
|
+
$LOAD_PATH.unshift('../lib')
|
2
|
+
require 'tidy'
|
3
|
+
Tidy.path = '/usr/lib/tidylib.so'
|
4
4
|
html = '<html><title>title</title>Body</html>'
|
5
5
|
xml = Tidy.open(:show_warnings=>true) do |tidy|
|
6
6
|
tidy.options.output_xml = true
|
data/tidy.gemspec
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
|
3
|
+
version = File.read('VERSION').strip
|
4
|
+
raise "no version" if version.empty?
|
5
|
+
|
2
6
|
spec = Gem::Specification.new do |s|
|
3
|
-
s.name =
|
4
|
-
s.version =
|
5
|
-
s.
|
6
|
-
s.
|
7
|
-
s.
|
7
|
+
s.name = 'tidy'
|
8
|
+
s.version = version
|
9
|
+
s.author = 'Kevin Howe'
|
10
|
+
s.email = 'kh@newclear.ca'
|
11
|
+
s.homepage = 'tidy.rubyforge.org'
|
12
|
+
s.platform = Gem::Platform::RUBY
|
13
|
+
s.summary = 'Ruby interface to HTML Tidy Library Project'
|
14
|
+
s.files = Dir['**/*'].delete_if { |f| f =~ /(cvs|gem|svn)$/i }
|
8
15
|
s.require_path = 'lib'
|
9
|
-
s.
|
16
|
+
s.rdoc_options << '--all' << '--inline-source' << '--main' << 'lib/tidy.rb'
|
10
17
|
s.has_rdoc = true
|
11
|
-
s.
|
12
|
-
s.homepage = "http://www.newclear.ca/ruby/tidy/"
|
18
|
+
s.rubyforge_project = 'tidy'
|
13
19
|
end
|
metadata
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.
|
2
|
+
rubygems_version: 0.8.3
|
3
3
|
specification_version: 1
|
4
4
|
name: tidy
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0
|
7
|
-
date: 2005-
|
6
|
+
version: 1.1.0
|
7
|
+
date: 2005-02-21
|
8
8
|
summary: Ruby interface to HTML Tidy Library Project
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
autorequire: tidy
|
11
|
+
email: kh@newclear.ca
|
12
|
+
homepage: tidy.rubyforge.org
|
13
|
+
rubyforge_project: tidy
|
14
|
+
description:
|
15
|
+
autorequire:
|
17
16
|
default_executable:
|
18
17
|
bindir: bin
|
19
18
|
has_rdoc: true
|
@@ -25,6 +24,8 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
25
24
|
version: 0.0.0
|
26
25
|
version:
|
27
26
|
platform: ruby
|
27
|
+
authors:
|
28
|
+
- Kevin Howe
|
28
29
|
files:
|
29
30
|
- test
|
30
31
|
- lib
|
@@ -33,6 +34,7 @@ files:
|
|
33
34
|
- CHANGES
|
34
35
|
- tidy.gemspec
|
35
36
|
- README.txt.en
|
37
|
+
- install.rb
|
36
38
|
- test/usage.rb
|
37
39
|
- lib/tidy
|
38
40
|
- lib/tidy.rb
|
@@ -42,7 +44,11 @@ files:
|
|
42
44
|
- lib/tidy/tidybuf.rb
|
43
45
|
- lib/tidy/tidyopt.rb
|
44
46
|
test_files: []
|
45
|
-
rdoc_options:
|
47
|
+
rdoc_options:
|
48
|
+
- "--all"
|
49
|
+
- "--inline-source"
|
50
|
+
- "--main"
|
51
|
+
- lib/tidy.rb
|
46
52
|
extra_rdoc_files: []
|
47
53
|
executables: []
|
48
54
|
extensions: []
|