Sha256: b361eaf8fac45d0b4515ef8d6102d2b98576e174db201304cb36297d8dbe4af5
Contents?: true
Size: 744 Bytes
Versions: 4
Compression:
Stored size: 744 Bytes
Contents
module RailsCoreExtensions module ActiveRecordLiquidExtensions extend ActiveSupport::Concern module ClassMethods def validates_liquid(field) field = field.to_sym before_validation do |record| begin Liquid::Template.parse(record.send(field), error_mode: :strict) rescue Liquid::SyntaxError => e record.errors.add(field, "Liquid Syntax Error: #{e}") end end end def liquid_field(field) class_eval <<-CODE def parsed_#{field} Liquid::Template.parse(#{field}) end def render_#{field}(*args) parsed_#{field}.render!(*args) end CODE end end end end
Version data entries
4 entries across 4 versions & 1 rubygems