Sha256: 2f40f3e2a3d7f80d571a7ce53c88afd5391828f8f8b01323e4fb8750c53565b3

Contents?: true

Size: 799 Bytes

Versions: 59

Compression:

Stored size: 799 Bytes

Contents

# frozen_string_literal: true

module Alchemy
  module DomIds
    extend ActiveSupport::Concern

    RESERVED_ANCHOR_SETTING_VALUES = %w[false from_value true]

    included do
      before_validation :parameterize_dom_id,
        if: -> { settings[:anchor].to_s == "true" }
      before_validation :set_dom_id_from_value,
        if: -> { settings[:anchor].to_s == "from_value" }
      before_validation :set_dom_id_to_fixed_value,
        if: -> { !RESERVED_ANCHOR_SETTING_VALUES.include? settings[:anchor].to_s }
    end

    private

    def parameterize_dom_id
      self.dom_id = dom_id&.parameterize
    end

    def set_dom_id_from_value
      self.dom_id = value&.parameterize
    end

    def set_dom_id_to_fixed_value
      self.dom_id = settings[:anchor]&.parameterize
    end
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

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