Sha256: db10349f08d4a7ca7436cc7bbafa19064e1e4c4d884bf960f7a7cceac19461a1

Contents?: true

Size: 760 Bytes

Versions: 6

Compression:

Stored size: 760 Bytes

Contents

# frozen_string_literal: true

module Archangel
  ##
  # Template model
  #
  class Template < ApplicationRecord
    acts_as_paranoid

    validates :content, presence: true
    validates :name, presence: true
    validates :partial, inclusion: { in: [true, false] }

    validate :valid_liquid_content

    belongs_to :parent, -> { where(partial: false) },
               class_name: "Archangel::Template",
               optional: true
    belongs_to :site

    protected

    def valid_liquid_content
      return if valid_liquid_content?

      errors.add(:content, Archangel.t(:liquid_invalid))
    end

    def valid_liquid_content?
      ::Liquid::Template.parse(content)

      true
    rescue ::Liquid::SyntaxError => _e
      false
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
archangel-0.0.7 app/models/archangel/template.rb
archangel-0.0.6 app/models/archangel/template.rb
archangel-0.0.5 app/models/archangel/template.rb
archangel-0.0.4 app/models/archangel/template.rb
archangel-0.0.3 app/models/archangel/template.rb
archangel-0.0.2 app/models/archangel/template.rb