-
Notifications
You must be signed in to change notification settings - Fork 186
Implement Engines support #484
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
Changes from 1 commit
4042f0c
7d5419c
5ba881b
bcc59b5
aeeb440
e416f2d
ba504f4
a9c9841
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,40 @@ def command_env(verbose:) | |
| def rails_css_compressor? | ||
| defined?(Rails) && Rails&.application&.config&.assets&.css_compressor.present? | ||
| end | ||
|
|
||
| def engines_tailwindcss_roots | ||
| return [] unless defined?(Rails) | ||
|
|
||
| Rails::Engine.subclasses.select do |engine| | ||
| begin | ||
| spec = Gem::Specification.find_by_name(engine.engine_name) | ||
| spec.dependencies.any? { |d| d.name == 'tailwindcss-rails' } | ||
| rescue Gem::MissingSpecError | ||
| false | ||
| end | ||
| end.map do |engine| | ||
| [ | ||
| Rails.root.join("app/assets/tailwind/#{engine.engine_name}/application.css"), | ||
| engine.root.join("app/assets/tailwind/#{engine.engine_name}/application.css") | ||
| ].select(&:exist?).compact.first.to_s | ||
| end.compact | ||
| end | ||
|
|
||
| def enhance_command(command) | ||
|
||
| engine_roots = Tailwindcss::Commands.engines_tailwindcss_roots | ||
| if engine_roots.any? | ||
| Tempfile.create('tailwind.css') do |file| | ||
| file.write(engine_roots.map { |root| "@import \"#{root}\";" }.join("\n")) | ||
| file.write("\n@import \"#{Rails.root.join('app/assets/tailwind/application.css')}\";\n") | ||
| file.rewind | ||
| transformed_command = command.dup | ||
| transformed_command[2] = file.path | ||
| yield transformed_command if block_given? | ||
| end | ||
| else | ||
| yield command if block_given? | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
Gem::Specification.find_by_nameguaranteed to return spec for the version of the gem that is loaded? If there are multiple versions installed on the system, could it return the spec from an earlier or later version?I've not seen this pattern of using an engine's dependencies to control behavior, and it feels very indirect/implicit. I'm very hesitant to use this approach.
Help me understand why we shouldn't use a railtie and ask engines to be explicit/imperative? The engine, in its railtie file, should explicitly do something like:
That would greatly simplify what we do in the gem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because it's overridden by Bundler, example: