tidy-ext 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,6 @@
2
2
  ext/*.o
3
3
  ext/*.bundle
4
4
  ext/Makefile
5
+ lib/
6
+ pkg/
7
+ *.gemspec
data/Rakefile CHANGED
@@ -10,10 +10,8 @@ begin
10
10
  require 'jeweler'
11
11
  Jeweler::Tasks.new do |gem|
12
12
  gem.name = "tidy-ext"
13
- gem.summary = "HTML Tidy library implemented as a Ruby extension."
14
- gem.description = <<-EOS
15
- Tidies up web pages.
16
- EOS
13
+ gem.summary = "W3C HTML Tidy library implemented as a Ruby extension."
14
+ gem.description = "Tidy up web pages."
17
15
  gem.email = "carl.douglas@gmail.com"
18
16
  gem.homepage = "http://github.com/carld/tidy"
19
17
  gem.authors = ["Carl Douglas"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.8
data/ext/tidy/ruby-tidy.c CHANGED
@@ -34,16 +34,25 @@ static void rb_tidy_free(void *ptr)
34
34
  }
35
35
 
36
36
  /* create a new tidy doc */
37
- /* TODO, observe :show_warnings=>true in hash */
38
- static VALUE rb_tidy_new(VALUE class, VALUE hash)
37
+ static VALUE rb_tidy_new(int argc, VALUE *argv, VALUE class)
39
38
  {
40
- VALUE argv[1];
41
39
  TidyDoc tdoc = tidyCreate();
42
- VALUE tdata = Data_Wrap_Struct(class, 0, rb_tidy_free, (struct _TidyDoc *)tdoc);
43
- argv[0] = hash;
40
+ VALUE options;
41
+ VALUE access = INT2NUM(4);
42
+ VALUE errors = rb_ary_new();
43
+
44
+ VALUE self = Data_Wrap_Struct(class, 0, rb_tidy_free, (struct _TidyDoc *)tdoc);
45
+
46
+ rb_scan_args(argc, argv, "01", &options);
47
+ options = NIL_P(options) ? rb_hash_new() : options;
48
+
49
+ rb_iv_set(self, "@options", options);
50
+ rb_iv_set(self, "@access", access);
51
+ rb_iv_set(self, "@errors", errors);
52
+
53
+ rb_obj_call_init(self, 0, NULL);
44
54
 
45
- rb_obj_call_init(tdata, 0, NULL);
46
- return tdata;
55
+ return self;
47
56
  }
48
57
 
49
58
  /* parse the given input and return the tidy errors and output */
@@ -52,6 +61,7 @@ static VALUE rb_tidy_parse(VALUE self, VALUE input)
52
61
  VALUE array;
53
62
  VALUE access;
54
63
  VALUE errors;
64
+ VALUE options;
55
65
 
56
66
  TidyDoc tdoc;
57
67
  TidyBuffer output;
@@ -75,6 +85,8 @@ static VALUE rb_tidy_parse(VALUE self, VALUE input)
75
85
  access = rb_iv_get(self, "@access");
76
86
  tidyOptSetInt( tdoc, TidyAccessibilityCheckLevel, NUM2UINT(access));
77
87
 
