Class: Jekyll::Converters::Css

Inherits:
Converter
  • Object
show all
Defined in:
lib/jekyll/converters/css.rb

Instance Method Summary collapse

Instance Method Details

#convert(content) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jekyll/converters/css.rb', line 18

def convert(content)
  return content unless /@tailwind|@import ['"]tailwindcss/i.match?(content)
  if config_path.nil? && tailwind_v3_syntax?(content)
    Jekyll.logger.error "Jekyll Tailwind:", "to use tailwind v3 you need to include a config path in _config.yml"
    return content
  end

  dev_mode = Jekyll.env == "development"
  Jekyll.logger.info "Jekyll Tailwind:", "Generating #{dev_mode ? "" : "minified "}CSS"

  compile_command = ::Tailwindcss::Commands
    .compile_command(debug: dev_mode, config_path: config_path, postcss_path: postcss_path)
    .join(" ")

  output, error = nil
  Open3.popen3(tailwindcss_env_options, compile_command) do |stdin, stdout, stderr, _wait_thread|
    stdin.write content # write the content of *.tailwindcss to the tailwindcss CLI as input
    stdin.close
    output = stdout.read
    error = stderr.read
  end
  Jekyll.logger.warn "Jekyll Tailwind:", error unless error.nil?

  output
rescue => e
  Jekyll.logger.error "Jekyll Tailwind:", e.message
  content
end

#matches(ext) ⇒ Object



9
10
11
# File 'lib/jekyll/converters/css.rb', line 9

def matches(ext)
  /^\.css$/i.match?(ext)
end

#output_ext(ext) ⇒ Object



13
14
15
16
# File 'lib/jekyll/converters/css.rb', line 13

def output_ext(ext)
  # At this point, we will have a CSS file
  ext
end