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 support for Rails view components #644

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

budu
Copy link
Contributor

@budu budu commented Dec 6, 2024

View components are using a block to be able to render slots.

@tagliala
Copy link
Contributor

tagliala commented Dec 6, 2024

Thanks, can you please add a spec?

@budu budu force-pushed the render-with-block branch from f7070fc to 481a99e Compare December 6, 2024 18:33
View components are using a block to be able to render slots.
@budu budu force-pushed the render-with-block branch from 481a99e to 4a28ea6 Compare December 6, 2024 18:39
@budu
Copy link
Contributor Author

budu commented Dec 6, 2024

Done.

I wasn't sure how to fake the component here, so I went with an anonymous class.

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.31%. Comparing base (5526517) to head (4a28ea6).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #644   +/-   ##
=======================================
  Coverage   94.31%   94.31%           
=======================================
  Files          17       17           
  Lines         457      457           
=======================================
  Hits          431      431           
  Misses         26       26           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tagliala tagliala requested a review from javierjulio December 6, 2024 21:02
@javierjulio
Copy link
Member

@budu can you please provide more information about what you are trying to do here and how this would be used? It's not clear if you are referring to view components as a general thing from Arbre's perspective or something specific to Rails. We'll also include this PR in the release notes so it would help to have background and examples on what this provides. Thank you.

@budu
Copy link
Contributor Author

budu commented Dec 9, 2024

In my use case, it's to support ViewComponent's slots feature. For example:

render BlogComponent.new do |component|
  component.with_header do
    link_to "My blog", root_path
  end
  BlogPost.all.each do |blog_post|
    component.with_post do
      link_to blog_post.name, blog_post.url
    end
  end
end

This allows the render helper to pass-in the view context along with the block to the component.

ViewComponent was using a monkey patch before Rails 6.1. The render helper from ActionView was changed in this commit to accomodate the render_in back in 2019.

@javierjulio javierjulio changed the title Add support for view components Add support for Rails view components Dec 9, 2024
Copy link
Member

@javierjulio javierjulio left a comment

Choose a reason for hiding this comment

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

Thanks!

@tagliala tagliala merged commit 66e6c0b into activeadmin:master Dec 9, 2024
17 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.

3 participants