Skip to content
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

Add optional method to TagBuilder for morph #665

Merged
merged 1 commit into from
Sep 16, 2024

Conversation

AlexKovynev
Copy link
Contributor

continue of this #658

@AlexKovynev AlexKovynev changed the title Add optional method to TagBuilder Add optional method to TagBuilder for morph Aug 17, 2024
@@ -77,8 +77,8 @@ def remove_all(targets)
# <%= turbo_stream.replace "clearance_5" do %>
# <div id='clearance_5'>Replace the dom target identified by clearance_5</div>
# <% end %>
def replace(target, content = nil, **rendering, &block)
action :replace, target, content, **rendering, &block
def replace(target, content = nil, method = nil, **rendering, &block)

Choose a reason for hiding this comment

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

@AlexKovynev

maybe this should be a keyword argument instead of a positional argument so one can pass rendering options without specifying the method?

btw, thanks for opening this PR 🙌

Copy link
Contributor Author

@AlexKovynev AlexKovynev Aug 19, 2024

Choose a reason for hiding this comment

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

DONE

template = render_template(target, content, allow_inferred_rendering: allow_inferred_rendering, **rendering, &block)

turbo_stream_action_tag name, target: target, template: template
turbo_stream_action_tag name, target: target, template: template, **attributes_from_method(method)

Choose a reason for hiding this comment

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

I think there's no need for attributes_from_method, could simply be replaced by , method: method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DONE

@AlexKovynev AlexKovynev force-pushed the AddMethodToTagBuilder branch 4 times, most recently from e529329 to 82ae81e Compare August 19, 2024 02:46
Copy link

@mrosso10 mrosso10 left a comment

Choose a reason for hiding this comment

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

👍 🙌

Copy link

@radanskoric radanskoric left a comment

Choose a reason for hiding this comment

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

Thank you so much for opening this, I was just looking for it! :)

@@ -23,6 +23,7 @@ class Turbo::StreamsControllerTest < ActionDispatch::IntegrationTest
<turbo-stream action="replace" target="message_1"><template>#{render(message_1)}</template></turbo-stream>
<turbo-stream action="replace" target="message_1"><template>Something else</template></turbo-stream>
<turbo-stream action="replace" target="message_5"><template>Something fifth</template></turbo-stream>
<turbo-stream method="morph" action="replace" target="message_5"><template>Something fifth</template></turbo-stream>

Choose a reason for hiding this comment

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

Maybe also cover the action="update" case in exactly the same way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update not covered at all as you see but anyway added with morph :)

app/models/turbo/streams/tag_builder.rb Show resolved Hide resolved
Copy link

@radanskoric radanskoric left a comment

Choose a reason for hiding this comment

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

Looks great. 👍

@hjhart
Copy link

hjhart commented Sep 6, 2024

Looks good to me! Eager to use this functionality in my rails project shortly.

@OutlawAndy
Copy link

Thanks for this PR, @AlexKovynev

Anything in particular holding it up at this point??

@AlexKovynev
Copy link
Contributor Author

AlexKovynev commented Sep 14, 2024

@dhh can it be merged somehow please? Cause this thing now missed when morph added.

Copy link
Member

@jorgemanrubia jorgemanrubia left a comment

Choose a reason for hiding this comment

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

Thanks @AlexKovynev 🙏

@jorgemanrubia jorgemanrubia merged commit dfabcf7 into hotwired:main Sep 16, 2024
15 checks passed
@jorgemanrubia
Copy link
Member

I'll release a new version with this one later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants