Sha256: 46570300f669791415064eb26a1455abf26954f50eb25457d7f2ce69bc4f9162
Contents?: true
Size: 733 Bytes
Versions: 9
Compression:
Stored size: 733 Bytes
Contents
module RailsCoreExtensions module ActiveRecordLiquidExtensions def self.included(base) base.extend ClassMethods end end 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
Version data entries
9 entries across 9 versions & 1 rubygems