Sha256: aa0d763564a0d2cdb2f2a8a6d88f60fe8c41fffad8db7779f82eee72882764e4

Contents?: true

Size: 785 Bytes

Versions: 5

Compression:

Stored size: 785 Bytes

Contents

# frozen_string_literal: true

module Alchemy
  # Returns a dom id used for elements html id tag.
  #
  # Uses the elements name and its position on the page.
  # If the element is nested in a parent element it prefixes
  # the id with the parent elements dom_id.
  #
  # Register your own dom id class with
  #
  #  Alchemy::Element.dom_id_class = MyDomIdClass
  #
  # @deprecated Use a headline ingredient with anchor setting instead.
  class Element < BaseRecord
    class DomId
      def initialize(element)
        @element = element
        @parent_element = element.parent_element
      end

      def call
        [parent_element&.dom_id, element.name, element.position].compact.join("-")
      end

      private

      attr_reader :element, :parent_element
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alchemy_cms-7.3.4 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.3.3 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.3.2 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.3.1 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.3.0 app/models/alchemy/element/dom_id.rb