tailwindcss-rails 2.0.29 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -9
- data/lib/generators/tailwindcss/controller/controller_generator.rb +2 -1
- data/lib/generators/tailwindcss/mailer/mailer_generator.rb +2 -1
- data/lib/generators/tailwindcss/mailer/templates/layout.html.erb.tt +13 -0
- data/lib/generators/tailwindcss/mailer/templates/layout.text.erb.tt +1 -0
- data/lib/generators/tailwindcss/scaffold/scaffold_generator.rb +3 -2
- data/lib/generators/tailwindcss/scaffold/templates/_form.html.erb.tt +1 -1
- data/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt +1 -1
- data/lib/generators/tailwindcss/scaffold/templates/new.html.erb.tt +1 -1
- data/lib/generators/tailwindcss/scaffold/templates/partial.html.erb.tt +1 -1
- data/lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt +3 -3
- data/lib/install/Procfile.dev +1 -1
- data/lib/install/dev +8 -0
- data/lib/puma/plugin/tailwindcss.rb +63 -0
- data/lib/tailwindcss/commands.rb +12 -6
- data/lib/tailwindcss/upstream.rb +1 -1
- data/lib/tailwindcss/version.rb +1 -1
- data/lib/tasks/build.rake +2 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f14bac83bc6a8df8bba207524b748c4f9a1a7689b012b3495814af1276e51172
|
4
|
+
data.tar.gz: 5714edc137dee618ea34462f1c0033d2bf6cafda8180e0448a6a15aea9ae3ab9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b8e7c71d76761ca29c57bdcfee4d41c585ce8b8fef60186e251689999a93354b2b9603bb9b3f0c6ec796f2478fbe1fcff172014793772e8f46628976c0b535f
|
7
|
+
data.tar.gz: 1a68c451d9f716e7788ec72d9dc726383d9b9f3bd7a5b261997cf5ef60b75fe75632113f4cb549dbc699e053f24999f49056091ac7709f9890da6024f3495134
|
data/README.md
CHANGED
@@ -38,7 +38,6 @@ This also works with relative paths. If you've installed into your app's directo
|
|
38
38
|
TAILWINDCSS_INSTALL_DIR=node_modules/.bin
|
39
39
|
```
|
40
40
|
|
41
|
-
|
42
41
|
## Developing with Tailwindcss
|
43
42
|
|
44
43
|
### Configuration
|
@@ -55,20 +54,31 @@ The `tailwindcss:build` is automatically attached to `assets:precompile`, so bef
|
|
55
54
|
|
56
55
|
### Building for testing
|
57
56
|
|
58
|
-
The `tailwindcss:build` task is automatically attached to the `test:prepare` Rake task.
|
57
|
+
The `tailwindcss:build` task is automatically attached to the `test:prepare` Rake task. This task runs before test commands. If you run `bin/rails test` in your CI environment, your Tailwind output will be generated before tests run.
|
59
58
|
|
60
|
-
If your tests need Tailwind assets in your CI environment, it's best to be explicit and run this command:
|
61
59
|
|
62
|
-
|
63
|
-
|
60
|
+
### Update assets automatically
|
61
|
+
|
62
|
+
While you're developing your application, you want to run Tailwind in "watch" mode, so changes are automatically reflected in the generated CSS output. You can do this in a few different ways:
|
63
|
+
|
64
|
+
- use the [Puma](https://puma.io/) plugin to integrate "watch" with `rails server`, or
|
65
|
+
- run `rails tailwindcss:watch` as a separate process, or
|
66
|
+
- run `bin/dev` which uses [Foreman](https://github.com/ddollar/foreman)
|
67
|
+
|
68
|
+
#### Puma plugin
|
69
|
+
|
70
|
+
The Puma plugin requires you to add this line to your `puma.rb` configuration:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
plugin :tailwindcss if ENV.fetch("RAILS_ENV", "development") == "development"
|
64
74
|
```
|
65
75
|
|
66
|
-
|
76
|
+
and then running `rails server` will run the Tailwind watch process in the background
|
67
77
|
|
68
|
-
While you're developing your application, you want to run Tailwind in "watch" mode, so changes are automatically reflected in the generated CSS output. You can do this by:
|
69
78
|
|
70
|
-
|
71
|
-
|
79
|
+
#### Run `rails tailwindcss:watch`
|
80
|
+
|
81
|
+
This is a flexible command, which can be run with a few different options.
|
72
82
|
|
73
83
|
If you are running `rails tailwindcss:watch` on a system that doesn't fully support file system events, pass a `poll` argument to the task to instruct tailwindcss to instead use polling: `rails tailwindcss:watch[poll]`. If you use `bin/dev` then you should modify your `Procfile.dev`.
|
74
84
|
|
@@ -77,6 +87,11 @@ If you are running `rails tailwindcss:watch` as a process in a Docker container,
|
|
77
87
|
If you are running `rails tailwindcss:watch` in a docker container without a tty, pass the `always` argument to the task to instruct tailwindcss to keep the watcher alive even when `stdin` is closed: `rails tailwindcss:watch[always]`. If you use `bin/dev` then you should modify your `Procfile.dev`.
|
78
88
|
|
79
89
|
|
90
|
+
#### Foreman
|
91
|
+
|
92
|
+
Running `bin/dev` invokes Foreman to start both the Tailwind watch process and the rails server in development mode based on your `Procfile.dev` file.
|
93
|
+
|
94
|
+
|
80
95
|
### Debugging with unminified assets
|
81
96
|
|
82
97
|
If you want unminified assets, you can pass a `debug` argument to the rake task, i.e. `rails tailwindcss:build[debug]` or `rails tailwindcss:watch[debug]`.
|
@@ -84,6 +99,24 @@ If you want unminified assets, you can pass a `debug` argument to the rake task,
|
|
84
99
|
Note that you can combine task options, e.g. `rails tailwindcss:watch[debug,poll]`.
|
85
100
|
|
86
101
|
|
102
|
+
### Using with PostCSS
|
103
|
+
|
104
|
+
If you want to use PostCSS as a preprocessor, create a custom `config/postcss.config.js` and it will be loaded automatically.
|
105
|
+
|
106
|
+
For example, to enable nesting:
|
107
|
+
|
108
|
+
```js
|
109
|
+
// config/postcss.config.js
|
110
|
+
module.exports = {
|
111
|
+
plugins: {
|
112
|
+
'postcss-import': {},
|
113
|
+
'tailwindcss/nesting': {},
|
114
|
+
tailwindcss: {},
|
115
|
+
autoprefixer: {},
|
116
|
+
},
|
117
|
+
}
|
118
|
+
```
|
119
|
+
|
87
120
|
### Custom inputs or outputs
|
88
121
|
|
89
122
|
If you need to use a custom input or output file, you can run `bundle exec tailwindcss` to access the platform-specific executable, and give it your own build options.
|
@@ -176,6 +209,12 @@ The inline version also works:
|
|
176
209
|
<section class="bg-[url('image.svg')]">Has the image as it's background</section>
|
177
210
|
```
|
178
211
|
|
212
|
+
### Conflict with pre-existing asset pipeline stylesheets
|
213
|
+
|
214
|
+
If you get a warning `Unrecognized at-rule or error parsing at-rule ‘@tailwind’.` in the browser console after installation, you incorrectly double-process `application.tailwind.css`. This is a misconfiguration, even though the styles will be fully effective in many cases. The file `application.tailwind.css` is installed when running `rails tailwindcss:install` and is placed alongside the common `application.css` in `app/assets/stylesheets`. Because the `application.css` in a newly generated Rails app includes a `require_tree .` directive, the asset pipeline incorrectly processes `application.tailwind.css`, where it should be taken care of by `tailwindcss`. The asset pipeline ignores TailwindCSS's at-directives, and the browser can't process them.
|
215
|
+
|
216
|
+
To fix the warning, you can either remove the `application.css`, if you don't plan to use the asset pipeline for stylesheets, and instead rely on TailwindCSS completely for styles. This is what this installer assumes. Else, if you do want to keep using the asset pipeline in parallel, make sure to remove the `require_tree .` line from the `application.css`.
|
217
|
+
|
179
218
|
## License
|
180
219
|
|
181
220
|
Tailwind for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -3,7 +3,8 @@ require "rails/generators/erb/controller/controller_generator"
|
|
3
3
|
module Tailwindcss
|
4
4
|
module Generators
|
5
5
|
class ControllerGenerator < Erb::Generators::ControllerGenerator
|
6
|
-
source_root File.expand_path("
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
|
+
source_paths << "lib/templates/erb/controller"
|
7
8
|
end
|
8
9
|
end
|
9
10
|
end
|
@@ -3,7 +3,8 @@ require "rails/generators/erb/mailer/mailer_generator"
|
|
3
3
|
module Tailwindcss
|
4
4
|
module Generators
|
5
5
|
class MailerGenerator < Erb::Generators::MailerGenerator
|
6
|
-
source_root File.expand_path("
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
|
+
source_paths << "lib/templates/erb/mailer"
|
7
8
|
end
|
8
9
|
end
|
9
10
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= yield %>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "rails/generators/erb/scaffold/scaffold_generator"
|
2
2
|
require "rails/generators/resource_helpers"
|
3
3
|
|
4
4
|
module Tailwindcss
|
@@ -6,7 +6,8 @@ module Tailwindcss
|
|
6
6
|
class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
7
7
|
include Rails::Generators::ResourceHelpers
|
8
8
|
|
9
|
-
source_root File.expand_path("
|
9
|
+
source_root File.expand_path("templates", __dir__)
|
10
|
+
source_paths << "lib/templates/erb/scaffold"
|
10
11
|
|
11
12
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
12
13
|
|
@@ -15,7 +15,7 @@
|
|
15
15
|
<div class="my-5">
|
16
16
|
<% if attribute.password_digest? -%>
|
17
17
|
<%%= form.label :password %>
|
18
|
-
<%%= form.password_field :password %>
|
18
|
+
<%%= form.password_field :password, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
|
19
19
|
</div>
|
20
20
|
|
21
21
|
<div class="my-5">
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
<div class="flex justify-between items-center">
|
7
7
|
<h1 class="font-bold text-4xl"><%= human_name.pluralize %></h1>
|
8
|
-
<%%= link_to
|
8
|
+
<%%= link_to "New <%= human_name.downcase %>", new_<%= singular_route_name %>_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
|
9
9
|
</div>
|
10
10
|
|
11
11
|
<div id="<%= plural_table_name %>" class="min-w-full">
|
@@ -3,5 +3,5 @@
|
|
3
3
|
|
4
4
|
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
|
5
5
|
|
6
|
-
<%%= link_to
|
6
|
+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
7
7
|
</div>
|
@@ -16,7 +16,7 @@
|
|
16
16
|
<% end -%>
|
17
17
|
<%% if action_name != "show" %>
|
18
18
|
<%%= link_to "Show this <%= human_name.downcase %>", <%= singular_name %>, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
19
|
-
<%%= link_to
|
19
|
+
<%%= link_to "Edit this <%= human_name.downcase %>", edit_<%= singular_name %>_path(<%= singular_name %>), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
|
20
20
|
<hr class="mt-6">
|
21
21
|
<%% end %>
|
22
22
|
</div>
|
@@ -6,10 +6,10 @@
|
|
6
6
|
|
7
7
|
<%%= render @<%= singular_table_name %> %>
|
8
8
|
|
9
|
-
<%%= link_to
|
9
|
+
<%%= link_to "Edit this <%= singular_table_name %>", edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
10
10
|
<div class="inline-block ml-2">
|
11
|
-
<%%= button_to
|
11
|
+
<%%= button_to "Destroy this <%= singular_table_name %>", <%= singular_table_name %>_path(@<%= singular_table_name %>), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
|
12
12
|
</div>
|
13
|
-
<%%= link_to
|
13
|
+
<%%= link_to "Back to <%= plural_table_name %>", <%= index_helper %>_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
14
14
|
</div>
|
15
15
|
</div>
|
data/lib/install/Procfile.dev
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
web: bin/rails server
|
1
|
+
web: bin/rails server
|
2
2
|
css: bin/rails tailwindcss:watch
|
data/lib/install/dev
CHANGED
@@ -5,4 +5,12 @@ if ! gem list foreman -i --silent; then
|
|
5
5
|
gem install foreman
|
6
6
|
fi
|
7
7
|
|
8
|
+
# Default to port 3000 if not specified
|
9
|
+
export PORT="${PORT:-3000}"
|
10
|
+
|
11
|
+
# Let the debug gem allow remote connections,
|
12
|
+
# but avoid loading until `debugger` is called
|
13
|
+
export RUBY_DEBUG_OPEN="true"
|
14
|
+
export RUBY_DEBUG_LAZY="true"
|
15
|
+
|
8
16
|
exec foreman start -f Procfile.dev "$@"
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "puma/plugin"
|
2
|
+
|
3
|
+
Puma::Plugin.create do
|
4
|
+
attr_reader :puma_pid, :tailwind_pid, :log_writer
|
5
|
+
|
6
|
+
def start(launcher)
|
7
|
+
@log_writer = launcher.log_writer
|
8
|
+
@puma_pid = $$
|
9
|
+
@tailwind_pid = fork do
|
10
|
+
Thread.new { monitor_puma }
|
11
|
+
system(*Tailwindcss::Commands.watch_command)
|
12
|
+
end
|
13
|
+
|
14
|
+
launcher.events.on_stopped { stop_tailwind }
|
15
|
+
|
16
|
+
in_background do
|
17
|
+
monitor_tailwind
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def stop_tailwind
|
23
|
+
Process.waitpid(tailwind_pid, Process::WNOHANG)
|
24
|
+
log "Stopping tailwind..."
|
25
|
+
Process.kill(:INT, tailwind_pid) if tailwind_pid
|
26
|
+
Process.wait(tailwind_pid)
|
27
|
+
rescue Errno::ECHILD, Errno::ESRCH
|
28
|
+
end
|
29
|
+
|
30
|
+
def monitor_puma
|
31
|
+
monitor(:puma_dead?, "Detected Puma has gone away, stopping tailwind...")
|
32
|
+
end
|
33
|
+
|
34
|
+
def monitor_tailwind
|
35
|
+
monitor(:tailwind_dead?, "Detected tailwind has gone away, stopping Puma...")
|
36
|
+
end
|
37
|
+
|
38
|
+
def monitor(process_dead, message)
|
39
|
+
loop do
|
40
|
+
if send(process_dead)
|
41
|
+
log message
|
42
|
+
Process.kill(:INT, $$)
|
43
|
+
break
|
44
|
+
end
|
45
|
+
sleep 2
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def tailwind_dead?
|
50
|
+
Process.waitpid(tailwind_pid, Process::WNOHANG)
|
51
|
+
false
|
52
|
+
rescue Errno::ECHILD, Errno::ESRCH
|
53
|
+
true
|
54
|
+
end
|
55
|
+
|
56
|
+
def puma_dead?
|
57
|
+
Process.ppid != puma_pid
|
58
|
+
end
|
59
|
+
|
60
|
+
def log(...)
|
61
|
+
log_writer.log(...)
|
62
|
+
end
|
63
|
+
end
|
data/lib/tailwindcss/commands.rb
CHANGED
@@ -3,6 +3,7 @@ require_relative "upstream"
|
|
3
3
|
module Tailwindcss
|
4
4
|
module Commands
|
5
5
|
DEFAULT_DIR = File.expand_path(File.join(__dir__, "..", "..", "exe"))
|
6
|
+
GEM_NAME = "tailwindcss-rails"
|
6
7
|
|
7
8
|
# raised when the host platform is not supported by upstream tailwindcss's binary releases
|
8
9
|
class UnsupportedPlatformException < StandardError
|
@@ -34,7 +35,7 @@ module Tailwindcss
|
|
34
35
|
MESSAGE
|
35
36
|
end
|
36
37
|
else
|
37
|
-
if Tailwindcss::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.
|
38
|
+
if Tailwindcss::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), GEM_NAME) }
|
38
39
|
raise UnsupportedPlatformException, <<~MESSAGE
|
39
40
|
tailwindcss-rails does not support the #{platform} platform
|
40
41
|
Please install tailwindcss following instructions at https://tailwindcss.com/docs/installation
|
@@ -42,7 +43,7 @@ module Tailwindcss
|
|
42
43
|
end
|
43
44
|
|
44
45
|
exe_file = Dir.glob(File.expand_path(File.join(exe_path, "*", "tailwindcss"))).find do |f|
|
45
|
-
Gem::Platform.
|
46
|
+
Gem::Platform.match_gem?(Gem::Platform.new(File.basename(File.dirname(f))), GEM_NAME)
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
@@ -73,14 +74,19 @@ module Tailwindcss
|
|
73
74
|
end
|
74
75
|
|
75
76
|
def compile_command(debug: false, **kwargs)
|
76
|
-
[
|
77
|
+
command = [
|
77
78
|
executable(**kwargs),
|
78
79
|
"-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s,
|
79
80
|
"-o", Rails.root.join("app/assets/builds/tailwind.css").to_s,
|
80
81
|
"-c", Rails.root.join("config/tailwind.config.js").to_s,
|
81
|
-
]
|
82
|
-
|
83
|
-
|
82
|
+
]
|
83
|
+
|
84
|
+
command << "--minify" unless (debug || rails_css_compressor?)
|
85
|
+
|
86
|
+
postcss_path = Rails.root.join("config/postcss.config.js")
|
87
|
+
command += ["--postcss", postcss_path.to_s] if File.exist?(postcss_path)
|
88
|
+
|
89
|
+
command
|
84
90
|
end
|
85
91
|
|
86
92
|
def watch_command(always: false, poll: false, **kwargs)
|
data/lib/tailwindcss/upstream.rb
CHANGED
data/lib/tailwindcss/version.rb
CHANGED
data/lib/tasks/build.rake
CHANGED
@@ -22,6 +22,8 @@ Rake::Task["assets:precompile"].enhance(["tailwindcss:build"])
|
|
22
22
|
|
23
23
|
if Rake::Task.task_defined?("test:prepare")
|
24
24
|
Rake::Task["test:prepare"].enhance(["tailwindcss:build"])
|
25
|
+
elsif Rake::Task.task_defined?("spec:prepare")
|
26
|
+
Rake::Task["spec:prepare"].enhance(["tailwindcss:build"])
|
25
27
|
elsif Rake::Task.task_defined?("db:test:prepare")
|
26
28
|
Rake::Task["db:test:prepare"].enhance(["tailwindcss:build"])
|
27
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tailwindcss-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -56,6 +56,8 @@ files:
|
|
56
56
|
- lib/generators/tailwindcss/controller/controller_generator.rb
|
57
57
|
- lib/generators/tailwindcss/controller/templates/view.html.erb.tt
|
58
58
|
- lib/generators/tailwindcss/mailer/mailer_generator.rb
|
59
|
+
- lib/generators/tailwindcss/mailer/templates/layout.html.erb.tt
|
60
|
+
- lib/generators/tailwindcss/mailer/templates/layout.text.erb.tt
|
59
61
|
- lib/generators/tailwindcss/mailer/templates/view.html.erb.tt
|
60
62
|
- lib/generators/tailwindcss/mailer/templates/view.text.erb.tt
|
61
63
|
- lib/generators/tailwindcss/scaffold/scaffold_generator.rb
|
@@ -70,6 +72,7 @@ files:
|
|
70
72
|
- lib/install/dev
|
71
73
|
- lib/install/tailwind.config.js
|
72
74
|
- lib/install/tailwindcss.rb
|
75
|
+
- lib/puma/plugin/tailwindcss.rb
|
73
76
|
- lib/tailwindcss-rails.rb
|
74
77
|
- lib/tailwindcss/commands.rb
|
75
78
|
- lib/tailwindcss/engine.rb
|
@@ -97,9 +100,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
100
|
requirements:
|
98
101
|
- - ">="
|
99
102
|
- !ruby/object:Gem::Version
|
100
|
-
version:
|
103
|
+
version: 3.2.0
|
101
104
|
requirements: []
|
102
|
-
rubygems_version: 3.4.
|
105
|
+
rubygems_version: 3.4.19
|
103
106
|
signing_key:
|
104
107
|
specification_version: 4
|
105
108
|
summary: Integrate Tailwind CSS with the asset pipeline in Rails.
|