Module: Cadmus::Concerns::LiquidTemplateField::ClassMethods
- Defined in:
- lib/cadmus/concerns/liquid_template_field.rb
Instance Method Summary collapse
- #liquid_template_field(method_name, field_name) ⇒ Object
- #validates_template_validity(field_name) ⇒ Object
Instance Method Details
#liquid_template_field(method_name, field_name) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cadmus/concerns/liquid_template_field.rb', line 7 def liquid_template_field(method_name, field_name) define_method method_name do content = send(field_name) begin Liquid::Template.parse(content) rescue Exception => exception Liquid::Template.parse("#{exception.class.name}: #{exception.}") end end end |
#validates_template_validity(field_name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cadmus/concerns/liquid_template_field.rb', line 19 def validates_template_validity(field_name) validate do |model| content = model.send(field_name) begin Liquid::Template.parse(content) rescue Exception => exception model.errors.add(field_name, "failed to parse: #{exception.class.name}: #{exception.}") end end end |