app/validators/template_validator.rb in tim-0.1.2 vs app/validators/template_validator.rb in tim-0.2.0
- old
+ new
@@ -2,14 +2,18 @@
class TemplateValidator < ActiveModel::Validator
@@template_rng = File.join(Tim::Engine.root, "config/schemas", "tdl.rng")
def validate(record)
- rng = Nokogiri::XML::RelaxNG(File.read(@@template_rng))
- xml = Nokogiri::XML(record.xml) { |config| config.strict }
+ 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
+ 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
\ No newline at end of file