Module: Asciidoctor::RFC::V3::Validate

Included in:
Converter
Defined in:
lib/asciidoctor/rfc/v3/validate.rb

Class Method Summary collapse

Class Method Details

.validate(doc) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/asciidoctor/rfc/v3/validate.rb', line 8

def validate(doc)
  # svg_location = File.join(File.dirname(__FILE__), "svg.rng")
  # schema = Nokogiri::XML::RelaxNG(File.read(File.join(File.dirname(__FILE__), "validate.rng")).
  #   gsub(%r{<ref name="svg"/>}, "<externalRef href='#{svg_location}'/>"))

  filename = File.join(File.dirname(__FILE__), "validate.rng")
  schema = Jing.new(filename)
  File.open(".tmp.xml", "w") { |f| f.write(doc.to_xml) }
  begin
    errors = schema.validate(".tmp.xml")
  rescue Jing::Error => e
    abort "[asciidoctor-rfc] Validation error: #{e}"
  end

  if errors.none?
    warn "[asciidoctor-rfc] Validation passed."
  else
    errors.each do |error|
      warn "[asciidoctor-rfc] #{error[:message]} @ #{error[:line]}:#{error[:column]}"
    end
  end

end