Class: Jekyll::Tailwind

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-tailwind.rb,
lib/jekyll-tailwind/version.rb

Constant Summary collapse

VERSION =
"2.1.1"

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Tailwind

Returns a new instance of Tailwind.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jekyll-tailwind.rb', line 11

def initialize(config)
  if config["config_path"]
    Jekyll.logger.warn "WARNING: The `config_path` option is deprecated and will be removed in the next releases. Please use the `config` option instead."
  end
  if config["version"]
    Jekyll.logger.warn "WARNING: The `version` option has no effect, version could be managed through 'tailwindcss-ruby' gem in you're Gemfile."
  end

  @config = config["config_path"] || config["config"] || "tailwind.config.js"
  @postcss = config.fetch("postcss", "postcss.config.js")

  @input = if config["input"].is_a?(Array)
    Jekyll.logger.warn "DEPRECATION: jekyll-tailwind gem can't have multiple input files. Ability to provide array as input will be gradually fazed out. Change array value like this `[assets/css/app.css]` to `assets/css/app.css`"

    raise "Multiple input files are not supported" if config["input"].length > 1

    config["input"].first
  else
    config["input"]
  end
  @output = config.fetch("output", "_site/assets/css/app.css")
  @minify = config.fetch("minify", false)
end

Instance Method Details

#compile ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jekyll-tailwind.rb', line 35

def compile
  command = [
            Shellwords.escape(Tailwindcss::Ruby.executable),
            "--output", @output.shellescape,
            "--config", @config.shellescape,
          ]

  command += ["--input", @input.shellescape] if @input
  command += ["--minify"] if @minify
  command += ["--postcss", @postcss.shellescape] if File.exist?(@postcss)

  `#{command.join(' ')}`
end