Skip to content

Add data and aria attribute expansion helpers#32

Merged
sbsoftware merged 4 commits intoreleases/v1.7.0from
feature/HTML-51
Feb 11, 2026
Merged

Add data and aria attribute expansion helpers#32
sbsoftware merged 4 commits intoreleases/v1.7.0from
feature/HTML-51

Conversation

@sbsoftware-agent
Copy link
Copy Markdown
Collaborator

@sbsoftware-agent sbsoftware-agent commented Feb 11, 2026

Summary

  • add data: / aria: container handling in AttributeHash so entries expand to data-* / aria-*
  • support value serialization for String, Bool, and numeric values; omit attributes for Nil
  • normalize container keys for symbol/string input by converting underscores to hyphens and avoiding double prefixes
  • define merge precedence so explicit data-* / aria-* attributes override data: / aria: entries
  • apply the same behavior across named args, tuple sources, array composition, and to_html_attrs
  • extend void-tag attribute composition to accept tuple sources consistently with normal tags
  • document usage and precedence with a README example

Tests

  • added spec/instance_template/data_aria_attributes_spec.cr covering:
    • basic expansion
    • type serialization and nil omission
    • merge behavior across array/tuple/to_html_attrs/named args
    • key normalization rules
  • ran:
    • CRYSTAL_CACHE_DIR=/tmp/.crystal-cache-html crystal spec
    • CRYSTAL_CACHE_DIR=/tmp/.crystal-cache-html crystal spec spec/instance_template/data_aria_attributes_spec.cr

@sbsoftware-agent sbsoftware-agent changed the title <pull request title> Add data and aria attribute expansion helpers Feb 11, 2026
Copy link
Copy Markdown
Owner

@sbsoftware sbsoftware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the whole "precedence of explicit attributes" feature bloats the code while bringing little value. Let's just implement it the least surprising way - who comes last, wins.

Comment thread spec/instance_template/data_aria_attributes_spec.cr
Comment thread src/attribute_hash.cr Outdated
Comment thread src/attribute_hash.cr Outdated
Comment thread src/attribute_hash.cr Outdated
@sbsoftware-agent
Copy link
Copy Markdown
Collaborator Author

Implemented as requested: precedence tracking was removed and merge behavior is now simple last-write-wins based on encounter order.

What changed:

  • removed explicit-priority bookkeeping and related branching from AttributeHash
  • duplicate data-* / aria-* assignments now overwrite by order, regardless of source (tuple, array, to_html_attrs, named args, data:/aria: maps)
  • updated specs to assert last-write-wins semantics
  • updated README wording/example to document last-write-wins behavior

Copy link
Copy Markdown
Owner

@sbsoftware sbsoftware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please audit the code for possible simplifications and redundancies to remove I've given one hint in a line comment, but there's probably more to discover. Try to inline code rather than using helper methods.

Comment thread src/attribute_hash.cr
@sbsoftware-agent
Copy link
Copy Markdown
Collaborator Author

Done. I audited src/attribute_hash.cr for simplifications and removed redundant helpers, favoring direct inline flow where practical.

Simplifications made:

  • inlined data/aria prefix detection in []= (removed prefixed_hash_prefix)
  • inlined hash-entry normalization/validation inside assign_prefixed_hash loops
  • removed assign_prefixed_hash_entry
  • removed normalize_prefixed_hash_key and normalize_prefixed_hash_key_part
  • removed serialize_prefixed_value and replaced with direct assign_prefixed_value overloads (Nil delete vs generic to_s assign)

Validation:

  • CRYSTAL_CACHE_DIR=/tmp/.crystal-cache-html crystal spec (37 examples, 0 failures)

Committed as 181b2f4.

Comment thread src/attribute_hash.cr Outdated
Comment thread src/attribute_hash.cr Outdated
@sbsoftware sbsoftware merged commit 9384304 into releases/v1.7.0 Feb 11, 2026
@sbsoftware sbsoftware deleted the feature/HTML-51 branch February 11, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants