ruby-vnu 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80832e29319788aa56973e328b2b5d382a5f7060
4
+ data.tar.gz: 571156a5d5b357ba16842340afa8b2441f124d67
5
+ SHA512:
6
+ metadata.gz: b420eaaa64fbf0da0bdbe477a6333217c519d4644ca3c2eeb3dea73fa8db24243c3b4789d2f8c67cf24a1ecc5852d0348a9ceb1338033cb99b79323141d2b3e2
7
+ data.tar.gz: 5d7d66cfb54ac9a919e99b6b177bddb8e1959ba209f077de5c07c8c5071b349c0f1b6a124540e7c2b147836710692a668f02dbd4e8ff0bec1ac1c18eb9fd8695
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2015 Laurent Arnoud <laurent@spkdev.net>
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 NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,14 @@
1
+ require 'rdoc/task'
2
+ require 'rake/testtask'
3
+
4
+ task default: [:test]
5
+
6
+ RDoc::Task.new do |rd|
7
+ rd.main = 'README.md'
8
+ rd.rdoc_files.include('README.md', 'lib/**/*.rb')
9
+ end
10
+
11
+ Rake::TestTask.new do |t|
12
+ t.pattern = 'spec/*_spec.rb'
13
+ end
14
+ task spec: :test
@@ -0,0 +1,63 @@
1
+ require 'open3'
2
+
3
+ # Ruby wrapper for [vnu](https://validator.github.io/validator/)
4
+ class Vnu
5
+ JAR_PATH = File.expand_path('../../vnu.jar', __FILE__)
6
+
7
+ attr_reader :command, :target
8
+
9
+ def initialize(*options)
10
+ @target = options.shift
11
+ options = options.last
12
+ if target
13
+ @command = vnu_cli_with_options(options)
14
+ else
15
+ fail RuntimeError
16
+ end
17
+ end
18
+
19
+ def vnu_cli_with_options(options)
20
+ "#{self.class.cli}#{vnu_options(options)} -"
21
+ end
22
+
23
+ def validate
24
+ execute(command)
25
+ end
26
+
27
+ class << self
28
+ def cli
29
+ @cli ||= "java -jar #{JAR_PATH}"
30
+ end
31
+
32
+ def cli_version
33
+ @cli_version ||= `#{cli} --version`.chomp
34
+ end
35
+
36
+ def validate(*options)
37
+ new(*options).validate
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def vnu_options(options)
44
+ return unless options
45
+ return @vnu_options if @vnu_options
46
+ @vnu_options = options.each_with_object('') do |o, str|
47
+ k = o.last.is_a?(String) ? " #{o.last}" : nil
48
+ str << " --#{o.first.to_s.gsub(/_/, '-')}#{k}"
49
+ end
50
+ end
51
+
52
+ def execute(command)
53
+ @output = @error = @exit_status = nil
54
+ Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
55
+ stdin.puts target
56
+ stdin.close
57
+ @output = stdout.read.chomp
58
+ @error = stderr.read.chomp
59
+ @exit_status = wait_thr.value
60
+ end
61
+ @error unless @exit_status.success?
62
+ end
63
+ end
@@ -0,0 +1,4 @@
1
+ require 'minitest/autorun'
2
+ require 'pry'
3
+
4
+ require 'vnu'
@@ -0,0 +1,51 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Vnu do
4
+ it 'return cli' do
5
+ Vnu.cli.must_equal "java -jar #{Vnu::JAR_PATH}"
6
+ end
7
+
8
+ it 'return cli version' do
9
+ Vnu.cli_version.must_match(/^(\d){8}$/)
10
+ end
11
+
12
+ describe 'options' do
13
+ it 'fail' do
14
+ -> { Vnu.new }.must_raise RuntimeError
15
+ end
16
+
17
+ it 'initialze stdin option' do
18
+ stdin = '<!doctype html><title>'
19
+ Vnu.new(stdin).command.must_equal "#{Vnu.cli} -"
20
+ end
21
+
22
+ it 'initialze vnu options' do
23
+ stdin = '<!doctype html><title>'
24
+ options = { errors_only: true, no_stream: true, format: 'json', html: true, verbose: true }
25
+ Vnu.new(stdin, options).command
26
+ .must_equal "#{Vnu.cli} --errors-only --no-stream --format json --html --verbose -"
27
+ end
28
+ end
29
+
30
+ describe 'validate' do
31
+ describe 'success' do
32
+ it 'have no output' do
33
+ stdin = '<!DOCTYPE html><html><head><title>Test</title></head></html>'
34
+ Vnu.validate(stdin).must_equal nil
35
+ end
36
+ end
37
+
38
+ describe 'fail' do
39
+ it 'output default' do
40
+ stdin = '<!DOCTYPE html><html><head><title>Test</title></head><body><ul><li id="1"></li><li id="1"></li></ul></body></html>'
41
+ Vnu.validate(stdin).must_equal %(:1.90-1.90: error: Duplicate ID “1”.
42
+ :1.74-1.74: info warning: The first occurrence of ID “1” was here.)
43
+ end
44
+
45
+ it 'output json' do
46
+ stdin = '<!doctype html><title>'
47
+ Vnu.validate(stdin, errors_only: true, format: 'json').must_equal "{\"messages\":[{\"type\":\"error\",\"lastLine\":1,\"lastColumn\":23,\"message\":\"End of file seen when expecting text or an end tag.\"},{\"type\":\"error\",\"lastLine\":1,\"lastColumn\":22,\"message\":\"Unclosed element “title”.\"}]}"
48
+ end
49
+ end
50
+ end
51
+ end
data/vnu.jar ADDED
Binary file
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-vnu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Laurent Arnoud
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ description: Ruby wrapper for Nu HTML validator (https://validator.github.io/validator/)
56
+ email: laurent@spkdev.net
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - LICENSE
62
+ - Rakefile
63
+ - lib/vnu.rb
64
+ - spec/spec_helper.rb
65
+ - spec/vnu_spec.rb
66
+ - vnu.jar
67
+ homepage: http://github.com/spk/ruby-vnu
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.0.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.2.2
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Ruby wrapper for Nu HTML validator
91
+ test_files:
92
+ - spec/vnu_spec.rb
93
+ has_rdoc: