Skip to content

Commit

Permalink
Merge pull request #459 from rails/flavorjones-bare-puma-support
Browse files Browse the repository at this point in the history
feat: support running the puma plugin in a bare puma process
  • Loading branch information
flavorjones authored Jan 19, 2025
2 parents b128001 + ca7812a commit b57e119
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
8 changes: 6 additions & 2 deletions lib/puma/plugin/tailwindcss.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "puma/plugin"
require "tailwindcss/commands"

Puma::Plugin.create do
attr_reader :puma_pid, :tailwind_pid, :log_writer
Expand All @@ -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

Expand Down
10 changes: 6 additions & 4 deletions lib/tailwindcss/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b57e119

Please sign in to comment.