Class: MJMLSyntaxValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- MJMLSyntaxValidator
- Defined in:
- app/validators/mjml_syntax_validator.rb
Overview
Validator to check for MJML syntax errors in MJML template files
Instance Method Summary collapse
Instance Method Details
#validate(record) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/validators/mjml_syntax_validator.rb', line 11 def validate( record ) file = Tempfile.new [ 'shinycms-', '.mjml' ] file.write record.file_content_with_erb_removed file.rewind valid = system "node_modules/mjml/bin/mjml --validate #{file.path} 2>/dev/null" file.delete record.errors.add( :filename, :invalid_mjml ) unless valid end |