validate-website 1.9.1 → 1.9.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60082f1dc222de92a3465b0487e6047597d7605fd2199e15f246a5930ddd5ea3
4
- data.tar.gz: 1fd7bd74bc0b58bbb16e82ae396309db5638362f6f9853d80161849299ff28d8
3
+ metadata.gz: fc639550c1560c9c30de32a770a398594030920917b57994d257c817715f8373
4
+ data.tar.gz: fbc6b126cb99f1f6276b2e7e384a640b971330813d985ddb317311d323e1c916
5
5
  SHA512:
6
- metadata.gz: 3ab5fa6da0d050fc39acabdd4cb26a764acfdb609df4786cb22f55af5d2f500e0638a55e67505cb1d6e1595e0c04ede5ad4ed88b46bf078bc09f58585b7f481c
7
- data.tar.gz: '0199501f535de09d55bc9a8f28549f4c01a94d9444f12732ad02fc503e36158daa1535a61e9b349ea462eb4799bebb5a599417e93dbe2b0abd92b0e0319abb28'
6
+ metadata.gz: 32079467f77389509dd01dd8ce400acbd9bb6a0821658b8d604e891eb5129f1f25413b1f1ec37c53550b4ebe065a603ae14ffdad12ebf8c6fbb7ba99c8a26ab0
7
+ data.tar.gz: 540b198e6ecdd6f804ec9afb63f7e8282eef0c13bb5825d252770f7eed864696a3e77e196932640ac94e6d3d0176a6bbd77e77e82a3240e7c706870672662793
data/History.md CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ 1.9.2 / 2019-03-09
3
+ ==================
4
+
5
+ * Load schema when needed instead of boot
6
+
2
7
  1.9.1 / 2019-03-05
3
8
  ==================
4
9
 
@@ -1,4 +1,5 @@
1
1
  require 'slop'
2
+ require File.expand_path('version', __dir__)
2
3
 
3
4
  module ValidateWebsite
4
5
  # Internal class for parse command line args
@@ -11,26 +11,24 @@ module ValidateWebsite
11
11
  extend ValidatorClassMethods
12
12
 
13
13
  @html5_validator_service_url = 'https://checker.html5.org/'
14
+ XHTML_SCHEMA_PATH = File.expand_path('../../data/schemas', __dir__)
15
+ @mutex = Mutex.new
16
+
14
17
  class << self
15
18
  attr_accessor :html5_validator_service_url
16
- end
17
-
18
- XHTML_PATH = File.expand_path('../../data/schemas', __dir__)
19
-
20
- @xsd_schemas ||= {}
21
19
 
22
- # `Dir.chdir` is needed by `Nokogiri::XML::Schema` to validate with local
23
- # files and cannot use file absolute path.
24
- Dir.glob(File.join(XHTML_PATH, '*.xsd')).each do |schema|
25
- Dir.chdir(XHTML_PATH) do
26
- schema_name = File.basename(schema, '.xsd')
27
- schema_content = File.read(File.basename(schema))
28
- begin
29
- @xsd_schemas[schema_name] = Nokogiri::XML::Schema(schema_content)
30
- rescue Nokogiri::XML::SyntaxError
31
- STDERR.puts "XSD SCHEMA: #{schema} cannot be loaded"
20
+ # http://www.w3.org/TR/xhtml1-schema/
21
+ def schema(namespace)
22
+ @mutex.synchronize do
23
+ Dir.chdir(XHTML_SCHEMA_PATH) do
24
+ if File.exist?("#{namespace}.xsd")
25
+ Nokogiri::XML::Schema(File.read("#{namespace}.xsd"))
26
+ end
27
+ end
32
28
  end
33
29
  end
30
+
31
+ alias xsd schema
34
32
  end
35
33
 
36
34
  attr_reader :original_doc, :body, :dtd, :doc, :namespace, :html5_validator
@@ -65,12 +63,6 @@ module ValidateWebsite
65
63
  @ignore ? @errors.reject { |e| @ignore =~ e } : @errors
66
64
  end
67
65
 
68
- # http://www.w3.org/TR/xhtml1-schema/
69
- def self.xsd(namespace)
70
- return unless namespace
71
- @xsd_schemas[namespace] if @xsd_schemas.key? namespace
72
- end
73
-
74
66
  private
75
67
 
76
68
  # http://www.w3.org/TR/xhtml1/#dtds
@@ -95,11 +87,11 @@ module ValidateWebsite
95
87
  def validate
96
88
  if document =~ /^\<!DOCTYPE html\>/i
97
89
  html5_validate
98
- elsif self.class.xsd(@namespace)
99
- self.class.xsd(@namespace).validate(xhtml_doc)
90
+ elsif self.class.schema(@namespace)
91
+ self.class.schema(@namespace).validate(xhtml_doc)
100
92
  else
101
93
  # dont have xsd fall back to dtd
102
- Dir.chdir(XHTML_PATH) do
94
+ Dir.chdir(XHTML_SCHEMA_PATH) do
103
95
  Nokogiri::HTML.parse(document)
104
96
  end.errors
105
97
  end
@@ -138,7 +130,7 @@ module ValidateWebsite
138
130
  end
139
131
 
140
132
  def xhtml_doc
141
- Dir.chdir(XHTML_PATH) do
133
+ Dir.chdir(XHTML_SCHEMA_PATH) do
142
134
  Nokogiri::XML(document) { |cfg| cfg.nonoent.dtdload.dtdvalid.nonet }
143
135
  end
144
136
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Version file for ValidateWebsite
4
4
  module ValidateWebsite
5
- VERSION = '1.9.1'.freeze
5
+ VERSION = '1.9.2'.freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validate-website
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Arnoud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-05 00:00:00.000000000 Z
11
+ date: 2019-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: crass