tidy-ext 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.1.10
data/ext/tidy/ruby-tidy.c CHANGED
@@ -33,28 +33,6 @@ static void rb_tidy_free(void *ptr)
33
33
  tidyRelease(ptr);
34
34
  }
35
35
 
36
- /* create a new tidy doc */
37
- static VALUE rb_tidy_new(int argc, VALUE *argv, VALUE class)
38
- {
39
- TidyDoc tdoc = tidyCreate();
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);
54
-
55
- return self;
56
- }
57
-
58
36
  /* called when iterating over options hash */
59
37
  static VALUE rb_tidy_set_option(VALUE arg1, VALUE arg2)
60
38
  {
@@ -110,6 +88,30 @@ static VALUE rb_tidy_set_option(VALUE arg1, VALUE arg2)
110
88
  return Qnil;
111
89
  }
112
90
 
91
+ /* create a new tidy doc */
92
+ static VALUE rb_tidy_new(int argc, VALUE *argv, VALUE class)
93
+ {
94
+ TidyDoc tdoc = tidyCreate();
95
+ VALUE options;
96
+ VALUE access = INT2NUM(4);
97
+ VALUE errors = rb_ary_new();
98
+
99
+ VALUE self = Data_Wrap_Struct(class, 0, rb_tidy_free, (struct _TidyDoc *)tdoc);
100
+
101
+ rb_scan_args(argc, argv, "01", &options);
102
+ options = NIL_P(options) ? rb_hash_new() : options;
103
+
104
+ rb_iv_set(self, "@options", options);
105
+ rb_iv_set(self, "@access", access);
106
+ rb_iv_set(self, "@errors", errors);
107
+
108
+ rb_iterate(rb_each, options, rb_tidy_set_option, self);
109
+
110
+ rb_obj_call_init(self, 0, NULL);
111
+
112
+ return self;
113
+ }
114
+
113
115
  /* parse the given input and return the tidy errors and output */
114
116
  static VALUE rb_tidy_parse(VALUE self, VALUE input)
115
117
  {
@@ -137,9 +139,6 @@ static VALUE rb_tidy_parse(VALUE self, VALUE input)
137
139
 
138
140
  status = tidySetErrorBuffer( tdoc, &errbuf );
139
141
 
140
- options = rb_iv_get(self, "@options");
141
- rb_iterate(rb_each, options, rb_tidy_set_option, self);
142
-
143
142
  if (status >= 0) {
144
143
 
145
144
  int is_input_source = 0;
@@ -0,0 +1,20 @@
1
+ require 'tidy'
2
+
3
+ Given /^(.+) is tidy$/ do |page_name|
4
+
5
+ visit path_to(page_name)
6
+
7
+ tidy = Tidy.open({:show_warnings => true}) do |tidy|
8
+ out = tidy.clean(response.body)
9
+ end
10
+
11
+ tidy.errors.scan(/(\d+) warning, (\d+) errors were found!/) do |w,e|
12
+ warnings = w.to_i
13
+ errors = e.to_i
14
+ unless warnings == 0 && errors == 0
15
+ raise tidy.errors
16
+ end
17
+ end
18
+
19
+ end
20
+
@@ -69,7 +69,7 @@ describe "tidy compatibility methods" do
69
69
  }
70
70
  tidy = Tidy.open(options) do |tidy|
71
71
  clean = tidy.clean(laundry)
72
- clean.should =~ /<HTML>/
72
+ clean.should_not =~ /<[a-z]+\s+[^>]*>/
73
73
  clean.should =~ /alt="hello world"/
74
74
  end
75
75
  end
@@ -82,7 +82,7 @@ describe "tidy compatibility methods" do
82
82
  }
83
83
  tidy = Tidy.open(options) do |tidy|
84
84
  clean = tidy.clean(laundry)
85
- clean.should =~ /<HTML>/
85
+ clean.should_not =~ /<[a-z]+\s+[^>]*>/
86
86
  clean.should =~ /alt="hello world"/
87
87
  end
88
88
  end
@@ -8,7 +8,9 @@ describe "tidy class methods" do
8
8
  it "should parse the google.com uri" do
9
9
  uri = open("http://www.google.com")
10
10
  page = uri.read
11
- errors, html = subject.parse(page)
11
+ tidy = Tidy.new() do |tidy|
12
+ errors, html = tidy.clean(page)
13
+ end
12
14
  end
13
15
 
14
16
  end
@@ -9,16 +9,20 @@ describe "tidy class methods" do
9
9
  end
10
10
 
11
11
  it "should parse a string" do
12
- errors, html = subject.parse("<html><body>String</body></html>")
13
- errors.should_not be_nil
14
- html.should_not be_nil
12
+ Tidy.new() do |tidy|
13
+ errors, html = tidy.clean("<html><body>String</body></html>")
14
+ errors.should_not be_nil
15
+ html.should_not be_nil
16
+ end
15
17
  end
16
18
 
17
19
  it "should parse a file" do
18
20
  file = File.new(File.join(File.dirname(__FILE__),'test1.html'))
19
- errors, html = subject.parse(file)
20
- errors.should_not be_nil
21
- html.should_not be_nil
21
+ Tidy.new() do |tidy|
22
+ errors, html = tidy.clean(file)
23
+ errors.should_not be_nil
24
+ html.should_not be_nil
25
+ end
22
26
  end
23
27
 
24
28
  it "should respond to access" do
@@ -26,8 +30,10 @@ describe "tidy class methods" do
26
30
  end
27
31
 
28
32
  it "should be able to parse more than one string consecutively" do
29
- errors1, html1 = subject.parse("<html><body>String</body></html>")
30
- errors2, html2 = subject.parse("<html><head><title>hello</title></head><body>String</body></html>")
33
+ Tidy.new do |tidy|
34
+ errors1, html1 = tidy.clean("<html><body>String</body></html>")
35
+ errors2, html2 = tidy.clean("<html><head><title>hello</title></head><body>String</body></html>")
36
+ end
31
37
  end
32
38
 
33
39
  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: 9
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 9
10
- version: 0.1.9
9
+ - 10
10
+ version: 0.1.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Carl Douglas
@@ -86,6 +86,7 @@ files:
86
86
  - ext/tidy/version.h
87
87
  - ext/tidy/win32tc.c
88
88
  - ext/tidy/win32tc.h
89
+ - features/step_definitions/tidy_steps.rb
89
90
  - spec/spec_helper.rb
90
91
  - spec/tidy/compat_spec.rb
91
92
  - spec/tidy/remote_uri_spec.rb