Module: Middleman::Xmlvalidator

Defined in:
lib/middleman/xmlvalidator/version.rb,
lib/middleman/xmlvalidator/extension.rb

Constant Summary collapse

VERSION =
"0.1.1"
PACKAGE =
"middleman-xmlvalidator"

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object Also known as: included



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/middleman/xmlvalidator/extension.rb', line 4

def registered(app)
	require 'nokogiri'
	app.after_build do |builder|
		puts "", "Validating with NokoGiri", ""

		Dir.glob("build/**/*BingSiteAuth.xml").each do |full_path|
			puts "  validating".blue + "  #{full_path}....." + (Xmlvalidator.valid(full_path, 'BingSiteAuth.xsd') == true ? "COMPLETE".green : "ERRORS FOUND".red)
			Xmlvalidator.validate(full_path, 'BingSiteAuth.xsd').each do |error|
				puts "     " + error.message
			end
		end

		Dir.glob("build/**/*crossdomain.xml").each do |full_path|
			puts "  validating".blue + "  #{full_path}....." + (Xmlvalidator.valid(full_path, 'crossdomain.xsd') == true ? "COMPLETE".green : "ERRORS FOUND".red)
			Xmlvalidator.validate(full_path, 'crossdomain.xsd').each do |error|
				puts "     " + error.message
			end
		end

		Dir.glob("build/**/*Sitemap.xml").each do |full_path|
			puts "  validating".blue + "  #{full_path}....." + (Xmlvalidator.valid(full_path, 'Sitemap3.xsd') == true ? "COMPLETE".green : "ERRORS FOUND".red)
			Xmlvalidator.validate(full_path, 'Sitemap3.xsd').each do |error|
				puts "     " + error.message
			end
		end

		Dir.glob("build/**/*.rss").each do |full_path|
			puts "  validating".blue + "  #{full_path}....." + (Xmlvalidator.valid(full_path, 'RSSSchema.xsd') == true ? "COMPLETE".green : "ERRORS FOUND".red)
			Xmlvalidator.validate(full_path, 'RSSSchema.xsd').each do |error|
				puts "     " + error.message
			end
		end

		Dir.glob("build/**/*.xml").each do |full_path|
			if not (full_path.match(/^.*BingSiteAuth.xml$/) || full_path.match(/^.*crossdomain.xml$/) || full_path.match(/^.*Sitemap.xml$/))
				puts "  validating".blue + "  #{full_path}....." + (Xmlvalidator.valid(full_path, 'XMLSchema.xsd') == true ? "COMPLETE".green : "ERRORS FOUND".red)
				Xmlvalidator.validate(full_path, 'XMLSchema.xsd').each do |error|
					puts "     " + error.message
				end
			end
		end

		puts "", "Validation with NokoGiri " + "Complete".green, ""
	end
end

.valid(document_path, schema_path) ⇒ Object



58
59
60
61
62
# File 'lib/middleman/xmlvalidator/extension.rb', line 58

def self.valid(document_path, schema_path)
	schema = Nokogiri::XML::Schema(File.read(File.join(File.dirname(File.expand_path(__FILE__)), "./schema/" + schema_path)))
	document = Nokogiri::XML(File.read(document_path))
	schema.valid?(document)
end

.validate(document_path, schema_path) ⇒ Object



52
53
54
55
56
# File 'lib/middleman/xmlvalidator/extension.rb', line 52

def self.validate(document_path, schema_path)
	schema = Nokogiri::XML::Schema(File.read(File.join(File.dirname(File.expand_path(__FILE__)), "./schema/" + schema_path)))
	document = Nokogiri::XML(File.read(document_path))
	schema.validate(document)
end