rack-valid-html 0.1 → 0.1.1
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 +1 -1
- data/lib/rack/tidy_response.rb +25 -23
- data/lib/rack/validator.rb +2 -2
- data/rack-valid-html.gemspec +1 -1
- data/test/rack_validator_test.rb +2 -2
- data.tar.gz.sig +0 -0
- metadata +3 -2
- metadata.gz.sig +2 -2
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('rack-valid-html', '0.1') do |p|
|
5
|
+
Echoe.new('rack-valid-html', '0.1.1') do |p|
|
6
6
|
p.description = "A Rack app that runs Tidy on your html and prepends any errors to the response"
|
7
7
|
p.url = "http://github.com/kid80/rack-validator"
|
8
8
|
p.author = "Felix Clack"
|
data/lib/rack/tidy_response.rb
CHANGED
@@ -1,33 +1,35 @@
|
|
1
1
|
require 'tidy'
|
2
2
|
|
3
|
-
|
3
|
+
module Rack
|
4
|
+
class TidyResponse
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(body)
|
7
|
+
@body = body
|
8
|
+
::Tidy.path = '/usr/lib/libtidy.A.dylib'
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
def to_s
|
12
|
+
tidy = Tidy.open
|
12
13
|
|
13
|
-
|
14
|
+
tidy.clean(@body)
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
tidy.errors.join("<br />") + @body
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
19
|
+
def w3c_errors
|
20
|
+
response = Net::HTTP.post_form(
|
21
|
+
URI.parse("http://validator.w3.org/check"),
|
22
|
+
{
|
23
|
+
'ss'=>0,
|
24
|
+
'fragment'=>@body
|
25
|
+
}
|
26
|
+
)
|
27
|
+
status = response['x-w3c-validator-status']
|
28
|
+
if status != 'Valid'
|
29
|
+
response.body
|
30
|
+
else
|
31
|
+
nil
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
data/lib/rack/validator.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'lib/rack/tidy_response'
|
1
|
+
require File.expand_path('./', 'lib/rack/tidy_response')
|
2
2
|
|
3
3
|
module Rack
|
4
4
|
class Validator
|
@@ -10,7 +10,7 @@ module Rack
|
|
10
10
|
def call(env)
|
11
11
|
status, headers, response = @app.call(env)
|
12
12
|
|
13
|
-
@response = response.respond_to?(:body) ? ::TidyResponse.new(response.body).to_s : response
|
13
|
+
@response = response.respond_to?(:body) ? Rack::TidyResponse.new(response.body).to_s : response
|
14
14
|
[status, headers, @response]
|
15
15
|
end
|
16
16
|
end
|
data/rack-valid-html.gemspec
CHANGED
data/test/rack_validator_test.rb
CHANGED
@@ -13,8 +13,8 @@ class RackValidatorTest < Test::Unit::TestCase
|
|
13
13
|
context "Rack::Validator" do
|
14
14
|
context "with html" do
|
15
15
|
should "pass it to TidyResponse" do
|
16
|
-
::TidyResponse.expects(:new)
|
17
|
-
::TidyResponse.any_instance.expects(:to_s)
|
16
|
+
Rack::TidyResponse.expects(:new)
|
17
|
+
Rack::TidyResponse.any_instance.expects(:to_s)
|
18
18
|
@response = get_response(invalid_html)
|
19
19
|
end
|
20
20
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-valid-html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Felix Clack
|
metadata.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
w7[���(��.�
|
2
|
+
C�x���)ӂ�2lj���|w���¯`��a���1g����Y7+��p(��I�|J�&�?zӾ�Q���Y��7r���s�?
|