Sha256: f2dd1aaa62c2b1aa0c1a30ae2b6726f5f9ccf262ce904f36a926a9ded4c8bed9

Contents?: true

Size: 1.34 KB

Versions: 47

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Alchemy
  class Element < BaseRecord
    # Module concerning element definitions
    #
    module Definitions
      extend ActiveSupport::Concern

      module ClassMethods
        # Register a custom element definitions repository
        #
        # The default repository is Alchemy::ElementDefinition
        #
        def definitions_repository=(klass)
          @_definitions_repository = klass
        end

        # Returns the definitions from elements.yml file.
        #
        # Place a +elements.yml+ file inside your apps +config/alchemy+ folder to define
        # your own set of elements
        #
        def definitions
          definitions_repository.all
        end

        # Returns one element definition by given name.
        #
        def definition_by_name(name)
          definitions_repository.get(name)
        end

        private

        def definitions_repository
          @_definitions_repository ||= ElementDefinition
        end
      end

      # The definition of this element.
      #
      def definition
        if (definition = self.class.definition_by_name(name))
          definition
        else
          log_warning "Could not find element definition for #{name}. " \
                      "Please check your elements.yml file!"
          {}
        end
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
alchemy_cms-7.3.4 app/models/alchemy/element/definitions.rb
alchemy_cms-7.3.3 app/models/alchemy/element/definitions.rb
alchemy_cms-7.3.2 app/models/alchemy/element/definitions.rb
alchemy_cms-7.2.7 app/models/alchemy/element/definitions.rb
alchemy_cms-7.3.1 app/models/alchemy/element/definitions.rb
alchemy_cms-7.3.0 app/models/alchemy/element/definitions.rb
alchemy_cms-7.2.6 app/models/alchemy/element/definitions.rb
alchemy_cms-7.2.5 app/models/alchemy/element/definitions.rb
alchemy_cms-7.1.12 app/models/alchemy/element/definitions.rb
alchemy_cms-7.0.15 app/models/alchemy/element/definitions.rb
alchemy_cms-7.2.4 app/models/alchemy/element/definitions.rb
alchemy_cms-7.1.11 app/models/alchemy/element/definitions.rb
alchemy_cms-7.2.3 app/models/alchemy/element/definitions.rb
alchemy_cms-7.1.10 app/models/alchemy/element/definitions.rb
alchemy_cms-7.2.2 app/models/alchemy/element/definitions.rb
alchemy_cms-7.1.9 app/models/alchemy/element/definitions.rb
alchemy_cms-7.0.14 app/models/alchemy/element/definitions.rb
alchemy_cms-7.2.1 app/models/alchemy/element/definitions.rb
alchemy_cms-7.0.13 app/models/alchemy/element/definitions.rb
alchemy_cms-7.1.8 app/models/alchemy/element/definitions.rb