Skip to content

Commit b57e119

Browse files
authored
Merge pull request #459 from rails/flavorjones-bare-puma-support
feat: support running the puma plugin in a bare puma process
2 parents b128001 + ca7812a commit b57e119

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## next / unreleased
22

3+
## v3.3.0 / unreleased
4+
5+
* Add support for running the puma plugin outside of `rails server`. (#458) @flavorjones
6+
7+
38
## v3.2.0 / 2025-01-10
49

510
* 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 for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ This gem ships with a Puma plugin. To use it, add this line to your `puma.rb` co
124124
plugin :tailwindcss if ENV.fetch("RAILS_ENV", "development") == "development"
125125
```
126126

127-
and then running `rails server` will run the Tailwind watch process in the background
127+
and then running `rails server` (or just `puma`) will run the Tailwind watch process in the background.
128128

129129

130130
#### Run `rails tailwindcss:watch`

Diff for: lib/puma/plugin/tailwindcss.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "puma/plugin"
2+
require "tailwindcss/commands"
23

34
Puma::Plugin.create do
45
attr_reader :puma_pid, :tailwind_pid, :log_writer
@@ -11,8 +12,11 @@ def start(launcher)
1112
# Using IO.popen(command, 'r+') will avoid watch_command read from $stdin.
1213
# If we use system(*command) instead, IRB and Debug can't read from $stdin
1314
# correctly bacause some keystrokes will be taken by watch_command.
14-
IO.popen(Tailwindcss::Commands.watch_command, 'r+') do |io|
15-
IO.copy_stream(io, $stdout)
15+
begin
16+
IO.popen(Tailwindcss::Commands.watch_command, 'r+') do |io|
17+
IO.copy_stream(io, $stdout)
18+
end
19+
rescue Interrupt
1620
end
1721
end
1822

Diff for: lib/tailwindcss/commands.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ module Tailwindcss
44
module Commands
55
class << self
66
def compile_command(debug: false, **kwargs)
7+
rails_root = defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd)
8+
79
command = [
810
Tailwindcss::Ruby.executable(**kwargs),
9-
"-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s,
10-
"-o", Rails.root.join("app/assets/builds/tailwind.css").to_s,
11-
"-c", Rails.root.join("config/tailwind.config.js").to_s,
11+
"-i", rails_root.join("app/assets/stylesheets/application.tailwind.css").to_s,
12+
"-o", rails_root.join("app/assets/builds/tailwind.css").to_s,
13+
"-c", rails_root.join("config/tailwind.config.js").to_s,
1214
]
1315

1416
command << "--minify" unless (debug || rails_css_compressor?)
1517

16-
postcss_path = Rails.root.join("config/postcss.config.js")
18+
postcss_path = rails_root.join("config/postcss.config.js")
1719
command += ["--postcss", postcss_path.to_s] if File.exist?(postcss_path)
1820

1921
command

0 commit comments

Comments
 (0)