tailwindcss-rails 2.0.12 → 2.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30aa11b22e17eae8fafbfecbea18b80f09b27464762bf26f3ccb5401be30f39e
4
- data.tar.gz: b46b1d62d538a02925b006048fce2ee5359a2e3965bfee9560e6353cbee19d95
3
+ metadata.gz: 0d154c6d0679b9cbb20eb9d720cdf83f121ddbe841b0c278bcd6800b5e800610
4
+ data.tar.gz: 1364721dab0dac09481e2d07f81dbc8479bd07d676b5f249bca37477e9a25586
5
5
  SHA512:
6
- metadata.gz: 86287c215766ddc4bfe1092bef31155892481d7c34751bd3d92ad9f85908b610e2047578ae6b759d609139009244bfe3012a462ddedd60fcb686c3738f6b49e3
7
- data.tar.gz: ab12715a423a55752a5a3ce2e5c4e3e4234e65dc5d14867d0456409749bf61da9ddba04502502c708a214b8eb6cbe31052075ac7a30ea2ebf49ab72cb01f6e95
6
+ metadata.gz: 91d844b8de7ca2d6b216b88cec302fd2092a7b908fd69a2c9f4f313c611c50ec44562bf0826d1118366a12061be90c34927459e8a972387088dd3502cd36a385
7
+ data.tar.gz: afa67781c4448af64cab2b6d428b3830c9622ede98d925523dedb612a9b8ec192a56abd62791730efa2c33755d394b9336cece627e4893910a33b3afd5c53cbd
data/README.md CHANGED
@@ -2,45 +2,71 @@
2
2
 
