tidy-ext 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +14 -5
- data/VERSION +1 -1
- data/ext/tidy/extconf.rb +5 -0
- data/ext/tidy/ruby-tidy.c +64 -9
- data/spec/tidy/compat_spec.rb +28 -4
- metadata +4 -4
data/Rakefile
CHANGED
@@ -2,10 +2,6 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'rake/extensiontask'
|
4
4
|
|
5
|
-
#require File.join(File.expand_path(File.dirname(__FILE__)), "lib")
|
6
|
-
|
7
|
-
MAKE = 'make'
|
8
|
-
|
9
5
|
begin
|
10
6
|
require 'jeweler'
|
11
7
|
Jeweler::Tasks.new do |gem|
|
@@ -53,6 +49,19 @@ Rake::RDocTask.new do |rdoc|
|
|
53
49
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
50
|
end
|
55
51
|
|
56
|
-
Rake::ExtensionTask.new
|
52
|
+
Rake::ExtensionTask.new do |ext|
|
53
|
+
ext.name = 'tidy'
|
54
|
+
ext.ext_dir = 'ext/tidy'
|
55
|
+
ext.config_options << '--with-coverage' if ENV['COV']
|
56
|
+
end
|
57
57
|
|
58
|
+
desc "Recompile with gcc coverage options and run specs"
|
59
|
+
task :gcov => [:clean] do |t|
|
60
|
+
ENV['COV'] = '1'
|
61
|
+
Rake::Task[:compile].invoke
|
62
|
+
Rake::Task[:spec].invoke
|
63
|
+
|
64
|
+
ruby_tidy_o = Dir.glob('**/ruby-tidy.o').first
|
65
|
+
puts %x{gcov --no-output --object-file #{ruby_tidy_o} ext/tidy/ruby-tidy.c}
|
66
|
+
end
|
58
67
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.9
|
data/ext/tidy/extconf.rb
CHANGED
data/ext/tidy/ruby-tidy.c
CHANGED
@@ -55,6 +55,61 @@ static VALUE rb_tidy_new(int argc, VALUE *argv, VALUE class)
|
|
55
55
|
return self;
|
56
56
|
}
|
57
57
|
|
58
|
+
/* called when iterating over options hash */
|
59
|
+
static VALUE rb_tidy_set_option(VALUE arg1, VALUE arg2)
|
60
|
+
{
|
61
|
+
VALUE key, value;
|
62
|
+
TidyDoc tdoc;
|
63
|
+
TidyOption opt;
|
64
|
+
Bool status = no;
|
65
|
+
|
66
|
+
/* See platform.h, opaque_type for typedef convention */
|
67
|
+
Data_Get_Struct(arg2, struct _TidyDoc, tdoc);
|
68
|
+
|
69
|
+
key = rb_ary_entry(arg1, 0);
|
70
|
+
value = rb_ary_entry(arg1, 1);
|
71
|
+
|
72
|
+
/* if the key is a symbol, convert it to a string
|
73
|
+
* and replace the underscores '_' with minuses '-'
|
74
|
+
*/
|
75
|
+
if (TYPE(key) == T_SYMBOL) {
|
76
|
+
char *ckey, *ptr;
|
77
|
+
|
78
|
+
ckey = (char *) rb_id2name(SYM2ID(key));
|
79
|
+
|
80
|
+
for(ptr = ckey; *ptr != '\0'; ptr++) {
|
81
|
+
if (*ptr == '_') {
|
82
|
+
*ptr = '-';
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
opt = tidyGetOptionByName(tdoc, ckey);
|
87
|
+
} else {
|
88
|
+
opt = tidyGetOptionByName(tdoc, StringValuePtr(key));
|
89
|
+
}
|
90
|
+
|
91
|
+
if ( opt != NULL ) {
|
92
|
+
TidyOptionId optId = tidyOptGetId(opt);
|
93
|
+
|
94
|
+
switch(TYPE(value)) {
|
95
|
+
case T_FALSE:
|
96
|
+
status = tidyOptSetBool(tdoc, optId, no);
|
97
|
+
break;
|
98
|
+
case T_TRUE:
|
99
|
+
status = tidyOptSetBool(tdoc, optId, yes);
|
100
|
+
break;
|
101
|
+
case T_FIXNUM:
|
102
|
+
status = tidyOptSetInt(tdoc, optId, NUM2ULONG(value));
|
103
|
+
break;
|
104
|
+
default:
|
105
|
+
status = tidyOptSetValue(tdoc, optId, StringValuePtr(value));
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
return Qnil;
|
111
|
+
}
|
112
|
+
|
58
113
|
/* parse the given input and return the tidy errors and output */
|
59
114
|
static VALUE rb_tidy_parse(VALUE self, VALUE input)
|
60
115
|
{
|
@@ -82,10 +137,8 @@ static VALUE rb_tidy_parse(VALUE self, VALUE input)
|
|
82
137
|
|
83
138
|
status = tidySetErrorBuffer( tdoc, &errbuf );
|
84
139
|
|
85
|
-
access = rb_iv_get(self, "@access");
|
86
|
-
tidyOptSetInt( tdoc, TidyAccessibilityCheckLevel, NUM2UINT(access));
|
87
|
-
|
88
140
|
options = rb_iv_get(self, "@options");
|
141
|
+
rb_iterate(rb_each, options, rb_tidy_set_option, self);
|
89
142
|
|
90
143
|
if (status >= 0) {
|
91
144
|
|
@@ -122,13 +175,11 @@ static VALUE rb_tidy_parse(VALUE self, VALUE input)
|
|
122
175
|
if (status >= 0)
|
123
176
|
status = tidySaveBuffer( tdoc, &output );
|
124
177
|
|
125
|
-
contentErrors
|
126
|
-
contentWarnings
|
127
|
-
accessWarnings
|
128
|
-
|
129
|
-
VALUE show_warnings = rb_hash_aref(options, ID2SYM(rb_intern("show_warnings")));
|
178
|
+
contentErrors = tidyErrorCount( tdoc );
|
179
|
+
contentWarnings = tidyWarningCount( tdoc );
|
180
|
+
accessWarnings = tidyAccessWarningCount( tdoc );
|
130
181
|
|
131
|
-
if (contentErrors > 0 ||
|
182
|
+
if (contentErrors > 0 || contentWarnings > 0) {
|
132
183
|
errors = rb_str_new2(errbuf.bp);
|
133
184
|
} else {
|
134
185
|
errors = rb_str_new2("");
|
@@ -150,6 +201,7 @@ static VALUE rb_tidy_init(VALUE self)
|
|
150
201
|
return self;
|
151
202
|
}
|
152
203
|
|
204
|
+
/* Create a tidy object */
|
153
205
|
static VALUE rb_tidy_open(VALUE class, VALUE options)
|
154
206
|
{
|
155
207
|
VALUE args[1];
|
@@ -165,6 +217,7 @@ static VALUE rb_tidy_open(VALUE class, VALUE options)
|
|
165
217
|
return tidy;
|
166
218
|
}
|
167
219
|
|
220
|
+
/* Given a string, returns the string after tidying */
|
168
221
|
static VALUE rb_tidy_clean(VALUE self, VALUE input)
|
169
222
|
{
|
170
223
|
VALUE array;
|
@@ -174,6 +227,7 @@ static VALUE rb_tidy_clean(VALUE self, VALUE input)
|
|
174
227
|
return rb_ary_entry(array, 1);
|
175
228
|
}
|
176
229
|
|
230
|
+
/* For sideways compatibility */
|
177
231
|
static VALUE rb_tidy_path_get(VALUE self)
|
178
232
|
{
|
179
233
|
VALUE path;
|
@@ -181,6 +235,7 @@ static VALUE rb_tidy_path_get(VALUE self)
|
|
181
235
|
return path;
|
182
236
|
}
|
183
237
|
|
238
|
+
/* For sideways compatibility */
|
184
239
|
static VALUE rb_tidy_path_set(VALUE self, VALUE path)
|
185
240
|
{
|
186
241
|
rb_cv_set(self, "@@path", path);
|
data/spec/tidy/compat_spec.rb
CHANGED
@@ -48,18 +48,42 @@ describe "tidy compatibility methods" do
|
|
48
48
|
errors1 = nil
|
49
49
|
errors2 = nil
|
50
50
|
|
51
|
-
tidy = Tidy.open({
|
51
|
+
tidy = Tidy.open({'show-warnings' => false}) do |tidy|
|
52
52
|
html = tidy.clean("<html><body>String</body></html>")
|
53
53
|
errors1 = tidy.errors
|
54
|
-
puts errors1
|
55
54
|
end
|
56
55
|
|
57
|
-
tidy = Tidy.open({
|
56
|
+
tidy = Tidy.open({'show-warnings' => true}) do |tidy|
|
58
57
|
html = tidy.clean("<html><body>String</body></html>")
|
59
58
|
errors2 = tidy.errors
|
60
|
-
puts errors2
|
61
59
|
end
|
62
60
|
|
63
61
|
errors1.should_not == errors2
|
64
62
|
end
|
63
|
+
|
64
|
+
it "should observe the options hash when it uses strings" do
|
65
|
+
laundry = "<html><body>String<img src=''/></body></html>"
|
66
|
+
options = {
|
67
|
+
'alt-text' => 'hello world',
|
68
|
+
'uppercase-tags' => true
|
69
|
+
}
|
70
|
+
tidy = Tidy.open(options) do |tidy|
|
71
|
+
clean = tidy.clean(laundry)
|
72
|
+
clean.should =~ /<HTML>/
|
73
|
+
clean.should =~ /alt="hello world"/
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should observe the options hash when it uses symbols" do
|
78
|
+
laundry = "<html><body>String<img src=''/></body></html>"
|
79
|
+
options = {
|
80
|
+
:alt_text => 'hello world',
|
81
|
+
:uppercase_tags => true
|
82
|
+
}
|
83
|
+
tidy = Tidy.open(options) do |tidy|
|
84
|
+
clean = tidy.clean(laundry)
|
85
|
+
clean.should =~ /<HTML>/
|
86
|
+
clean.should =~ /alt="hello world"/
|
87
|
+
end
|
88
|
+
end
|
65
89
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tidy-ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 9
|
10
|
+
version: 0.1.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Carl Douglas
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-07-23 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|