css_validator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80f97ca610e810853f305d79c2c44ce14ee523fc
4
+ data.tar.gz: b05352c7fe8a508185de7d137e128fe3b66c57ef
5
+ SHA512:
6
+ metadata.gz: 0038dfe753e6a87f64f4fe3378b2e6568d4b72746557cd12577b5629faac9b6cb616532c580194e47010f7c6d4eca8ed6fef2a585a2fc52b1af7086594a220af
7
+ data.tar.gz: dbfd43c1d94b07362ccacfe68e59cd8bbed045a2c3ae63a8e51630150fcdd19493ac89d118d6f67695722eb2534913febe706bdbd9326be78c91faaaa45febbd
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.swp
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
6
+
7
+ Vagrantfile
8
+ .vagrant
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in css_validator.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2014 Teng Siong Ong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # CSS Validator
2
+
3
+ This uses the `css-validator.jar` from [W3C](http://jigsaw.w3.org/css-validator/DOWNLOAD.html) to validate CSS in ActiveModel.
4
+ So, your system requires `java` to use this gem.
5
+
6
+ ## Usage
7
+
8
+ ```ruby
9
+ require 'css_validator'
10
+
11
+ class WebPage
12
+ include ActiveModel::Validations
13
+ attr_accessor :css
14
+
15
+ validates :css, presence: true, css: true
16
+ end
17
+
18
+ p = WebPage.new
19
+ p.css = <<-eos
20
+ #valid {
21
+ margin: asd;
22
+ }
23
+ eos
24
+ p.valid? # => false
25
+
26
+ p.css = <<-eos
27
+ #valid {
28
+ margin: 10px;
29
+ }
30
+ eos
31
+ p.valid? # => true
32
+ ```
33
+
34
+ ## Installation
35
+
36
+ In your Gemfile:
37
+
38
+ ```ruby
39
+ gem 'css_validator'
40
+ ```
41
+
42
+ ## License
43
+
44
+ (The MIT License)
45
+
46
+ Copyright (c) 2014 Teng Siong Ong
47
+
48
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
49
+
50
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ task :default => [:spec]
10
+ task :build => [:spec]
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "css_validator"
3
+ s.version = "1.0.0"
4
+ s.authors = ["Teng Siong Ong"]
5
+ s.email = ["siong1987@gmail.com"]
6
+ s.homepage = "https://github.com/siong1987/css_validator"
7
+ s.summary = %q{ActiveModel Validation for CSS}
8
+ s.description = %q{ActiveModel Validation for CSS}
9
+ s.license = "MIT"
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+
14
+ s.require_paths = ["lib"]
15
+
16
+ # specify any dependencies here; for example:
17
+ s.add_development_dependency "rspec"
18
+ s.add_development_dependency "rake"
19
+ s.add_runtime_dependency "activemodel"
20
+ end
@@ -0,0 +1,30 @@
1
+ require 'open3'
2
+ require 'active_model'
3
+ require 'active_model/validations'
4
+
5
+ class CssValidator < ActiveModel::EachValidator
6
+ VALIDATOR = File.join(File.expand_path('../..', __FILE__), 'vendor', 'css-validator.jar')
7
+
8
+ def validate_each(record, attribute, value)
9
+ java_path = `which java`.rstrip
10
+ raise 'You do not have a Java installed, but it is required.' unless java_path && !java_path.empty?
11
+
12
+ return if options[:allow_nil] && value.nil?
13
+ return if options[:allow_blank] && value.blank?
14
+
15
+ css_file = Tempfile.new(['css', '.css'])
16
+ css_file.write(value)
17
+ css_file.close
18
+
19
+ cmd = "#{java_path} -jar #{VALIDATOR} -output text -profile css3 'file:#{css_file.path}'"
20
+ Open3.popen3(cmd) do |stdin, stdout, stderr|
21
+ result = stdout.read
22
+ if result =~ /found the following errors \((\d+)\)/
23
+ record.errors.add attribute, (options[:message] || 'is invalid')
24
+ end
25
+ end
26
+
27
+ ensure
28
+ css_file.unlink if css_file # deletes the temp file
29
+ end
30
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ VALID_FIXTURES = Dir.glob(File.join(File.expand_path('../..', __FILE__), 'spec', 'fixtures', 'valid_css', '*'))
4
+ INVALID_FIXTURES = Dir.glob(File.join(File.expand_path('../..', __FILE__), 'spec', 'fixtures', 'invalid_css', '*'))
5
+
6
+ describe CssValidator do
7
+ webpage_class = Class.new do
8
+ include ActiveModel::Validations
9
+ attr_accessor :css
10
+ validates :css, css: true
11
+ end
12
+
13
+ webpage_class_nil_allowed = Class.new do
14
+ include ActiveModel::Validations
15
+ attr_accessor :css
16
+ validates :css, css: { allow_nil: true }
17
+ end
18
+
19
+ webpage_class_blank_allowed = Class.new do
20
+ include ActiveModel::Validations
21
+ attr_accessor :css
22
+ validates :css, css: { allow_blank: true }
23
+ end
24
+
25
+ describe "validating css" do
26
+ let!(:errors) { [ "is invalid" ] }
27
+ subject { webpage_class.new }
28
+
29
+ it "should pass when css empty" do
30
+ subject.valid?.should be_true
31
+ subject.errors[:css].should be_empty
32
+ end
33
+
34
+ VALID_FIXTURES.each do |css_file|
35
+ it "should pass when css is valid" do
36
+ css_content = File.read(css_file)
37
+
38
+ subject.css = css_content
39
+ subject.valid?.should be_true
40
+ subject.errors[:css].should be_empty
41
+ end
42
+ end
43
+
44
+ INVALID_FIXTURES.each do |css_file|
45
+ it "should fail when css is not valid" do
46
+ css_content = File.read(css_file)
47
+
48
+ subject.css = css_content
49
+ subject.valid?.should be_false
50
+ subject.errors[:css].should == errors
51
+ end
52
+ end
53
+ end
54
+
55
+ describe "Can allow nil" do
56
+ subject { webpage_class_nil_allowed.new }
57
+
58
+ it "should pass even if css isn't set" do
59
+ subject.css = nil
60
+ subject.should be_valid
61
+ subject.errors[:css].should be_empty
62
+ end
63
+ end
64
+
65
+ describe "Can allow blank" do
66
+ subject { webpage_class_blank_allowed.new }
67
+
68
+ it "should pass even if css is a blank string set" do
69
+ subject.css = ''
70
+ subject.should be_valid
71
+ subject.errors[:css].should be_empty
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ invalid {
2
+ invaild;
3
+ }
@@ -0,0 +1,3 @@
1
+ #valid {
2
+ margin: invalid;
3
+ }
@@ -0,0 +1 @@
1
+ alert("javascript injection");
@@ -0,0 +1,3 @@
1
+ #valid {
2
+ margin: 0;
3
+ }
@@ -0,0 +1,2 @@
1
+ $:.unshift File.expand_path('../../lib',__FILE__)
2
+ require 'css_validator'
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: css_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Teng Siong Ong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activemodel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ActiveModel Validation for CSS
56
+ email:
57
+ - siong1987@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - css_validator.gemspec
69
+ - lib/css_validator.rb
70
+ - spec/css_validator_spec.rb
71
+ - spec/fixtures/invalid_css/0.css
72
+ - spec/fixtures/invalid_css/1.css
73
+ - spec/fixtures/invalid_css/2.css
74
+ - spec/fixtures/valid_css/0.css
75
+ - spec/spec_helper.rb
76
+ - vendor/css-validator.jar
77
+ - vendor/lib/commons-collections-3.2.1.jar
78
+ - vendor/lib/commons-lang-2.6.jar
79
+ - vendor/lib/htmlparser-1.2.1.jar
80
+ - vendor/lib/jigsaw.jar
81
+ - vendor/lib/tagsoup-1.2.jar
82
+ - vendor/lib/velocity-1.7.jar
83
+ - vendor/lib/xercesImpl.jar
84
+ homepage: https://github.com/siong1987/css_validator
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.1.11
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: ActiveModel Validation for CSS
108
+ test_files: []