Skip to content

Support component generator for tailwindcss-rails#1098

Merged
Spone merged 1 commit intoViewComponent:mainfrom
dixpac:dix/tailwind_css
Jan 5, 2022
Merged

Support component generator for tailwindcss-rails#1098
Spone merged 1 commit intoViewComponent:mainfrom
dixpac:dix/tailwind_css

Conversation

@dixpac
Copy link
Contributor

@dixpac dixpac commented Oct 14, 2021

This commit adds support for tailwindcss-rails engine.

This is my first contribution so I hope I did this correctly.
I've spinend up demo app with view_component and tailwindcss-railsand it works.
But, I may have missed something :)

@dixpac dixpac requested a review from a team as a code owner October 14, 2021 15:21
@joelhawksley joelhawksley requested a review from Spone October 14, 2021 15:51
@joelhawksley
Copy link
Member

@dixpac thank you for your contribution! @Spone has handled code reviews for generators in the past, so I've passed this one to him ❤️

@Spone
Copy link
Collaborator

Spone commented Oct 14, 2021

Hi @dixpac! Thanks for your PR! I'm not much of a Tailwind user, can you elaborate on what's the expected behavior for the generator? I read the diff quickly and I'm not sure I understand how this differs from the regular generator?

@dixpac
Copy link
Contributor Author

dixpac commented Oct 14, 2021

Yeah, it is pretty much the default rails generator with tailwindcss templates.
We had to "monkey-patch/copy" it in order to support partials in Rails 6 --> https://github.com/rails/tailwindcss-rails/blob/main/lib/generators/tailwindcss/scaffold/scaffold_generator.rb#L25

Inside the engine, template name is tailwindcss so when folks are using it together with view_component they get an error
error tailwindcss [not found] when generating the component.

Generator just needs to create same files as with erb generators :)

I hope this helps :)

@toddsiegel
Copy link

This would certainly be useful for those of us using tailwindcss-rails.

For others using view_component and tailwindcss-rails this workaround will keep you going.

$ bin/rails g component <Name> --template-engine=erb

@Spone
Copy link
Collaborator

Spone commented Nov 11, 2021

@dixpac can you please rebase to resolve the conflicts, and try to fix the tests that do not pass for Rails 5?

@dixpac
Copy link
Contributor Author

dixpac commented Nov 12, 2021

@Spone sure I will try. Rails 5 will be a bit harder since tw-rails is rails >= 6, but we will make it work somehow :)

@vsppedro
Copy link
Contributor

vsppedro commented Dec 2, 2021

What do you think about using Appraisal?

You will be able to install tailwindcss-rails only for rails 6.

@joelhawksley
Copy link
Member

👋🏻 I think it's worth pursuing conditionally adding this support only in Rails >= 6, as long as we make it clear in the documentation. The Rails asset delivery story has certainly changed a bit from 5>6>7 and I think it's not unreasonable to expect folks to be reasonably up to date to use this functionality.

@Spone Spone force-pushed the dix/tailwind_css branch 3 times, most recently from 081de18 to 4f674de Compare December 7, 2021 21:59
@Spone
Copy link
Collaborator

Spone commented Dec 7, 2021

I tried this without success (works locally, but not in CI).

@joelhawksley would you be open to adding Appraisal? I think it's the cleanest way to implement conditional dependencies. It would also make locally running tests for all versions of Rails much easier.

@joelhawksley
Copy link
Member

@Spone I'm totally fine with adding Appraisal ❤️

@Spone Spone linked an issue Dec 10, 2021 that may be closed by this pull request
@pboling
Copy link

pboling commented Dec 14, 2021

@Spone Worth noting that there may be complexity getting Appraisal to fully work with Github Actions: thoughtbot/appraisal#174 (comment)
I'm slowly, painfully, ripping it out of my gems due to not getting it to run with Github Actions.

@Spone
Copy link
Collaborator

Spone commented Dec 15, 2021

@pboling I haven't looked into it in detail yet, but I know we're using Appraisal + Github Actions to test https://github.com/pantographe/view_component-form without issues.

@coder2000
Copy link

Is still useful with the new tailwindcss-rails?

@dixpac
Copy link
Contributor Author

dixpac commented Dec 21, 2021

@coder2000 yes. If you want to "attack" adding Appraisal that would be awesome

@Spone Spone mentioned this pull request Dec 30, 2021
@Spone
Copy link
Collaborator

Spone commented Jan 5, 2022

Hi @dixpac, Appraisal is now setup and I used it in your PR to manage the conditional dependency to tailwindcss-rails.

@dixpac
Copy link
Contributor Author

dixpac commented Jan 5, 2022

👏🏼 @Spone thank you! I'll bump and resolve the conflict

This commit adds support for [`tailwindcss-rails](https://github.com/rails/tailwindcss-rails)` engine.

This is my first contribution so I hope I did this correctly.
I've spinend up demo app with `view_component` and `tailwindcss-rails`
and it works. But, I may have missed something :)

Co-authored-by: Hans Lemuet <38524+Spone@users.noreply.github.com>
@dixpac
Copy link
Contributor Author

dixpac commented Jan 5, 2022

@Spone version bumped, conflicts fixed, squashed and I've added you as a co-author :)


gem "capybara", "~> 3"
gem "rails", "~> 6.0.0"
gem "tailwindcss-rails", "~> 2.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think 2 as a dependency is what we are looking for, since tailwindcss-rails version 1 was not complete and it was missing some of the major tailwindcss parts. That is solved with version 2, so I can't really see anyone using version 1 :)

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.

Generator failing for rails 7.0.0.rc1 + tailwind

7 participants