Sha256: 4d03e9090880010d53cf26409ee760ae875c85a9a55675a7e4652306d9e9c25d

Contents?: true

Size: 916 Bytes

Versions: 2

Compression:

Stored size: 916 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

    ##
    # Return string of partial status.
    #
    # @return [String] partial status
    #
    def status
      partial? ? "partial" : "full"
    end

    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

2 entries across 2 versions & 1 rubygems

Version Path
archangel-0.3.0 app/models/archangel/template.rb
archangel-0.0.8 app/models/archangel/template.rb