Sha256: c7f41afb132f703d6f3d6749efaa29966070a27950ddd979c23716f3da4eb934
Contents?: true
Size: 1.22 KB
Versions: 33
Compression:
Stored size: 1.22 KB
Contents
# # Base template object for managing all communications templates # class Template include StandardModel # # Fields # field :name, type: String field :template, type: String # # Relationships # belongs_to :account, inverse_of: :templates # # Validations # validates :name, uniqueness: { scope: :account_id } validates :name, presence: true validates :template, presence: true validate :valid_liquid_template # # Retrieve the template out of the project # def self.from_file(template_name, format: 'liquid', prefix: nil, delivery_channel: 'email') file_name = [template_name, prefix, format].compact.join('.') if File.exist?(Rails.root.join('lib/templates', delivery_channel, file_name)) File.open(Rails.root.join('lib/templates', delivery_channel, file_name)) else File.open(File.join(__dir__, '../../../lib/templates', delivery_channel, file_name)) end.read rescue StandardError nil end private # # Ensure that the template is correct from a liquid statement # def valid_liquid_template Liquid::Template.parse(template).nil? rescue StandardError => error errors.add(:template, "Invalid liquid text in template: #{error.message}") false end end
Version data entries
33 entries across 33 versions & 1 rubygems