Skip to content

fix: add support for spreading non-string attribute values in RenderAttributes#1213

Merged
a-h merged 7 commits intomainfrom
fix/issue-1212-numeric-attributes-copilot
Jul 6, 2025
Merged

fix: add support for spreading non-string attribute values in RenderAttributes#1213
a-h merged 7 commits intomainfrom
fix/issue-1212-numeric-attributes-copilot

Conversation

@a-h
Copy link
Copy Markdown
Owner

@a-h a-h commented Jul 3, 2025

Add support for all numeric types (ints, uints, floats, complex) in RenderAttributes function.

Changes

  • Add support for all numeric types from the stringable interface in RenderAttributes
  • Use fmt.Sprint to convert numeric values to strings before rendering
  • Add comprehensive unit tests for RenderAttributes function
  • Add integration test for numeric attribute types in spread attributes

Problem

Previously, only string and boolean values were rendered when using spread attributes. Numeric values like integers and floats were ignored.

Solution

Extended the switch statement in RenderAttributes to handle all types from the stringable interface by converting them to strings using fmt.Sprint().

Testing

  • All existing tests pass
  • New unit tests verify numeric type handling
  • Integration test confirms end-to-end functionality

Fixes #1212

…ttributes

- Add support for all numeric types (ints, uints, floats, complex) in RenderAttributes
- Use fmt.Sprint to convert numeric values to strings before rendering
- Add comprehensive unit tests for RenderAttributes function
- Add integration test for numeric attribute types in spread attributes
- Fixes issue where only string/bool values were rendered in spread attributes

Fixes #1212
a-h added 4 commits July 3, 2025 11:25
- Remove unnecessary section comments from RenderAttributes
- Add t.Parallel() to make tests run in parallel
- Format code with go fmt
Use the existing generic ptr[T any] function instead of specific
stringPtr and boolPtr functions to reduce code duplication.
- Add support for int, uint, float, and complex types in RenderAttributes
- Add comprehensive unit tests for all numeric attribute types
- Add integration test for numeric attribute spreading
- Use generic ptr function for test pointer helpers
- All tests run in parallel and pass

Fixes #1212
@a-h a-h merged commit 732862b into main Jul 6, 2025
9 checks passed
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.

Add support for spreading non-string attribute values in templ.RenderAttributes

2 participants