jekyll-tailwindcss 0.7.0 → 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 +4 -4
- data/CHANGELOG.md +74 -0
- data/README.md +45 -10
- data/lib/jekyll/converters/css.rb +4 -28
- data/lib/jekyll/converters/tailwindcss.rb +14 -45
- data/lib/jekyll/tailwindcss/commands.rb +83 -0
- data/lib/jekyll/tailwindcss/install_command.rb +90 -0
- data/lib/jekyll-tailwindcss/version.rb +1 -1
- data/lib/jekyll-tailwindcss.rb +23 -4
- metadata +12 -6
- data/lib/tailwindcss/commands.rb +0 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1dbaabf8182ffec1b921e55302c42347e79a050e34dbf4d81f12c519a7b0ce1c
|
|
4
|
+
data.tar.gz: 58f26e5d0c0fe75f8332b110891e60486fc0c5682ddd023af7729de84a13b55b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
@@ -127,6 +127,22 @@ tailwindcss:
|
|
|
127
127
|
|
|
128
128
|
> See an example repo at https://github.com/vormwald/jekyll-blahg
|
|
129
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
|
+
|
|
134
|
+
```sh
|
|
135
|
+
bundle exec jekyll tailwindcss:install
|
|
136
|
+
```
|
|
137
|
+
|
|
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>`:
|
|
139
|
+
|
|
140
|
+
```html
|
|
141
|
+
<link rel="stylesheet" href="{{ '/assets/css/styles.css' | relative_url }}">
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The command doesn't support Tailwind v3. For v3, follow the [Tailwind Version 3 Setup](#optional-choosing-a-specific-version-of-tailwindcss).
|
|
145
|
+
|
|
130
146
|
### Setup
|
|
131
147
|
You'll need 2 files to make this work:
|
|
132
148
|
|
|
@@ -143,28 +159,28 @@ This file acts as your tailwind configuration file. Import "tailwindcss" and any
|
|
|
143
159
|
|
|
144
160
|
**File 2: `./assets/css/styles.tailwindcss`**
|
|
145
161
|
|
|
146
|
-
Place this file wherever you'd like your site's tailwind CLI generated content to go: `assets/css/your_css_file.tailwindcss` -> `
|
|
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`
|
|
147
163
|
|
|
148
164
|
It must contain yaml frontmatter to be processed by Jekyll [^1]
|
|
149
165
|
|
|
150
166
|
```yaml
|
|
151
167
|
---
|
|
152
|
-
# This file will be converted to
|
|
168
|
+
# This file will be converted to _site/assets/css/styles.css
|
|
153
169
|
---
|
|
154
|
-
This file is just a placeholder.
|
|
170
|
+
This file is just a placeholder. Its content will be replaced by output from the tailwindcss CLI.
|
|
155
171
|
```
|
|
156
172
|
|
|
157
173
|
> [!NOTE]
|
|
158
174
|
> Why the 2 files?
|
|
159
175
|
>
|
|
160
|
-
> 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
|
|
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)
|
|
161
177
|
>
|
|
162
178
|
> The `_tailwind.css` file serves as the tailwindcss config file.
|
|
163
|
-
> If you'd rather
|
|
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:`):
|
|
164
180
|
>
|
|
165
181
|
> ```yaml
|
|
166
182
|
> tailwindcss:
|
|
167
|
-
>
|
|
183
|
+
> css_path: ./_data/tailwind.css
|
|
168
184
|
> ```
|
|
169
185
|
|
|
170
186
|
### Building the Jekyll site
|
|
@@ -179,6 +195,23 @@ bundle exec jekyll serve
|
|
|
179
195
|
|
|
180
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/)
|
|
181
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
|
+
|
|
182
215
|
## Development
|
|
183
216
|
|
|
184
217
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
|
@@ -206,15 +239,17 @@ end
|
|
|
206
239
|
|
|
207
240
|
### Cutting a release
|
|
208
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
|
+
|
|
209
244
|
- bump the version
|
|
210
245
|
- [ ] update `lib/jekyll-tailwindcss/version.rb`
|
|
211
246
|
- [ ] update `CHANGELOG.md`
|
|
212
247
|
- [ ] bundle install to pick up the new version
|
|
213
|
-
- [ ] commit and
|
|
214
|
-
-
|
|
215
|
-
- [ ] `
|
|
216
|
-
- [ ] `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"` )
|
|
217
251
|
- [ ] `git push --follow-tags`
|
|
252
|
+
- [ ] watch the `Release` workflow — it runs the test matrix, verifies the tag matches `VERSION`, and publishes the gem
|
|
218
253
|
- announce
|
|
219
254
|
- [ ] create a release at https://github.com/vormwald/jekyll-tailwindcss/releases
|
|
220
255
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require "open3"
|
|
2
|
-
|
|
3
1
|
module Jekyll
|
|
4
2
|
module Converters
|
|
5
3
|
class Css < Converter
|
|
@@ -18,30 +16,14 @@ module Jekyll
|
|
|
18
16
|
def convert(content)
|
|
19
17
|
return content unless /@tailwind|@import ['"]tailwindcss/i.match?(content)
|
|
20
18
|
if config_path.nil? && tailwind_v3_syntax?(content)
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
raise ::Jekyll::Tailwindcss::CompilationError,
|
|
20
|
+
"to use tailwind v3 you need to include a config path in _config.yml"
|
|
23
21
|
end
|
|
24
22
|
|
|
25
23
|
dev_mode = Jekyll.env == "development"
|
|
26
|
-
Jekyll.logger.info "Jekyll Tailwind:", "Generating #{
|
|
27
|
-
|
|
28
|
-
compile_command = ::Tailwindcss::Commands
|
|
29
|
-
.compile_command(debug: dev_mode, config_path: config_path, postcss_path: postcss_path)
|
|
30
|
-
.join(" ")
|
|
31
|
-
|
|
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?
|
|
24
|
+
Jekyll.logger.info "Jekyll Tailwind:", "Generating #{"minified " unless dev_mode}CSS"
|
|
40
25
|
|
|
41
|
-
|
|
42
|
-
rescue => e
|
|
43
|
-
Jekyll.logger.error "Jekyll Tailwind:", e.message
|
|
44
|
-
content
|
|
26
|
+
::Jekyll::Tailwindcss::Commands.compile(content, debug: dev_mode, config_path: config_path, postcss_path: postcss_path)
|
|
45
27
|
end
|
|
46
28
|
|
|
47
29
|
private
|
|
@@ -52,12 +34,6 @@ module Jekyll
|
|
|
52
34
|
content.include?("@tailwind")
|
|
53
35
|
end
|
|
54
36
|
|
|
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
37
|
def config_path
|
|
62
38
|
@config.dig("tailwindcss", "config")
|
|
63
39
|
end
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require "open3"
|
|
2
|
-
|
|
3
1
|
module Jekyll
|
|
4
2
|
module Converters
|
|
5
3
|
class Tailwindcss < Converter
|
|
@@ -16,60 +14,31 @@ module Jekyll
|
|
|
16
14
|
end
|
|
17
15
|
|
|
18
16
|
def convert(content)
|
|
19
|
-
unless
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return
|
|
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 #{
|
|
27
|
-
|
|
28
|
-
compile_command = ::Tailwindcss::Commands
|
|
29
|
-
.compile_command(debug: dev_mode)
|
|
30
|
-
.join(" ")
|
|
31
|
-
|
|
32
|
-
output, error = nil
|
|
33
|
-
Open3.popen3(compile_command) do |stdin, stdout, stderr, _wait_thread|
|
|
34
|
-
stdin.write tailwind_content
|
|
35
|
-
stdin.close
|
|
36
|
-
output = stdout.read
|
|
37
|
-
error = stderr.read
|
|
38
|
-
end
|
|
39
|
-
Jekyll.logger.warn "Jekyll Tailwind:", error unless error.nil?
|
|
22
|
+
Jekyll.logger.info "Jekyll Tailwind:", "Generating #{"minified " unless dev_mode}CSS"
|
|
40
23
|
|
|
41
|
-
|
|
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
29
|
def tailwind_content
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def tailwind_css_path
|
|
54
|
-
@config.dig("tailwindcss", "css_path") || "./_tailwind.css"
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def valid_tailwindcss_gem_version?
|
|
58
|
-
gem_spec = Gem.loaded_specs["tailwindcss-ruby"]
|
|
59
|
-
return false unless gem_spec
|
|
60
|
-
|
|
61
|
-
Gem::Version.new(gem_spec.version) >= Gem::Version.new("4.0.0")
|
|
62
|
-
rescue
|
|
63
|
-
# If anything goes wrong (gem not found, version format issues, etc.)
|
|
64
|
-
false
|
|
30
|
+
path = ::Jekyll::Tailwindcss.css_path(@config).gsub(/["\\]/) { |c| "\\#{c}" }
|
|
31
|
+
"@import \"#{path}\";"
|
|
65
32
|
end
|
|
66
33
|
|
|
67
|
-
def
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
|
73
42
|
end
|
|
74
43
|
end
|
|
75
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
|
data/lib/jekyll-tailwindcss.rb
CHANGED
|
@@ -2,14 +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"
|
|
5
7
|
require_relative "jekyll/converters/css"
|
|
6
8
|
require_relative "jekyll/converters/tailwindcss"
|
|
7
|
-
require_relative "tailwindcss/commands"
|
|
8
9
|
|
|
9
10
|
module Jekyll
|
|
10
11
|
module Tailwindcss
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
13
22
|
|
|
14
|
-
|
|
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
|
|
15
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.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Vormwald
|
|
8
|
-
bindir:
|
|
8
|
+
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
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,6 +29,7 @@ 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
|
|
@@ -36,12 +37,17 @@ files:
|
|
|
36
37
|
- lib/jekyll-tailwindcss/version.rb
|
|
37
38
|
- lib/jekyll/converters/css.rb
|
|
38
39
|
- lib/jekyll/converters/tailwindcss.rb
|
|
39
|
-
- lib/tailwindcss/commands.rb
|
|
40
|
+
- lib/jekyll/tailwindcss/commands.rb
|
|
41
|
+
- lib/jekyll/tailwindcss/install_command.rb
|
|
40
42
|
homepage: https://github.com/vormwald/jekyll-tailwindcss
|
|
41
43
|
licenses:
|
|
42
44
|
- MIT
|
|
43
45
|
metadata:
|
|
44
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'
|
|
45
51
|
rdoc_options: []
|
|
46
52
|
require_paths:
|
|
47
53
|
- lib
|
|
@@ -49,14 +55,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
49
55
|
requirements:
|
|
50
56
|
- - ">="
|
|
51
57
|
- !ruby/object:Gem::Version
|
|
52
|
-
version: 3.
|
|
58
|
+
version: 3.2.0
|
|
53
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
60
|
requirements:
|
|
55
61
|
- - ">="
|
|
56
62
|
- !ruby/object:Gem::Version
|
|
57
63
|
version: '0'
|
|
58
64
|
requirements: []
|
|
59
|
-
rubygems_version:
|
|
65
|
+
rubygems_version: 4.0.20
|
|
60
66
|
specification_version: 4
|
|
61
67
|
summary: Integrate Tailwind CSS into your Jekyll site.
|
|
62
68
|
test_files: []
|
data/lib/tailwindcss/commands.rb
DELETED
|
@@ -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
|