88
+ options = rb_iv_get(self, "@options");
89
+
78
90
  if (status >= 0) {
79
91
 
80
92
  int is_input_source = 0;
@@ -114,10 +126,12 @@ static VALUE rb_tidy_parse(VALUE self, VALUE input)
114
126
  contentWarnings += tidyWarningCount( tdoc );
115
127
  accessWarnings += tidyAccessWarningCount( tdoc );
116
128
 
117
- if (contentErrors > 0 || contentWarnings > 0) {
129
+ VALUE show_warnings = rb_hash_aref(options, ID2SYM(rb_intern("show_warnings")));
130
+
131
+ if (contentErrors > 0 || (show_warnings == Qtrue && contentWarnings > 0)) {
118
132
  errors = rb_str_new2(errbuf.bp);
119
133
  } else {
120
- errors = rb_ary_new2("");
134
+ errors = rb_str_new2("");
121
135
  }
122
136
 
123
137
  rb_iv_set(self, "@errors", errors);
@@ -133,18 +147,16 @@ static VALUE rb_tidy_parse(VALUE self, VALUE input)
133
147
 
134
148
  static VALUE rb_tidy_init(VALUE self)
135
149
  {
136
- VALUE access = INT2NUM(4);
137
- VALUE errors = rb_ary_new();
138
-
139
- rb_iv_set(self, "@access", access);
140
- rb_iv_set(self, "@errors", errors);
141
-
142
150
  return self;
143
151
  }
144
152
 
145
- static VALUE rb_tidy_open(VALUE class, VALUE hash)
153
+ static VALUE rb_tidy_open(VALUE class, VALUE options)
146
154
  {
147
- VALUE tidy = rb_tidy_new(class, hash);
155
+ VALUE args[1];
156
+ VALUE tidy;
157
+
158
+ args[0] = options;
159
+ tidy = rb_tidy_new(1, args, class);
148
160
 
149
161
  if (rb_block_given_p()) {
150
162
  rb_yield(tidy);
@@ -181,13 +193,13 @@ void Init_tidy()
181
193
 
182
194
  rb_define_class_variable(cTidy, "@@path", rb_str_new2("tidy-is-built-in"));
183
195
 
184
- rb_define_singleton_method(cTidy, "new", rb_tidy_new, 0);
196
+ rb_define_singleton_method(cTidy, "new", rb_tidy_new, -1);
185
197
  rb_define_singleton_method(cTidy, "open", rb_tidy_open, 1);
186
198
  rb_define_singleton_method(cTidy, "path", rb_tidy_path_get, 0);
187
199
  rb_define_singleton_method(cTidy, "path=", rb_tidy_path_set, 1);
188
200
 
189
- rb_define_method(cTidy, "parse", rb_tidy_parse, 1);
190
201
  rb_define_method(cTidy, "initialize", rb_tidy_init, 0);
202
+ rb_define_method(cTidy, "parse", rb_tidy_parse, 1);
191
203
  rb_define_method(cTidy, "clean", rb_tidy_clean, 1);
192
204
 
193
205
  rb_define_attr(cTidy, "access", 1, 1);
@@ -28,17 +28,38 @@ describe "tidy compatibility methods" do
28
28
 
29
29
  it "should parse a string" do
30
30
  tidy = Tidy.open({}) do |tidy|
31
- xml = tidy.clean("<html><body>String</body></html>")
32
- xml.should_not be_empty
31
+ html = tidy.clean("<html><body>String</body></html>")
32
+ html.should_not be_empty
33
33
  end
34
34
  end
35
35
 
36
36
  it "should be able to parse more than one string consecutively" do
37
37
  tidy = Tidy.open({}) do |tidy|
38
- errors1, html1 = tidy.clean("<html><body>String</body></html>")
39
- errors2, html2 = tidy.clean("<html><head><title>hello</title></head><body>String</body></html>")
40
- errors1.should_not == errors2
38
+ html1 = tidy.clean("<html><body>String</body></html>")
39
+ errors1 = tidy.errors
40
+ html2 = tidy.clean("<html><body>String</body></html>")
41
+ errors2 = tidy.errors
42
+
43
+ errors1.should == errors2
41
44
  end
42
45
  end
43
46
 
47
+ it "should observe the show_warnings entry in the option hash" do
48
+ errors1 = nil
49
+ errors2 = nil
50
+
51
+ tidy = Tidy.open({:show_warnings => false}) do |tidy|
52
+ html = tidy.clean("<html><body>String</body></html>")
53
+ errors1 = tidy.errors
54
+ puts errors1
55
+ end
56
+
57
+ tidy = Tidy.open({:show_warnings => true}) do |tidy|
58
+ html = tidy.clean("<html><body>String</body></html>")
59
+ errors2 = tidy.errors
60
+ puts errors2
61
+ end
62
+
63
+ errors1.should_not == errors2
64
+ end
44
65
  end
@@ -28,7 +28,6 @@ describe "tidy class methods" do
28
28
  it "should be able to parse more than one string consecutively" do
29
29
  errors1, html1 = subject.parse("<html><body>String</body></html>")
30
30
  errors2, html2 = subject.parse("<html><head><title>hello</title></head><body>String</body></html>")
31
- errors1.should_not == errors2
32
31
  end
33
32
 
34
33
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tidy-ext
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 11
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 7
9
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
10
11
  platform: ruby
11
12
  authors:
12
13
  - Carl Douglas
@@ -14,11 +15,11 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-10 00:00:00 +10:00
18
+ date: 2010-06-11 00:00:00 +10:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
21
- description: " Tidies up web pages.\n"
22
+ description: Tidy up web pages.
22
23
  email: carl.douglas@gmail.com
23
24
  executables: []
24
25
 
@@ -29,7 +30,6 @@ extra_rdoc_files:
29
30
  files:
30
31
  - .gitignore
31
32
  - LICENSE
32
- - README
33
33
  - Rakefile
34
34
  - VERSION
35
35
  - ext/tidy/access.c
@@ -101,25 +101,29 @@ rdoc_options:
101
101
  require_paths:
102
102
  - lib
103
103
  required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
104
105
  requirements:
105
106
  - - ">="
106
107
  - !ruby/object:Gem::Version
108
+ hash: 3
107
109
  segments:
108
110
  - 0
109
111
  version: "0"
110
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
111
114
  requirements:
112
115
  - - ">="
113
116
  - !ruby/object:Gem::Version
117
+ hash: 3
114
118
  segments:
115
119
  - 0
116
120
  version: "0"
117
121
  requirements: []
118
122
 
119
123
  rubyforge_project:
120
- rubygems_version: 1.3.6
124
+ rubygems_version: 1.3.7
121
125
  signing_key:
122
126
  specification_version: 3
123
- summary: HTML Tidy library implemented as a Ruby extension.
127
+ summary: W3C HTML Tidy library implemented as a Ruby extension.
124
128
  test_files: []
125
129
 
data/README DELETED
@@ -1,12 +0,0 @@
1
- A native Ruby extension for the tidy application.
2
-
3
- Example usage:
4
-
5
- require 'tidy'
6
- require 'open-uri'
7
-
8
- tidy = Tidy.new
9
- errors, tidy_output = tidy.parse('http://www.github.com')
10
-
11
- puts errors, tidy_output
12
-