Sha256: d12ab5b557b186e17ae7ca72253567de033f45ad01cdde44a3930a7652d05aee
Contents?: true
Size: 1.41 KB
Versions: 17
Compression:
Stored size: 1.41 KB
Contents
# frozen_string_literal: true module Katalyst module Content # STI base class for content items class Item < ApplicationRecord def self.config Katalyst::Content.config end enum heading_style: config.heading_styles, _prefix: :heading belongs_to :container, polymorphic: true validates :heading, presence: true validates :heading_style, inclusion: { in: config.heading_styles } validates :background, presence: true, inclusion: { in: config.backgrounds }, if: :validate_background? after_initialize :initialize_tree before_validation :set_defaults attr_accessor :parent, :children, :index, :depth def self.permitted_params %i[ container_type container_id type heading heading_style background visible ] end def to_plain_text heading if show_heading? && visible? end def show_heading? !heading_none? end def heading_style_class heading_style unless heading_default? end def layout? is_a? Layout end private def initialize_tree self.parent ||= nil self.children ||= [] end def set_defaults self.heading_style = "none" if heading_style.blank? end def validate_background? true end end end end
Version data entries
17 entries across 17 versions & 1 rubygems