Skip to content

Commit

Permalink
feat: support running the puma plugin in a bare puma process
Browse files Browse the repository at this point in the history
that is, not in `rails server`.

Closes #458
  • Loading branch information
flavorjones committed Jan 19, 2025
1 parent b128001 commit de2aac5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ While you're developing your application, you want to run Tailwind in "watch" mo

#### Puma plugin

This gem ships with a Puma plugin. To use it, add this line to your `puma.rb` configuration:
This gem ships with a Puma plugin. To use it, add this to your `puma.rb` configuration:

```ruby
require_relative "application"
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

0 comments on commit de2aac5

Please sign in to comment.