rack-valid-html 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source :gemcutter
2
+
3
+ gem 'bundler'
4
+
5
+ gem 'rack'
6
+ gem 'tidy'
7
+
8
+ group :test do
9
+ gem 'shoulda'
10
+ gem 'mhennemeyer-matchy'
11
+ gem 'mocha'
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ mhennemeyer-matchy (0.3.3)
5
+ rack (1.2.1)
6
+ shoulda (2.11.3)
7
+ tidy (1.1.2)
8
+
9
+ PLATFORMS
10
+ ruby
11
+
12
+ DEPENDENCIES
13
+ bundler
14
+ mhennemeyer-matchy
15
+ rack
16
+ shoulda
17
+ tidy
data/Manifest ADDED
@@ -0,0 +1,10 @@
1
+ Gemfile
2
+ Gemfile.lock
3
+ Rakefile
4
+ lib/rack/tidy_response.rb
5
+ lib/rack/validator.rb
6
+ readme.md
7
+ test/rack_validator_test.rb
8
+ test/test_helper.rb
9
+ test/tidy_response_test.rb
10
+ Manifest
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('rack-valid-html', '0.1') do |p|
6
+ p.description = "A Rack app that runs Tidy on your html and prepends any errors to the response"
7
+ p.url = "http://github.com/kid80/rack-validator"
8
+ p.author = "Felix Clack"
9
+ p.email = "felixclack@gmail.com"
10
+ p.development_dependencies = []
11
+ end
@@ -0,0 +1,33 @@
1
+ require 'tidy'
2
+
3
+ class TidyResponse
4
+
5
+ def initialize(body)
6
+ @body = body
7
+ ::Tidy.path = '/usr/lib/libtidy.A.dylib'
8
+ end
9
+
10
+ def to_s
11
+ tidy = Tidy.open
12
+
13
+ tidy.clean(@body)
14
+
15
+ tidy.errors.join("<br />") + @body
16
+ end
17
+
18
+ def w3c_errors
19
+ response = Net::HTTP.post_form(
20
+ URI.parse("http://validator.w3.org/check"),
21
+ {
22
+ 'ss'=>0,
23
+ 'fragment'=>@body
24
+ }
25
+ )
26
+ status = response['x-w3c-validator-status']
27
+ if status != 'Valid'
28
+ response.body
29
+ else
30
+ nil
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ require 'lib/rack/tidy_response'
2
+
3
+ module Rack
4
+ class Validator
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ status, headers, response = @app.call(env)
12
+
13
+ @response = response.respond_to?(:body) ? ::TidyResponse.new(response.body).to_s : response
14
+ [status, headers, @response]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rack-valid-html}
5
+ s.version = "0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Felix Clack"]
9
+ s.cert_chain = ["/Users/felix/.ssh/gem-public_cert.pem"]
10
+ s.date = %q{2010-09-14}
11
+ s.description = %q{A Rack app that runs Tidy on your html and prepends any errors to the response}
12
+ s.email = %q{felixclack@gmail.com}
13
+ s.extra_rdoc_files = ["lib/rack/tidy_response.rb", "lib/rack/validator.rb"]
14
+ s.files = ["Gemfile", "Gemfile.lock", "Rakefile", "lib/rack/tidy_response.rb", "lib/rack/validator.rb", "readme.md", "test/rack_validator_test.rb", "test/test_helper.rb", "test/tidy_response_test.rb", "Manifest", "rack-valid-html.gemspec"]
15
+ s.homepage = %q{http://github.com/kid80/rack-validator}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rack-valid-html", "--main", "readme.md"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{rack-valid-html}
19
+ s.rubygems_version = %q{1.3.7}
20
+ s.signing_key = %q{/Users/felix/.ssh/gem-private_key.pem}
21
+ s.summary = %q{A Rack app that runs Tidy on your html and prepends any errors to the response}
22
+ s.test_files = ["test/rack_validator_test.rb", "test/test_helper.rb", "test/tidy_response_test.rb"]
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 3
27
+
28
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
29
+ else
30
+ end
31
+ else
32
+ end
33
+ end
data/readme.md ADDED
@@ -0,0 +1,18 @@
1
+ Rack::Validator
2
+ ===============
3
+
4
+ Ensure your html is valid. Use it as middleware in your Rails app.
5
+
6
+ This is the first line of defence against invalid html.
7
+
8
+ In your Gemfile:
9
+ `
10
+ config.gem 'rack-validator', :group => :development
11
+ `
12
+
13
+ then in your development.rb:
14
+ `
15
+ require 'rack/validator'
16
+
17
+ config.middleware.use Rack::Validator
18
+ `
@@ -0,0 +1,22 @@
1
+ require 'test/test_helper'
2
+
3
+ class RackValidatorTest < Test::Unit::TestCase
4
+
5
+ def get_response(body)
6
+ app = Rack::Builder.new do
7
+ use Rack::Validator
8
+ run lambda { |env| [200, {'Content-Type' => 'text/html'}, [body] ] }
9
+ end
10
+ Rack::MockRequest.new(app).get("")
11
+ end
12
+
13
+ context "Rack::Validator" do
14
+ context "with html" do
15
+ should "pass it to TidyResponse" do
16
+ ::TidyResponse.expects(:new)
17
+ ::TidyResponse.any_instance.expects(:to_s)
18
+ @response = get_response(invalid_html)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+ require 'rack'
6
+ require 'lib/rack/validator'
7
+ require 'rack/mock'
8
+ require 'matchy'
9
+
10
+ class Test::Unit::TestCase
11
+
12
+ def invalid_html
13
+ "<html><head><title>Title</title></head><body><p id='duplicate'><h1 id='duplicate'>Invalid header</h1></p></body></html>"
14
+ end
15
+
16
+ def errors_html
17
+ "line 1 column 1 - Warning: missing <!DOCTYPE> declaration\nline 1 column 125 - Warning: inserting implicit <p>\nline 1 column 81 - Warning: <h1> anchor \"duplicate\" already defined\nline 1 column 125 - Warning: trimming empty <p>\n"
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ require 'test/test_helper'
2
+
3
+ class TidyResponseTest < Test::Unit::TestCase
4
+
5
+ context "with invalid html" do
6
+ setup { @tidy_response = TidyResponse.new(invalid_html) }
7
+
8
+ context "when validated" do
9
+ setup { @response = @tidy_response.to_s }
10
+
11
+ should "add errors to the response" do
12
+ @response.should == errors_html + invalid_html
13
+ end
14
+ end
15
+ end
16
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-valid-html
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Felix Clack
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ - |
17
+ -----BEGIN CERTIFICATE-----
18
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRMwEQYDVQQDDApmZWxp
19
+ eGNsYWNrMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFgNj
20
+ b20wHhcNMTAwOTE0MTQ0NjUyWhcNMTEwOTE0MTQ0NjUyWjBBMRMwEQYDVQQDDApm
21
+ ZWxpeGNsYWNrMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
22
+ FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC4m3tRNrwOHYYy
23
+ qZ/AYcrCB8ZNiQKP8o5eyRId44OwYwQ1bGjfC1MWNHv1DLUHUNkD0wpt1uNBInmU
24
+ D3ZKpk4wGCF4D6kBFVdAU4dvPeaQ2Pb18Ih3jSKqxaCvfd7ILWgPEHVABd8zMf2n
25
+ 5i5dDTyMHJJDNC6mSVi9dfStozYFgRBaRD0Aa2XhSwHXon820068xlX4qfTRYKu5
26
+ /HKweJun3UH4MnOT+PZ9UpPtkV482AekofImPYrtdwkSOWdF6nYno7eupbGBuqkK
27
+ 5Cj9X5p3iz3yAE+pqIHHoc3LAipG+aZ3dYXvVqWJoD+efH3Bd2nIXM5Tk7R82mlw
28
+ oek5lS2nAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
29
+ BBQWm/BO6jvKebOjybdOb98o26/RrjANBgkqhkiG9w0BAQUFAAOCAQEAKSoXp1VS
30
+ rhcNtjBuDKYKV4tmmPdtJOqxSA6MrBmuChKTjd9L8wDerXDbdS7bPlPTlMKHkvxx
31
+ FxhpHyy0zfg9PTCJH7USPZTywwAs9pwbNecGaYXV4tdUdPmof2kCtdh3vSdVjGty
32
+ Pt3YjmScthtCj2MR6A2fIusGuwqFljR3vkmrDIjH9RUDdtakDHhqirHSl8P1uQe9
33
+ KHB7OHEwC0MvGgFDcvB00ErI+L4brAhfS4sO6zTIduGE84dMbbK9JhehEPzaLcSw
34
+ lM3FE2rsXVpGIRaDCvfdMlwZ1/JQGHivMYhaqX4EUmhytjE4RWVZYFdGyWqO4ixc
35
+ RCL0dGze8u6+VQ==
36
+ -----END CERTIFICATE-----
37
+
38
+ date: 2010-09-14 00:00:00 +01:00
39
+ default_executable:
40
+ dependencies: []
41
+
42
+ description: A Rack app that runs Tidy on your html and prepends any errors to the response
43
+ email: felixclack@gmail.com
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - lib/rack/tidy_response.rb
50
+ - lib/rack/validator.rb
51
+ files:
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - Rakefile
55
+ - lib/rack/tidy_response.rb
56
+ - lib/rack/validator.rb
57
+ - readme.md
58
+ - test/rack_validator_test.rb
59
+ - test/test_helper.rb
60
+ - test/tidy_response_test.rb
61
+ - Manifest
62
+ - rack-valid-html.gemspec
63
+ has_rdoc: true
64
+ homepage: http://github.com/kid80/rack-validator
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --line-numbers
70
+ - --inline-source
71
+ - --title
72
+ - Rack-valid-html
73
+ - --main
74
+ - readme.md
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 11
92
+ segments:
93
+ - 1
94
+ - 2
95
+ version: "1.2"
96
+ requirements: []
97
+
98
+ rubyforge_project: rack-valid-html
99
+ rubygems_version: 1.3.7
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: A Rack app that runs Tidy on your html and prepends any errors to the response
103
+ test_files:
104
+ - test/rack_validator_test.rb
105
+ - test/test_helper.rb
106
+ - test/tidy_response_test.rb
metadata.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ �����@�:Vx.2�8�GSX�ҘI����"&~��<�� {2�m'���7��l���y7�'.f�"���El��Ǚ�����[o��"��������� ��!��ڵ��_�?�y��sw5�g���"��N�+�����J2�<���_���ZѲ�4��%�ѩY���
2
+ F�|?�9PT2��l��߬)��P�:L_yW�n�B�������b��