Skip to content

Comma-separated tokens #904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 8, 2025
Merged

Comma-separated tokens #904

merged 5 commits into from
May 8, 2025

Conversation

joeldrapper
Copy link
Collaborator

@joeldrapper joeldrapper commented May 7, 2025

Implementation of #882

Comment on lines 5 to 9
img: <<~RUBY,
if (tokens = attributes[:srcset])
attributes[:srcset] = __nested_tokens__(tokens, ", ")
end
RUBY
Copy link
Collaborator Author

@joeldrapper joeldrapper May 7, 2025

Choose a reason for hiding this comment

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

The technique here is to generate specifically optimised code to check and pre-process the comma-separated-lists before caching takes place. We could cache this step separately but I don’t think it’s worth it.

@@ -23,6 +56,7 @@ def #{method_name}(**attributes)
if block_given # with content block
buffer << "<#{tag}"
begin
#{COMMA_SEPARATED_TOKENS[method_name]}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This outputs nothing for most elements and otherwise outputs the code to pre-process one or two values if they exist before caching.

@joeldrapper joeldrapper requested a review from willcosgrove May 7, 2025 23:24
Copy link
Contributor

@willcosgrove willcosgrove left a comment

Choose a reason for hiding this comment

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

Concept ACK. I like this approach a lot. It's nice that it only adds the overhead to elements that may use it. I left a few typo fixes.

@joeldrapper joeldrapper marked this pull request as ready for review May 8, 2025 09:44
@joeldrapper joeldrapper merged commit d4f1d8f into main May 8, 2025
13 checks passed
@joeldrapper joeldrapper deleted the comma-sep-lists branch May 8, 2025 09:48
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