Sha256: e0a3519df89e133e4d9b7c3356ded911bd2031a648c3074bfc2af59b51ecdcd5
Contents?: true
Size: 1.43 KB
Versions: 7
Compression:
Stored size: 1.43 KB
Contents
# frozen_string_literal: true module Katalyst module Content # STI base class for content items class Item < ApplicationRecord include HasStyle 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
7 entries across 7 versions & 1 rubygems