Sha256: 4a061c2883fe8e80a99378c5d319d706575e02da4f64d862b70eed9729da2d90

Contents?: true

Size: 714 Bytes

Versions: 54

Compression:

Stored size: 714 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
  #
  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

54 entries across 54 versions & 1 rubygems

Version Path
alchemy_cms-7.2.7 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.2.6 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.2.5 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.12 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.15 app/models/alchemy/element/dom_id.rb
alchemy_cms-6.1.10 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.2.4 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.11 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.2.3 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.10 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.2.2 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.9 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.14 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.2.1 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.13 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.8 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.7 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.12 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.11 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.6 app/models/alchemy/element/dom_id.rb