Sha256: 0098e23b080445d339b529cafb4e301416d1629a719612df2e0ad0329c19af19
Contents?: true
Size: 1.23 KB
Versions: 16
Compression:
Stored size: 1.23 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 private # # Ensure that the template is correct from a liquid statement # def valid_liquid_template Liquid::Template.parse(self.template).nil? rescue Exception => error self.errors.add(:template, "Invalid liquid text in template: #{error.message}") false end # # 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 end
Version data entries
16 entries across 16 versions & 1 rubygems