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.1.5 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.10 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.4 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.9 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.3 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.2 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.1 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.0 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.0.pre.rc1 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.0.pre.b2 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.1.0.pre.b1 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.8 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.7 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.6 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.5 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.4 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.3 app/models/alchemy/element/dom_id.rb
alchemy_cms-6.1.9 app/models/alchemy/element/dom_id.rb
alchemy_cms-7.0.2 app/models/alchemy/element/dom_id.rb
alchemy_cms-6.1.8 app/models/alchemy/element/dom_id.rb