Sha256: 165e607ba7267468b705e9c998ec6177d5f56fccf3b056561401829d35d47e41
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
module Middleman module Xmlvalidator class << self def registered(app) require 'nokogiri' app.after_build do |builder| puts "", "Validating with NokoGiri", "" Dir.glob("build/**/*.{xml,rss}").each do |full_path| Xmlvalidator.validate_file(full_path) end puts "", "Validation with NokoGiri " + "Complete".green, "" end end alias :included :registered end def self.validate_file(file_path) file_name = file_path.split('/').last validator_file = file_name.gsub(/\.\w*/, '.xsd') schema_path = File.join(File.dirname(__FILE__), '/schema/') schema_path += File.exists?(schema_path + validator_file) ? validator_file : (file_name.end_with?('.rss') ? "RSSSchema.xsd" : "XMLSchema.xsd") errors = Xmlvalidator.validate(file_path, schema_path) puts " validating".blue + " #{file_path}....." + (errors.size == 0 ? "COMPLETE".green : "ERRORS FOUND".red) errors.each { |error| puts " " + error.message } end def self.validate(document_path, schema_path) schema = Nokogiri::XML::Schema(File.read(schema_path)) document = Nokogiri::XML(File.read(document_path)) schema.validate(document) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
middleman-xmlvalidator-0.2.1 | lib/middleman/xmlvalidator/extension.rb |