Sha256: 8f182129789a3d4f243e95efd21ab19ad93c0f0be4803d8f9917458977d8450f
Contents?: true
Size: 566 Bytes
Versions: 2
Compression:
Stored size: 566 Bytes
Contents
require "nokogiri" class TemplateValidator < ActiveModel::Validator @@template_rng = File.join(Tim::Engine.root, "config/schemas", "tdl.rng") def validate(record) begin rng = Nokogiri::XML::RelaxNG(File.read(@@template_rng)) xml = Nokogiri::XML(record.xml) { |config| config.strict } rng.validate(xml).each do |error| record.errors.add :xml, error.message end rescue Nokogiri::XML::SyntaxError => e record.errors.add :xml, "Syntax error on line #{e.line} at column #{e.column}: #{e.message}" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tim-0.3.0 | app/validators/template_validator.rb |
tim-0.2.0 | app/validators/template_validator.rb |