-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By default it 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 ```rb Alchemy::Element.dom_id_class = MyDomIdClass ```
- Loading branch information
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters