-
Notifications
You must be signed in to change notification settings - Fork 185
Implement Engines Support #554
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
d50dae4
9765895
430e611
a253d67
f3772d6
8a332fb
656913d
3b1f4f2
279c929
7fca4ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Tailwindcss | ||
module Engines | ||
class << self | ||
def bundle | ||
FileUtils.mkdir_p(Rails.root.join("app/assets/builds/tailwind")) | ||
Rails::Engine.subclasses.select do |engine| | ||
engine.root.join("app/assets/tailwind/#{engine.engine_name}/application.css").exist? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming this file "application.css" seems odd given it's the CSS for an engine (not an application). Why not "#{engine_name}/engine.css"? I don't feel strongly about it, just curious. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call, it'll reduce the chances that the developer will mix app/engine files. Done and tested on local. |
||
end.each do |engine| | ||
file_path = Rails.root.join("app/assets/builds/tailwind/#{engine.engine_name}.css") | ||
flavorjones marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FileUtils.rm(file_path) if File.exist?(file_path) | ||
template = <<~TEMPLATE | ||
/* DO NOT MODIFY THIS FILE, it was auto-generated by tailwindcss-rails */ | ||
|
||
@import "#{engine.root.join("app/assets/tailwind/#{engine.engine_name}/application.css")}"; | ||
TEMPLATE | ||
File.open(file_path, 'w') do |file| | ||
file.puts template | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require "test_helper" | ||
require "minitest/mock" | ||
|
||
class Tailwindcss::EngineTest < ActiveSupport::TestCase | ||
def setup | ||
super | ||
# Store original Rails state | ||
@original_rails_root = Rails.root | ||
@original_application = Rails.application | ||
end | ||
|
||
def teardown | ||
super | ||
# Restore original Rails state | ||
Rails.application = @original_application if @original_application | ||
end | ||
|
||
test "after_initialize calls Tailwindcss::Engines.bundle" do | ||
called = false | ||
|
||
# Replace bundle method with our spy | ||
Tailwindcss::Engines.stub(:bundle, ->{ called = true }) do | ||
# Execute the after_initialize block | ||
Rails.stub(:root, File) do | ||
engine_file = File.join(File.dirname(__FILE__), "../../../lib/tailwindcss/engine.rb") | ||
engine_code = File.read(engine_file) | ||
|
||
# Verify that the after_initialize block calls Engines.bundle | ||
assert_match(/config\.after_initialize do.*?Tailwindcss::Engines\.bundle.*?end/m, engine_code, | ||
"Expected after_initialize block to call Tailwindcss::Engines.bundle") | ||
|
||
# Call bundle to verify our spy works | ||
Tailwindcss::Engines.bundle | ||
assert called, "Expected Tailwindcss::Engines.bundle to be called" | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this test is meaningful. I would remove it and either
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked over |
||
end |
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.
This is wrapped incorrectly, probably because the linting tool you're using is paying attention to the incorrect code block type
html
. It should beruby
.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.
I suspect it's ToC update that did it. Corrected.