jekyll-tailwindcss 0.6.2 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e1e29ca0abd9c5830429366d0552d685446274bda03e353ee6829e2bb946296
4
- data.tar.gz: 1cd3dd8fd880efdb33118309492697061c624e046abd72cc5540e98db9bee90c
3
+ metadata.gz: 1dbaabf8182ffec1b921e55302c42347e79a050e34dbf4d81f12c519a7b0ce1c
4
+ data.tar.gz: 58f26e5d0c0fe75f8332b110891e60486fc0c5682ddd023af7729de84a13b55b
5
5
  SHA512:
6
- metadata.gz: 58bfbab5c38628acc762375d3d6f8211ce6cb302b6803bbff3428f345efafe1e29f4087739dfc05fb855e65149c749c18b8206d3677015837fb2c159207cea5b
7
- data.tar.gz: 67c4d4efafa86cc2972cc1db7e357cfdd65e14583ed5e27138a692e94a8f8af198555184e717db19e19046cae215f2680f04358e2182a64a6f6d1df75eebbf8a
6
+ metadata.gz: a38213fba4c426ec56c5167c289ccbd2be7c1fbaca162c0be859501828adde4ce7388044ced71aea77de4f2ba2dc361c735933daccd927cfa6afd54fd3237f5c
7
+ data.tar.gz: 84ff52cf55150133d1bac3de41cc3896dc96114e9d9fcf1f02a72497a5ba79896eb31f845b414e59c59c8e7723e34b78b7063751370129e656f94e8afaed15dd
data/CHANGELOG.md ADDED
@@ -0,0 +1,74 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.8.0] - 2026-11-25
4
+ - **Breaking:** Tailwind failures now fail the Jekyll build. A missing tailwindcss binary, a CLI error, a v3 stylesheet without a `tailwindcss.config` path, or a `.tailwindcss` file on tailwindcss-ruby < 4 raises `Jekyll::Tailwindcss::CompilationError`, and `jekyll build` exits non-zero. Previously the gem logged the error and published the uncompiled source. [#35](https://github.com/vormwald/jekyll-tailwindcss/pull/35)
5
+ - Fix `.tailwindcss` builds run from outside the site source (e.g. `jekyll build --source src`). `tailwindcss.css_path` is now resolved against the site source instead of the working directory, and the tailwindcss CLI runs in the site source so it finds the classes in your templates. **If you set `source:` and wrote `css_path` relative to the working directory to get around this (e.g. `css_path: src/_tailwind.css`), make it relative to the source instead (`css_path: _tailwind.css`).** The v3 error message now points at the README's v3 setup instead of suggesting v4 syntax. [#38](https://github.com/vormwald/jekyll-tailwindcss/issues/38)
6
+ - Drop support for Ruby 3.1, which reached end-of-life on 2025-03-31. The gem now requires Ruby >= 3.2. [#34](https://github.com/vormwald/jekyll-tailwindcss/pull/34)
7
+ - Add `jekyll tailwindcss:install`, which creates `_tailwind.css` (or your `tailwindcss.css_path`) and `assets/css/styles.tailwindcss`, skips files that already exist, and prints the `<link>` tag to add to your layout. Requires tailwindcss-ruby >= 4.0. [#31](https://github.com/vormwald/jekyll-tailwindcss/pull/31)
8
+ - Fix CSS compilation failing with `invalid byte sequence in US-ASCII` on build machines without a UTF-8 locale (e.g. `LANG=C`). The tailwindcss CLI's input and output are now always handled as UTF-8. [#36](https://github.com/vormwald/jekyll-tailwindcss/issues/36)
9
+
10
+ ## [0.7.0] - 2025-04-12
11
+ - Added a new (and better) way to organize your project with _tailwind.css and styles.tailwindcss files [#26](https://github.com/vormwald/jekyll-tailwindcss/pull/26)
12
+
13
+ ## [0.6.2] - 2025-02-28
14
+
15
+ - Support importing official plugins in CSS for v4 [#22](https://github.com/vormwald/jekyll-tailwindcss/pull/22) @imustafin
16
+
17
+ ## [0.6.1] - 2025-02-13
18
+
19
+ - Expand the matcher to match additional valid tailwindcss imports [#21](https://github.com/vormwald/jekyll-tailwindcss/pull/21)
20
+
21
+ ## [0.6.0] - 2025-02-13
22
+
23
+ - Remove the unused jekyll-tailwindcss executable [#17](https://github.com/vormwald/jekyll-tailwindcss/pull/17)
24
+ - BIG Upgrade to TailwindCSS v4 [#18](https://github.com/vormwald/jekyll-tailwindcss/pull/18)
25
+
26
+ ## [0.5.1]
27
+
28
+ - Fix a potential bug that would hang on large tailwind files - [#13](https://github.com/vormwald/jekyll-tailwindcss/pull/13) @marckohlbrugge
29
+
30
+ ## [0.5.0]
31
+
32
+ - Location of `tailwind.config.js` can be specified in `_config.yml` - [#9](https://github.com/vormwald/jekyll-tailwindcss/pull/9) @imustafin
33
+
34
+ ## [0.4.0] - 2024-11-23
35
+
36
+ ### Changed
37
+
38
+ - The upstream `tailwindcss` executable has been extracted from this gem into a new dependency, `tailwindcss-ruby`.
39
+
40
+ In advance of the upcoming TailwindCSS v4 release, we are decoupling the `tailwindcss` executable
41
+ from the Rails integration. This will allow users to upgrade TailwindCSS at a time of their
42
+ choosing, and allow early adopters to start using the beta releases.
43
+
44
+ ## [0.3.1] - 2024-06-10
45
+
46
+ ### Changed
47
+
48
+ - Update to [Tailwind CSS v3.4.12](https://github.com/tailwindlabs/tailwindcss/releases/tag/v3.4.12)
49
+
50
+ ## [0.3.0] - 2024-06-09
51
+
52
+ ### Changed
53
+
54
+ - Renamed the gems executable from `tailwindcss` to `jekyll-tailwindcss` to avoid conflicts with the `tailwindcss-rails` gem
55
+
56
+ ### Added
57
+
58
+ - arm64-darwin platform support
59
+
60
+ ## [0.2.0] - 2024-04-17
61
+
62
+ ### Changed
63
+
64
+ - The plugin now converts any css file that contains frontmatter and a `@tailwind` directive
65
+ - No longer needs the extra files from initial version
66
+
67
+ ### Added
68
+
69
+ - an integration test that runs in CI and confirms that the CLIs download correctly
70
+ - Better logging from the plugin. Any errors from tailwind are displayed as warns, and any errors from the gem are displayed as error level
71
+
72
+ ## [0.1.0] - 2024-02-12
73
+
74
+ - Initial release
data/README.md CHANGED
@@ -1,20 +1,15 @@
1
1
  # Jekyll::Tailwindcss
2
2
 
3
- Bring the fun of building with TailwindCSS into your Jekyll project (without any JavaScript)
3
+ Bring the joy of building with TailwindCSS into your Jekyll project (without any JavaScript)
4
4
 
5
- **TL;DR** This gem borrows _heavily_ from [tailwindcss-rails](https://github.com/rails/tailwindcss-rails) to provide platform-specific tailwind executables and provide a smooth developer experience in Jekyll projects
5
+ **TL;DR** This gem uses [tailwindcss-ruby](https://github.com/rails/tailwindcss-ruby) to provide platform-specific tailwind executables and enables a smooth developer experience in Jekyll projects
6
6
 
7
- > _"Because building a great jekyll site shouldn't require a `node_modules` folder"_
7
+ > _"Because building a great Jekyll site shouldn't require a `node_modules` folder"_
8
8
 
9
- ## Installation
10
-
11
- Install the gem in your jekyll project's Gemfile by executing the following:
12
9
 
13
- ```
14
- bundle add jekyll-tailwindcss --group jekyll_plugins
15
- ```
10
+ ## Installation
16
11
 
17
- Or by adding the gem manually
12
+ Add the gem to your Jekyll project's Gemfile
18
13
 
19
14
  ```ruby
20
15
  # Gemfile
@@ -25,10 +20,12 @@ group :jekyll_plugins do
25
20
  end
26
21
  ```
27
22
 
28
- > [!NOTE]
29
- > By adding this gem to the jekyll_plugins group, you don't need to explicitly configure it in `_config.yml`.
23
+ Run `bundle install`
24
+
25
+ > [!TIP]
26
+ > By adding this gem to the `:jekyll_plugins` group, you don't need to explicitly configure it in `_config.yml`.
30
27
 
31
- ### Choosing a specific version of tailwindcss
28
+ ### Optional: Choosing a specific version of tailwindcss
32
29
 
33
30
  This gem uses the latest TailwindCSS by default. However since CLI versions are managed by the `tailwindcss-ruby` gem, it supports older versions as well.
34
31
 
@@ -56,7 +53,7 @@ tailwindcss:
56
53
  config: "./tailwind.config.js"
57
54
  ```
58
55
 
59
- Tailwind will generate CSS for the classes found in `content` directories. For most jekyll sites, this would work well.
56
+ Tailwind will generate CSS for the classes found in `content` directories. For most Jekyll sites, this would work well.
60
57
 
61
58
  ```js
62
59
  // ./tailwind.config.js
@@ -83,7 +80,7 @@ Any CSS file with frontmatter and `@tailwind` directives will be converted.
83
80
  ```css
84
81
  /* assets/css/styles.css */
85
82
  ---
86
- # This yaml frontmatter is required for jekyll to process the file
83
+ # This yaml frontmatter is required for Jekyll to process the file
87
84
  ---
88
85
 
89
86
  @tailwind base;
@@ -101,14 +98,21 @@ will be converted to
101
98
  /* _site/assets/css/styles.css */
102
99
 
103
100
  /*
104
- * Tailwind generated CSS
101
+ * Tailwind generated CSS
105
102
  * ...
106
103
  */
107
104
  ```
108
105
 
109
106
  ### PostCSS Support
110
107
 
111
- This gem includes basic PostCSS support. If a `postcss.config.js` file is included in your `_config.yml`, the Tailwind CLI will be invoked with the `--postcss` flag.
108
+ > [!WARNING]
109
+ > PostCSS configuration is considered an advanced use case and is outside the scope of this gem.
110
+ > It is possible that support be removed in future versions of this gem. If needed, you should look to run your Tailwind builds with node.
111
+
112
+ That said... This gem includes basic PostCSS support. If a `postcss.config.js` file is included in your `_config.yml`, the Tailwind CLI will be invoked with the `--postcss` flag.
113
+
114
+ Users should verify their PostCSS setup outside this gem by running:
115
+ `bundle exec tailwindcss --postcss postcss.config.js`
112
116
 
113
117
  ```yaml
114
118
  tailwindcss:
@@ -116,62 +120,98 @@ tailwindcss:
116
120
  postcss: "./postcss.config.js" # OPTIONAL, only if you have a postcss config file
117
121
  ```
118
122
 
119
- > [!NOTE]
120
- > PostCSS configuration is considered an advanced use case and is outside the scope of this gem. Users should verify their PostCSS setup outside this gem by running:
121
- > `bundle exec tailwindcss --postcss postcss.config.js`
122
123
 
123
124
  </details>
124
125
 
125
126
  ## Usage
126
127
 
128
+ > See an example repo at https://github.com/vormwald/jekyll-blahg
129
+
130
+ ### Quick start
131
+
132
+ With Tailwind v4 (tailwindcss-ruby >= 4.0) and the gem in your Gemfile's `:jekyll_plugins` group (see [Installation](#installation)), run:
133
+
127
134
  ```sh
128
- bundle exec jekyll serve # or build
135
+ bundle exec jekyll tailwindcss:install
129
136
  ```
130
137
 
131
- Any `*.css` file processed by jekyll [^1] that contains the `@import "tailwindcss";` [directive](https://tailwindcss.com/docs/functions-and-directives#config) will be converted through the Tailwind CLI.
138
+ This creates `_tailwind.css` (or your `tailwindcss.css_path`) and `assets/css/styles.tailwindcss`, skipping any that already exist. Then add the stylesheet to your layout's `<head>`:
132
139
 
133
- [^1]: Jekyll will process any file that begins with yaml [frontmatter](https://jekyllrb.com/docs/front-matter/)
140
+ ```html
141
+ <link rel="stylesheet" href="{{ '/assets/css/styles.css' | relative_url }}">
142
+ ```
134
143
 
135
- ### Example
136
- Any CSS file with frontmatter and `@import "tailwindcss";` will be converted.
144
+ The command doesn't support Tailwind v3. For v3, follow the [Tailwind Version 3 Setup](#optional-choosing-a-specific-version-of-tailwindcss).
137
145
 
138
- Your CSS file
146
+ ### Setup
147
+ You'll need 2 files to make this work:
139
148
 
140
- ```css
141
- /* assets/css/styles.css */
142
- ---
143
- # This yaml frontmatter is required for jekyll to process the file
144
- ---
149
+ **File 1: `./_tailwind.css`**
150
+
151
+ This file acts as your tailwind configuration file. Import "tailwindcss" and any custom CSS here.
145
152
 
153
+ ```css
146
154
  @import "tailwindcss";
147
155
 
148
- .btn {
149
- @apply rounded border border-gray-300;
150
- }
156
+ /* ... any other imports or css classes */
151
157
  ```
152
158
 
153
- will be converted to
154
159
 
155
- ```css
156
- /* _site/assets/css/styles.css */
160
+ **File 2: `./assets/css/styles.tailwindcss`**
157
161
 
158
- /*
159
- * Tailwind generated CSS
160
- * ...
161
- .btn {
162
- border-radius: 0.25rem;
163
- border-style: var(--tw-border-style);
164
- border-width: 1px;
165
- border-color: var(--color-gray-300);
166
- }
167
- * ...
168
- */
162
+ Place this file wherever you'd like your site's tailwind CLI generated content to go: `assets/css/your_css_file.tailwindcss` -> `_site/assets/css/your_css_file.css`
163
+
164
+ It must contain yaml frontmatter to be processed by Jekyll [^1]
165
+
166
+ ```yaml
167
+ ---
168
+ # This file will be converted to _site/assets/css/styles.css
169
+ ---
170
+ This file is just a placeholder. Its content will be replaced by output from the tailwindcss CLI.
171
+ ```
172
+
173
+ > [!NOTE]
174
+ > Why the 2 files?
175
+ >
176
+ > This is a compromise to allow the [TailwindCSS intellisense](https://tailwindcss.com/docs/editor-setup#intellisense-for-vs-code) plugin to work. (It cannot parse a CSS file with frontmatter, so we keep it separate)
177
+ >
178
+ > The `_tailwind.css` file serves as the tailwindcss config file.
179
+ > If you'd rather keep this file somewhere else, you can do so by setting the `tailwindcss.css_path` option in `_config.yml`. A relative path is resolved against your site source, not the directory you run `jekyll` from (before 0.8.0 it was the latter, so drop any `src/`-style prefix you added for `source:`):
180
+ >
181
+ > ```yaml
182
+ > tailwindcss:
183
+ > css_path: ./_data/tailwind.css
184
+ > ```
185
+
186
+ ### Building the Jekyll site
187
+
188
+ ```sh
189
+ bundle exec jekyll serve
169
190
  ```
191
+ [^1]: Jekyll will process any file that begins with yaml [frontmatter](https://jekyllrb.com/docs/front-matter/)
192
+
170
193
 
171
194
  ### Minification
172
195
 
173
196
  The `--minify` flag is automatically added when the `JEKYLL_ENV` environment variable is present and set to anything other than `development`. [Jekyll Docs](https://jekyllrb.com/docs/configuration/environments/)
174
197
 
198
+ ## Troubleshooting
199
+
200
+ ### Build failures
201
+
202
+ If Tailwind can't compile your CSS, this gem raises an error and `jekyll build` exits non-zero, so your host fails the deploy instead of publishing an unstyled site.
203
+
204
+ If the error says `Cannot find the tailwindcss executable for x86_64-linux`, your `Gemfile.lock` probably lists the generic `ruby` platform, which installs `tailwindcss-ruby` without its binary. Run `bundle lock --add-platform x86_64-linux` and commit the lockfile. For ARM Linux, use `bundle lock --add-platform aarch64-linux`.
205
+
206
+ ### `Jekyll Tailwind: invalid byte sequence in US-ASCII`
207
+
208
+ The build machine has no UTF-8 locale (common on minimal CI images), so Ruby treats the tailwindcss CLI output as US-ASCII. Versions after 0.7.0 handle this for you. On 0.7.0 and earlier, set a UTF-8 locale in the build environment:
209
+
210
+ ```sh
211
+ export LANG=C.UTF-8
212
+ export LC_ALL=C.UTF-8
213
+ ```
214
+
175
215
  ## Development
176
216
 
177
217
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
@@ -199,15 +239,17 @@ end
199
239
 
200
240
  ### Cutting a release
201
241
 
242
+ Releases are published to RubyGems automatically via [trusted publishing](https://guides.rubygems.org/trusted-publishing/). Pushing the version tag is the publishing step — do not `gem push` by hand.
243
+
202
244
  - bump the version
203
245
  - [ ] update `lib/jekyll-tailwindcss/version.rb`
204
246
  - [ ] update `CHANGELOG.md`
205
247
  - [ ] bundle install to pick up the new version
206
- - [ ] commit and create a git tag ( example `git tag -a v0.3.1 -m "Release 0.3.1"` )
207
- - push
208
- - [ ] `bundle exec rake build`
209
- - [ ] `gem push pkg/jekyll-tailwind-[NEW_VERSION].gem
248
+ - [ ] commit and merge to `main`
249
+ - publish
250
+ - [ ] tag the release commit, matching the new version exactly ( example `git tag -a v0.3.1 -m "Release 0.3.1"` )
210
251
  - [ ] `git push --follow-tags`
252
+ - [ ] watch the `Release` workflow — it runs the test matrix, verifies the tag matches `VERSION`, and publishes the gem
211
253
  - announce
212
254
  - [ ] create a release at https://github.com/vormwald/jekyll-tailwindcss/releases
213
255
 
@@ -0,0 +1,46 @@
1
+ module Jekyll
2
+ module Converters
3
+ class Css < Converter
4
+ safe true
5
+ priority :low
6
+
7
+ def matches(ext)
8
+ /^\.css$/i.match?(ext)
9
+ end
10
+
11
+ def output_ext(ext)
12
+ # At this point, we will have a CSS file
13
+ ext
14
+ end
15
+
16
+ def convert(content)
17
+ return content unless /@tailwind|@import ['"]tailwindcss/i.match?(content)
18
+ if config_path.nil? && tailwind_v3_syntax?(content)
19
+ raise ::Jekyll::Tailwindcss::CompilationError,
20
+ "to use tailwind v3 you need to include a config path in _config.yml"
21
+ end
22
+
23
+ dev_mode = Jekyll.env == "development"
24
+ Jekyll.logger.info "Jekyll Tailwind:", "Generating #{"minified " unless dev_mode}CSS"
25
+
26
+ ::Jekyll::Tailwindcss::Commands.compile(content, debug: dev_mode, config_path: config_path, postcss_path: postcss_path)
27
+ end
28
+
29
+ private
30
+
31
+ def tailwind_v3_syntax?(content)
32
+ return false if content.include?("@plugin")
33
+
34
+ content.include?("@tailwind")
35
+ end
36
+
37
+ def config_path
38
+ @config.dig("tailwindcss", "config")
39
+ end
40
+
41
+ def postcss_path
42
+ @config.dig("tailwindcss", "postcss")
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,69 +1,44 @@
1
- require "open3"
2
-
3
1
  module Jekyll
4
2
  module Converters
5
3
  class Tailwindcss < Converter
6
4
  safe true
7
5
  priority :low
6
+ EXTENSION_PATTERN = %r{^\.tailwind(css)?$}i
8
7
 
9
8
  def matches(ext)
10
- /^\.css$/i.match?(ext)
9
+ EXTENSION_PATTERN.match? ext
11
10
  end
12
11
 
13
12
  def output_ext(ext)
14
- # At this point, we will have a CSS file
15
- ext
13
+ ".css"
16
14
  end
17
15
 
18
16
  def convert(content)
19
- return content unless /@tailwind|@import ['"]tailwindcss/i.match?(content)
20
- if config_path.nil? && tailwind_v3_syntax?(content)
21
- Jekyll.logger.error "Jekyll Tailwind:", "to use tailwind v3 you need to include a config path in _config.yml"
22
- return content
17
+ unless ::Jekyll::Tailwindcss.v4?
18
+ raise ::Jekyll::Tailwindcss::CompilationError, tailwind_v3_message
23
19
  end
24
20
 
25
21
  dev_mode = Jekyll.env == "development"
26
- Jekyll.logger.info "Jekyll Tailwind:", "Generating #{dev_mode ? "" : "minified "}CSS"
27
-
28
- compile_command = ::Tailwindcss::Commands
29
- .compile_command(debug: dev_mode, config_path: config_path, postcss_path: postcss_path)
30
- .join(" ")
22
+ Jekyll.logger.info "Jekyll Tailwind:", "Generating #{"minified " unless dev_mode}CSS"
31
23
 
32
- output, error = nil
33
- Open3.popen3(tailwindcss_env_options, compile_command) do |stdin, stdout, stderr, _wait_thread|
34
- stdin.write content # write the content of *.tailwindcss to the tailwindcss CLI as input
35
- stdin.close
36
- output = stdout.read
37
- error = stderr.read
38
- end
39
- Jekyll.logger.warn "Jekyll Tailwind:", error unless error.nil?
40
-
41
- output
42
- rescue => e
43
- Jekyll.logger.error "Jekyll Tailwind:", e.message
44
- content
24
+ ::Jekyll::Tailwindcss::Commands.compile(tailwind_content, debug: dev_mode, chdir: @config["source"])
45
25
  end
46
26
 
47
27
  private
48
28
 
49
- def tailwind_v3_syntax?(content)
50
- return false if content.include?("@plugin")
51
-
52
- content.include?("@tailwind")
53
- end
54
-
55
- def tailwindcss_env_options
56
- # Without this ENV you'll get a warning about `Browserslist: caniuse-lite is outdated`
57
- # Since we're using the CLI, we can't update the data, so we ignore it.
58
- {"BROWSERSLIST_IGNORE_OLD_DATA" => "1"}
59
- end
60
-
61
- def config_path
62
- @config.dig("tailwindcss", "config")
29
+ def tailwind_content
30
+ path = ::Jekyll::Tailwindcss.css_path(@config).gsub(/["\\]/) { |c| "\\#{c}" }
31
+ "@import \"#{path}\";"
63
32
  end
64
33
 
65
- def postcss_path
66
- @config.dig("tailwindcss", "postcss")
34
+ def tailwind_v3_message
35
+ <<~MESSAGE.chomp
36
+ You're using a .tailwindcss file extension, but your tailwindcss-ruby gem is below version 4.0.
37
+ The .tailwindcss extension is only supported in v4.0.0 and above. Please either:
38
+ - Upgrade with: bundle update tailwindcss-ruby
39
+ - Stay on v3 with a .css file and tailwind.config.js, as described in the README's "Tailwind Version 3 Setup" section:
40
+ https://github.com/vormwald/jekyll-tailwindcss#optional-choosing-a-specific-version-of-tailwindcss
41
+ MESSAGE
67
42
  end
68
43
  end
69
44
  end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+ require "tailwindcss/ruby"
5
+
6
+ module Jekyll
7
+ module Tailwindcss
8
+ # Raised when Tailwind can't produce CSS. Jekyll re-raises converter
9
+ # errors, so this fails `jekyll build` instead of publishing a broken
10
+ # stylesheet.
11
+ class CompilationError < StandardError; end
12
+
13
+ module Commands
14
+ # Without this ENV you'll get a warning about `Browserslist: caniuse-lite is outdated`
15
+ # Since we're using the CLI, we can't update the data, so we ignore it.
16
+ ENV_OPTIONS = {"BROWSERSLIST_IGNORE_OLD_DATA" => "1"}.freeze
17
+
18
+ class << self
19
+ def compile_command(debug: false, config_path: nil, postcss_path: nil, **kwargs)
20
+ command = [
21
+ executable(**kwargs),
22
+ "--input", "-"
23
+ ]
24
+ command += ["--config", config_path] if config_path
25
+ command += ["--postcss", postcss_path] if postcss_path
26
+
27
+ command << "--minify" unless debug
28
+
29
+ command
30
+ end
31
+
32
+ # Path to the platform-specific tailwindcss binary provided by the
33
+ # tailwindcss-ruby gem. Raises CompilationError when it's missing,
34
+ # most often because Gemfile.lock lacks the build machine's platform.
35
+ def executable(**kwargs)
36
+ ::Tailwindcss::Ruby.executable(**kwargs)
37
+ rescue ::Tailwindcss::Ruby::UnsupportedPlatformException,
38
+ ::Tailwindcss::Ruby::ExecutableNotFoundException,
39
+ ::Tailwindcss::Ruby::DirectoryNotFoundException => e
40
+ raise CompilationError, e.message
41
+ end
42
+
43
+ # Runs the tailwindcss CLI against `content` and returns the compiled
44
+ # CSS. Raises CompilationError if the CLI can't be found or run, or if
45
+ # it exits unsuccessfully.
46
+ #
47
+ # `chdir` sets the CLI's working directory. Tailwind resolves relative
48
+ # imports in stdin input and scans for class names from there, so
49
+ # callers pass the site source.
50
+ def compile(content, chdir: nil, **kwargs)
51
+ command = compile_command(**kwargs)
52
+ # The CLI reads and writes UTF-8. Without binmode, Ruby tags the
53
+ # captured output with Encoding.default_external, which follows the
54
+ # locale; under LANG=C that's US-ASCII and any non-ASCII byte (the
55
+ # CLI's own "≈ tailwindcss" banner, or a character in the CSS) makes
56
+ # later string operations raise "invalid byte sequence".
57
+ stdout, stderr, status = run(command, content, chdir: chdir)
58
+
59
+ unless status.success?
60
+ raise CompilationError, "tailwindcss CLI exited with status #{status.exitstatus}:\n#{stderr}"
61
+ end
62
+
63
+ Jekyll.logger.warn "Jekyll Tailwind:", stderr unless stderr.empty?
64
+
65
+ stdout
66
+ end
67
+
68
+ private
69
+
70
+ def run(command, content, chdir: nil)
71
+ options = {stdin_data: content, binmode: true}
72
+ options[:chdir] = chdir if chdir
73
+ stdout, stderr, status = Open3.capture3(ENV_OPTIONS, *command, **options)
74
+ stdout.force_encoding(Encoding::UTF_8)
75
+ stderr.force_encoding(Encoding::UTF_8)
76
+ [stdout, stderr, status]
77
+ rescue SystemCallError => e
78
+ raise CompilationError, "could not run the tailwindcss CLI (#{command.first}): #{e.message}"
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "pathname"
5
+
6
+ module Jekyll
7
+ module Tailwindcss
8
+ # `jekyll tailwindcss:install`. Jekyll registers every Jekyll::Command
9
+ # subclass, so the command shows up once the gem is loaded from the
10
+ # :jekyll_plugins Gemfile group.
11
+ class InstallCommand < Jekyll::Command
12
+ TAILWIND_CSS_CONTENT = <<~CSS
13
+ @import "tailwindcss";
14
+
15
+ /* Add any custom CSS or additional imports here */
16
+ CSS
17
+
18
+ STYLES_TAILWINDCSS_PATH = File.join("assets", "css", "styles.tailwindcss")
19
+
20
+ STYLES_TAILWINDCSS_CONTENT = <<~CSS
21
+ ---
22
+ ---
23
+ This content is replaced by output from the tailwindcss CLI.
24
+ CSS
25
+
26
+ LINK_TAG = %(<link rel="stylesheet" href="{{ '/assets/css/styles.css' | relative_url }}">)
27
+
28
+ V3_MESSAGE = <<~MESSAGE.chomp
29
+ tailwindcss:install sets up Tailwind v4, but your tailwindcss-ruby gem is below 4.0. Nothing was written.
30
+ Upgrade with `bundle update tailwindcss-ruby`, or set up v3 by hand as described in the README's "Tailwind Version 3 Setup" section:
31
+ https://github.com/vormwald/jekyll-tailwindcss#optional-choosing-a-specific-version-of-tailwindcss
32
+ MESSAGE
33
+
34
+ class << self
35
+ def init_with_program(prog)
36
+ prog.command(:"tailwindcss:install") do |c|
37
+ c.syntax "tailwindcss:install [options]"
38
+ c.description "Create the files needed to use Tailwind CSS v4 in this Jekyll site"
39
+ c.option "source", "-s", "--source SOURCE", "Custom source directory"
40
+ c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array, "Custom configuration file"
41
+
42
+ c.action do |_args, opts|
43
+ process(opts)
44
+ end
45
+ end
46
+ end
47
+
48
+ def process(opts = {})
49
+ Jekyll.logger.abort_with "Jekyll Tailwind:", V3_MESSAGE unless Jekyll::Tailwindcss.v4?
50
+
51
+ config = configuration_from_options(opts)
52
+ created = [
53
+ create_file(Jekyll::Tailwindcss.css_path(config), TAILWIND_CSS_CONTENT),
54
+ create_file(File.join(config["source"], STYLES_TAILWINDCSS_PATH), STYLES_TAILWINDCSS_CONTENT)
55
+ ].any?
56
+ return unless created
57
+
58
+ Jekyll.logger.info "Jekyll Tailwind:", "Next steps:"
59
+ Jekyll.logger.info "Jekyll Tailwind:", " Add #{LINK_TAG} to your layout's <head>"
60
+ Jekyll.logger.info "Jekyll Tailwind:", " Run `bundle exec jekyll serve`"
61
+ end
62
+
63
+ private
64
+
65
+ # Writes `content` to `path` unless it exists. Returns true if it
66
+ # created the file.
67
+ def create_file(path, content)
68
+ if File.exist?(path)
69
+ Jekyll.logger.info "Jekyll Tailwind:", "Skipped #{display_path(path)} (already exists)"
70
+ return false
71
+ end
72
+
73
+ FileUtils.mkdir_p(File.dirname(path))
74
+ File.write(path, content)
75
+ Jekyll.logger.info "Jekyll Tailwind:", "Created #{display_path(path)}"
76
+ true
77
+ end
78
+
79
+ # `path` relative to the working directory when it's inside it,
80
+ # otherwise absolute.
81
+ def display_path(path)
82
+ relative = Pathname.new(path).relative_path_from(Pathname.pwd).to_s
83
+ relative.start_with?("..") ? path : relative
84
+ rescue ArgumentError
85
+ path
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Tailwindcss
5
- VERSION = "0.6.2"
5
+ VERSION = "0.8.0"
6
6
  end
7
7
  end
@@ -2,13 +2,33 @@
2
2
 
3
3
  require "jekyll"
4
4
  require_relative "jekyll-tailwindcss/version"
5
+ require_relative "jekyll/tailwindcss/commands"
6
+ require_relative "jekyll/tailwindcss/install_command"
7
+ require_relative "jekyll/converters/css"
5
8
  require_relative "jekyll/converters/tailwindcss"
6
- require_relative "tailwindcss/commands"
7
9
 
8
10
  module Jekyll
9
11
  module Tailwindcss
10
- end
11
- end
12
+ DEFAULT_CSS_PATH = "./_tailwind.css"
13
+
14
+ class << self
15
+ # Absolute path of the stylesheet that `.tailwindcss` files compile.
16
+ # A relative `tailwindcss.css_path` is resolved against the site source,
17
+ # not the working directory, so `jekyll build --source <dir>` works.
18
+ def css_path(config)
19
+ path = config.dig("tailwindcss", "css_path") || DEFAULT_CSS_PATH
20
+ File.expand_path(path, config["source"])
21
+ end
12
22
 
13
- module Tailwindcss
23
+ # True when the loaded tailwindcss-ruby gem is 4.0 or newer.
24
+ def v4?
25
+ spec = Gem.loaded_specs["tailwindcss-ruby"]
26
+ return false unless spec
27
+
28
+ Gem::Version.new(spec.version) >= Gem::Version.new("4.0.0")
29
+ rescue ArgumentError
30
+ false
31
+ end
32
+ end
33
+ end
14
34
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-tailwindcss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Vormwald
8
- bindir: exe
8
+ bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-03 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: tailwindcss-ruby
@@ -29,18 +29,25 @@ executables: []
29
29
  extensions: []
30
30
  extra_rdoc_files: []
31
31
  files:
32
+ - CHANGELOG.md
32
33
  - LICENSE
33
34
  - README.md
34
35
  - Rakefile
35
36
  - lib/jekyll-tailwindcss.rb
36
37
  - lib/jekyll-tailwindcss/version.rb
38
+ - lib/jekyll/converters/css.rb
37
39
  - lib/jekyll/converters/tailwindcss.rb
38
- - lib/tailwindcss/commands.rb
40
+ - lib/jekyll/tailwindcss/commands.rb
41
+ - lib/jekyll/tailwindcss/install_command.rb
39
42
  homepage: https://github.com/vormwald/jekyll-tailwindcss
40
43
  licenses:
41
44
  - MIT
42
45
  metadata:
43
46
  homepage_uri: https://github.com/vormwald/jekyll-tailwindcss
47
+ changelog_uri: https://github.com/vormwald/jekyll-tailwindcss/blob/main/CHANGELOG.md
48
+ source_code_uri: https://github.com/vormwald/jekyll-tailwindcss
49
+ bug_tracker_uri: https://github.com/vormwald/jekyll-tailwindcss/issues
50
+ rubygems_mfa_required: 'true'
44
51
  rdoc_options: []
45
52
  require_paths:
46
53
  - lib
@@ -48,14 +55,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
55
  requirements:
49
56
  - - ">="
50
57
  - !ruby/object:Gem::Version
51
- version: 3.1.0
58
+ version: 3.2.0
52
59
  required_rubygems_version: !ruby/object:Gem::Requirement
53
60
  requirements:
54
61
  - - ">="
55
62
  - !ruby/object:Gem::Version
56
63
  version: '0'
57
64
  requirements: []
58
- rubygems_version: 3.6.2
65
+ rubygems_version: 4.0.20
59
66
  specification_version: 4
60
67
  summary: Integrate Tailwind CSS into your Jekyll site.
61
68
  test_files: []
@@ -1,20 +0,0 @@
1
- require "tailwindcss/ruby"
2
-
3
- module Tailwindcss
4
- module Commands
5
- class << self
6
- def compile_command(debug: false, config_path: nil, postcss_path: nil, **kwargs)
7
- command = [
8
- Tailwindcss::Ruby.executable(**kwargs),
9
- "--input", "-"
10
- ]
11
- command += ["--config", config_path] if config_path
12
- command += ["--postcss", postcss_path] if postcss_path
13
-
14
- command << "--minify" unless debug
15
-
16
- command
17
- end
18
- end
19
- end
20
- end