diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f07f0c4..00a78f83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## next / unreleased +## v3.3.0 / unreleased + +* Add support for running the puma plugin outside of `rails server`. (#458) @flavorjones + + ## v3.2.0 / 2025-01-10 * Improve the scaffold views by making positions, padding, and sizes more consistent, add titles to all pages, add hover states and semantic colors to buttons and links, and change border and focus colors on fields with errors. (#452) @patriciomacadden diff --git a/README.md b/README.md index 60b2f27e..e81a5474 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ This gem ships with a Puma plugin. To use it, add this line to your `puma.rb` co plugin :tailwindcss if ENV.fetch("RAILS_ENV", "development") == "development" ``` -and then running `rails server` will run the Tailwind watch process in the background +and then running `rails server` (or just `puma`) will run the Tailwind watch process in the background. #### Run `rails tailwindcss:watch` diff --git a/lib/puma/plugin/tailwindcss.rb b/lib/puma/plugin/tailwindcss.rb index e614d62a..4624d7e8 100644 --- a/lib/puma/plugin/tailwindcss.rb +++ b/lib/puma/plugin/tailwindcss.rb @@ -1,4 +1,5 @@ require "puma/plugin" +require "tailwindcss/commands" Puma::Plugin.create do attr_reader :puma_pid, :tailwind_pid, :log_writer @@ -11,8 +12,11 @@ def start(launcher) # Using IO.popen(command, 'r+') will avoid watch_command read from $stdin. # If we use system(*command) instead, IRB and Debug can't read from $stdin # correctly bacause some keystrokes will be taken by watch_command. - IO.popen(Tailwindcss::Commands.watch_command, 'r+') do |io| - IO.copy_stream(io, $stdout) + begin + IO.popen(Tailwindcss::Commands.watch_command, 'r+') do |io| + IO.copy_stream(io, $stdout) + end + rescue Interrupt end end diff --git a/lib/tailwindcss/commands.rb b/lib/tailwindcss/commands.rb index 26c5178a..40d983a6 100644 --- a/lib/tailwindcss/commands.rb +++ b/lib/tailwindcss/commands.rb @@ -4,16 +4,18 @@ module Tailwindcss module Commands class << self def compile_command(debug: false, **kwargs) + rails_root = defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd) + command = [ Tailwindcss::Ruby.executable(**kwargs), - "-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s, - "-o", Rails.root.join("app/assets/builds/tailwind.css").to_s, - "-c", Rails.root.join("config/tailwind.config.js").to_s, + "-i", rails_root.join("app/assets/stylesheets/application.tailwind.css").to_s, + "-o", rails_root.join("app/assets/builds/tailwind.css").to_s, + "-c", rails_root.join("config/tailwind.config.js").to_s, ] command << "--minify" unless (debug || rails_css_compressor?) - postcss_path = Rails.root.join("config/postcss.config.js") + postcss_path = rails_root.join("config/postcss.config.js") command += ["--postcss", postcss_path.to_s] if File.exist?(postcss_path) command