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 using view components in rails engine #1951

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

tkowalewski
Copy link

@tkowalewski tkowalewski commented Jan 3, 2024

What are you trying to accomplish?

I'm trying to add support for generating view components in the module (engine) namespace in rails engine.
To do it we need to wrap templates code with module_namespacing (provided by rails)

How to test

  1. Create new rails engine
rails plugin new engine_with_test --mountable
  1. Update gemspec (engine_with_test.gemspec)
    Update spec.homepage
    Update spec.summary
    Update spec.description
    Update spec.metadata["source_code_uri"]
    Update spec.metadata["changelog_uri"]

  2. Add view_component to Gemfile

gem "view_component", github: "tkowalewski/view_component", branch: "component_template_with_module_namespacing"
  1. Install gems
bundle install
  1. Generate example component
bin/rails generate component Example message --preview
  1. Update component template (app/components/engine_with_test/example_component.html.erb)
<span><%= @message %></span>
  1. Uncomment test (test/components/engine_with_test/example_component_test.rb)

  2. Run tests

bin/rails test
  1. Preview component
bin/rails server

and go to http://localhost:3000/rails/view_components

What approach did you choose and why?

There is only one solution to deliver view components for rails engine with module (engine) namespace: Wrap templates code with module_namespacing :)

Anything you want to highlight for special attention from reviewers?

  • I had to prepare dummy rails engine for tests (test/dummy)
  • New rake test task (engine_test) was added to Rakefile
  • ViewComponent configuration has been extended to provide preview paths for rails engine

@boardfish boardfish linked an issue Jan 4, 2024 that may be closed by this pull request
@boardfish
Copy link
Collaborator

👋 Just a quick nudge to say #1308 means you'll need to rebase this branch for checks to pass.

@tkowalewski tkowalewski force-pushed the component_template_with_module_namespacing branch 2 times, most recently from 2c551bf to 3ba0a7c Compare January 10, 2024 17:43
@tkowalewski tkowalewski force-pushed the component_template_with_module_namespacing branch 2 times, most recently from 18c846c to 1910a72 Compare March 14, 2024 19:25
@tkowalewski tkowalewski force-pushed the component_template_with_module_namespacing branch from 1910a72 to 5c16496 Compare May 14, 2024 18:47
@tkowalewski tkowalewski changed the title WIP: Add support for using view components in rails engine Add support for using view components in rails engine May 17, 2024
@tkowalewski tkowalewski marked this pull request as ready for review May 17, 2024 09:23
@tkowalewski
Copy link
Author

@boardfish @Spone

There is problem with tests for main release of rails :|
Any plans to add support for rails 8.0.0.alpha?

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.

Rails Engine support
2 participants