3
3
  [Tailwind CSS](https://tailwindcss.com) is a utility-first CSS framework packed with classes like flex, pt-4, text-center and rotate-90 that can be composed to build any design, directly in your markup.
4
4
 
5
+ ## Installation
6
+
7
+ With Rails 7 you can generate a new application preconfigured with Tailwind by using `--css tailwind`. If you're adding Tailwind later, you need to:
8
+
9
+ 1. Run `./bin/bundle add tailwindcss-rails`
10
+ 2. Run `./bin/rails tailwindcss:install`
11
+
5
12
  This gem wraps [the standalone executable version](https://tailwindcss.com/blog/standalone-cli) of the Tailwind CSS v3 framework. These executables are platform specific, so there are actually separate underlying gems per platform, but the correct gem will automatically be picked for your platform. Supported platforms are Linux x64, macOS arm64, macOS x64, and Windows x64. (Note that due to this setup, you must install the actual gems – you can't pin your gem to the github repo.)
6
13
 
14
+
15
+ ## Developing with Tailwindcss
16
+
17
+ ### Configuration
18
+
7
19
  You can customize the Tailwind build through the `config/tailwind.config.js` file, just like you would if Tailwind was running in a traditional node installation. All the first-party plugins are supported.
8
20
 
9
21
  The installer will create your Tailwind input file in `app/assets/stylesheets/application.tailwind.css`. This is where you import the plugins you want to use, and where you can setup your custom `@apply` rules. When you run `rails tailwindcss:build`, this input file will be used to generate the output in `app/assets/builds/tailwind.css`. That's the output CSS that you'll include in your app (the installer automatically configures this, alongside the Inter font as well).
10
22
 
11
- 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.
12
23
 
13
- When 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 either by running `rails tailwindcss:watch` as a separate process, or by running `./bin/dev` which uses [foreman](https://github.com/ddollar/foreman) to starts both the Tailwind watch process and the rails server in development mode. If you are running `rails tailwindcss:watch` as a process in a Docker container, set `tty: true` in `docker-compose.yml` for the appropriate container to keep the watch process running.
24
+ ### Building for production
14
25
 
26
+ The `tailwindcss:build` is automatically attached to `assets:precompile`, so before the asset pipeline digests the files, the Tailwind output will be generated.
15
27
 
16
- ## Installation
17
28
 
18
- With Rails 7 you can generate a new application preconfigured with Tailwind by using `--css tailwind`. If you're adding Tailwind later, you need to:
29
+ ### Building for testing
19
30
 
20
- 1. Run `./bin/bundle add tailwindcss-rails`
21
- 2. Run `./bin/rails tailwindcss:install`
31
+ The `tailwindcss:build` is automatically attached to `test:prepare`, which runs before Rails tests. (Note that this currently only applies to rails `test:*` tasks (like `test:all` or `test:controllers`), not "rails test", as that doesn't load `test:prepare`).
22
32
 
23
33
 
24
- ## Building in production
34
+ ### Update assets automatically
25
35
 
26
- The `tailwindcss:build` is automatically attached to `assets:precompile`, so before the asset pipeline digests the files, the Tailwind output will be generated.
36
+ 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:
27
37
 
28
- ## Building for testing
38
+ - running `rails tailwindcss:watch` as a separate process,
39
+ - or by running `./bin/dev` which uses [foreman](https://github.com/ddollar/foreman) to start both the Tailwind watch process and the rails server in development mode.
29
40
 
30
- The `tailwindcss:build` is automatically attached to `test:prepare`, which runs before Rails tests. (Note that this currently only applies to rails `test:*` tasks (like `test:all` or `test:controllers`), not "rails test", as that doesn't load `test:prepare`).
41
+ If you are running `rails tailwindcss:watch` as a process in a Docker container, set `tty: true` in `docker-compose.yml` for the appropriate container to keep the watch process running.
31
42
 
32
- ## Conflict with sassc-rails
43
+ 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`.
33
44
 
34
- Tailwind uses modern CSS features that are not recognized by the `sassc-rails` extension that was included by default in the Gemfile for Rails 6. In order to avoid any errors like `SassC::SyntaxError`, you must remove that gem from your Gemfile.
35
45
 
36
- ## Class names must be spelled out
46
+ ### Debugging with unminified assets
47
+
48
+ 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]`.
49
+
50
+ Note that you can combine task options, e.g. `rails tailwindcss:watch[debug,poll]`.
51
+
52
+
53
+ ### Custom inputs or outputs
54
+
55
+ 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.
37
56
 
38
- For Tailwind to work, your class names need to be spelled out. They can't be programmatically composed. So no "text-gray-#{grade}", only "text-gray-500".
39
57
 
40
58
  ## Troubleshooting
41
59
 
42
60
  Some common problems experienced by users ...
43
61
 
62
+ ### Conflict with sassc-rails
63
+
64
+ Tailwind uses modern CSS features that are not recognized by the `sassc-rails` extension that was included by default in the Gemfile for Rails 6. In order to avoid any errors like `SassC::SyntaxError`, you must remove that gem from your Gemfile.
65
+
66
+ ### Class names must be spelled out
67
+
68
+ For Tailwind to work, your class names need to be spelled out. They can't be programmatically composed. So no "text-gray-#{grade}", only "text-gray-500".
69
+
44
70
  ### ERROR: Cannot find the tailwindcss executable for <supported platform>
45
71
 
46
72
  Some users are reporting this error even when running on one of the supported native platforms:
data/exe/tailwindcss CHANGED
@@ -1,46 +1,19 @@
1
1
  #! /usr/bin/env ruby
2
2
  # because rubygems shims assume a gem's executables are Ruby
3
3
 
4
- require "shellwords"
5
- require "tailwindcss/upstream"
6
-
7
- supported_platforms = Tailwindcss::Upstream::NATIVE_PLATFORMS.keys
8
- platform = [:cpu, :os].map { |m| Gem::Platform.local.send(m) }.join("-")
9
-
10
- if supported_platforms.none? { |supported_platform| Gem::Platform.match(supported_platform) }
11
- STDERR.puts(<<~ERRMSG)
12
- ERROR: tailwindcss-rails does not support the #{platform} platform
13
- Please install tailwindcss following instructions at https://tailwindcss.com/docs/installation
14
- ERRMSG
4
+ require "tailwindcss/commands"
5
+
6
+ begin
7
+ command = [Tailwindcss::Commands.executable, *ARGV]
8
+ puts command.inspect
9
+ if Gem.win_platform?
10
+ # use system rather than exec as exec inexplicably fails to find the executable on Windows
11
+ # see related https://github.com/rubys/sprockets-esbuild/pull/4
12
+ system(*command, exception: true)
13
+ else
14
+ exec(*command)
15
+ end
16
+ rescue Tailwindcss::Commands::UnsupportedPlatformException, Tailwindcss::Commands::ExecutableNotFoundException => e
17
+ STDERR.puts("ERROR: " + e.message)
15
18
  exit 1
16
19
  end
17
-
18
- exe_path = Dir.glob(File.join(__dir__, "*", "tailwindcss")).find do |f|
19
- Gem::Platform.match(File.basename(File.dirname(f)))
20
- end
21
- if exe_path.nil?
22
- STDERR.puts(<<~ERRMSG)
23
- ERROR: Cannot find the tailwindcss executable for #{platform} in #{__dir__}
24
- If you're using bundler, please make sure you're on the latest bundler version:
25
-
26
- gem install bundler
27
- bundle update --bundler
28
-
29
- Then make sure your lock file includes this platform by running:
30
-
31
- bundle lock --add-platform #{platform}
32
- bundle install
33
-
34
- See `bundle lock --help` output for details.
35
-
36
- If you're still seeing this message after taking those steps, try running
37
- `bundle config` and ensure `force_ruby_platform` isn't set to `true`. See
38
- https://github.com/rails/tailwindcss-rails#check-bundle_force_ruby_platform
39
- for more details.
40
- ERRMSG
41
- exit 1
42
- end
43
-
44
- command = Shellwords.join([exe_path, ARGV].flatten)
45
- puts "+ #{command}"
46
- exec(command)
@@ -0,0 +1,77 @@
1
+ require_relative "upstream"
2
+
3
+ module Tailwindcss
4
+ module Commands
5
+ # raised when the host platform is not supported by upstream tailwindcss's binary releases
6
+ class UnsupportedPlatformException < StandardError
7
+ end
8
+
9
+ # raised when the tailwindcss executable could not be found where we expected it to be
10
+ class ExecutableNotFoundException < StandardError
11
+ end
12
+
13
+ class << self
14
+ def platform
15
+ [:cpu, :os].map { |m| Gem::Platform.local.send(m) }.join("-")
16
+ end
17
+
18
+ def executable(
19
+ exe_path: File.expand_path(File.join(__dir__, "..", "..", "exe"))
20
+ )
21
+ if Tailwindcss::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.match(p) }
22
+ raise UnsupportedPlatformException, <<~MESSAGE
23
+ tailwindcss-rails does not support the #{platform} platform
24
+ Please install tailwindcss following instructions at https://tailwindcss.com/docs/installation
25
+ MESSAGE
26
+ end
27
+
28
+ exe_path = Dir.glob(File.expand_path(File.join(exe_path, "*", "tailwindcss"))).find do |f|
29
+ Gem::Platform.match(File.basename(File.dirname(f)))
30
+ end
31
+
32
+ if exe_path.nil?
33
+ raise ExecutableNotFoundException, <<~MESSAGE
34
+ Cannot find the tailwindcss executable for #{platform} in #{exe_path}
35
+
36
+ If you're using bundler, please make sure you're on the latest bundler version:
37
+
38
+ gem install bundler
39
+ bundle update --bundler
40
+
41
+ Then make sure your lock file includes this platform by running:
42
+
43
+ bundle lock --add-platform #{platform}
44
+ bundle install
45
+
46
+ See `bundle lock --help` output for details.
47
+
48
+ If you're still seeing this message after taking those steps, try running
49
+ `bundle config` and ensure `force_ruby_platform` isn't set to `true`. See
50
+ https://github.com/rails/tailwindcss-rails#check-bundle_force_ruby_platform
51
+ for more details.
52
+ MESSAGE
53
+ end
54
+
55
+ exe_path
56
+ end
57
+
58
+ def compile_command(debug: false, **kwargs)
59
+ [
60
+ executable(**kwargs),
61
+ "-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s,
62
+ "-o", Rails.root.join("app/assets/builds/tailwind.css").to_s,
63
+ "-c", Rails.root.join("config/tailwind.config.js").to_s,
64
+ ].tap do |command|
65
+ command << "--minify" unless debug
66
+ end
67
+ end
68
+
69
+ def watch_command(poll: false, **kwargs)
70
+ compile_command(**kwargs).tap do |command|
71
+ command << "-w"
72
+ command << "-p" if poll
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,3 +1,3 @@
1
1
  module Tailwindcss
2
- VERSION = "2.0.12"
2
+ VERSION = "2.0.13"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  module Tailwindcss
2
2
  end
3
3
 
4
- require "tailwindcss/upstream"
5
- require "tailwindcss/version"
6
- require "tailwindcss/engine"
4
+ require_relative "tailwindcss/upstream"
5
+ require_relative "tailwindcss/version"
6
+ require_relative "tailwindcss/engine"
7
+ require_relative "tailwindcss/commands"
data/lib/tasks/build.rake CHANGED
@@ -1,14 +1,19 @@
1
- TAILWIND_COMPILE_COMMAND = "#{RbConfig.ruby} #{Pathname.new(__dir__).to_s}/../../exe/tailwindcss -i '#{Rails.root.join("app/assets/stylesheets/application.tailwind.css")}' -o '#{Rails.root.join("app/assets/builds/tailwind.css")}' -c '#{Rails.root.join("config/tailwind.config.js")}' --minify"
2
-
3
1
  namespace :tailwindcss do
4
2
  desc "Build your Tailwind CSS"
5
- task :build do
6
- system(TAILWIND_COMPILE_COMMAND, exception: true)
3
+ task :build do |_, args|
4
+ debug = args.extras.include?("debug")
5
+ command = Tailwindcss::Commands.compile_command(debug: debug)
6
+ puts command.inspect
7
+ system(*command, exception: true)
7
8
  end
8
9
 
9
10
  desc "Watch and build your Tailwind CSS on file changes"
10
- task :watch do
11
- system "#{TAILWIND_COMPILE_COMMAND} -w"
11
+ task :watch do |_, args|
12
+ debug = args.extras.include?("debug")
13
+ poll = args.extras.include?("poll")
14
+ command = Tailwindcss::Commands.watch_command(debug: debug, poll: poll)
15
+ puts command.inspect
16
+ system(*command)
12
17
  end
13
18
  end
14
19
 
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.12
4
+ version: 2.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-10 00:00:00.000000000 Z
11
+ date: 2022-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 6.0.0
27
- description:
27
+ description:
28
28
  email: david@loudthinking.com
29
29
  executables:
30
30
  - tailwindcss
@@ -70,6 +70,7 @@ files:
70
70
  - lib/install/tailwind.config.js
71
71
  - lib/install/tailwindcss.rb
72
72
  - lib/tailwindcss-rails.rb
73
+ - lib/tailwindcss/commands.rb
73
74
  - lib/tailwindcss/engine.rb
74
75
  - lib/tailwindcss/upstream.rb
75
76
  - lib/tailwindcss/version.rb
@@ -82,7 +83,7 @@ licenses:
82
83
  metadata:
83
84
  homepage_uri: https://github.com/rails/tailwindcss-rails
84
85
  rubygems_mfa_required: 'true'
85
- post_install_message:
86
+ post_install_message:
86
87
  rdoc_options: []
87
88
  require_paths:
88
89
  - lib
@@ -97,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
98
  - !ruby/object:Gem::Version
98
99
  version: '0'
99
100
  requirements: []
100
- rubygems_version: 3.3.19
101
- signing_key:
101
+ rubygems_version: 3.3.7
102
+ signing_key:
102
103
  specification_version: 4
103
104
  summary: Integrate Tailwind CSS with the asset pipeline in Rails.
104
105
  test_files: []