Class: Middleman::Tailwind::Main

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman/tailwind.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ Main

Returns a new instance of Main.



14
15
16
17
18
19
20
21
22
# File 'lib/middleman/tailwind.rb', line 14

def initialize(app, options_hash = {}, &block)
  super

  @gem_dir = File.expand_path "../..", __dir__
  @project_dir = Dir.pwd
  @config_path = options.config_path
  @css_path = options.css_path
  @destination_path = options.destination_path
end

Instance Method Details

#application_cssObject



32
33
34
35
36
# File 'lib/middleman/tailwind.rb', line 32

def application_css
  return File.join(@project_dir, @css_path) if @css_path

  File.join(@gem_dir, "tailwind/application.tailwind.css")
end

#config_fileObject



42
43
44
45
46
# File 'lib/middleman/tailwind.rb', line 42

def config_file
  return File.join(@project_dir, @config_path) if @config_path

  File.join(@gem_dir, "tailwind/tailwind.config.js")
end

#destinationObject



38
39
40
# File 'lib/middleman/tailwind.rb', line 38

def destination
  File.join(@project_dir, @destination_path)
end

#executableObject



28
29
30
# File 'lib/middleman/tailwind.rb', line 28

def executable
  Upstream::NATIVE_PLATFORMS[platform]
end

#platformObject



24
25
26
# File 'lib/middleman/tailwind.rb', line 24

def platform
  %i[cpu os].map { |m| Gem::Platform.local.send(m) }.join("-")
end

#readyObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/middleman/tailwind.rb', line 48

def ready
  exe = File.join(@gem_dir, "exe/#{executable}")
  cmd = "#{exe} -c #{config_file} -i #{application_css} -o #{destination}"

  if app.mode?(:server)
    Thread.new do
      system("#{cmd} -w", out: $stdout)
    end
  else
    puts "Building Tailwind CSS..."
    system(cmd, out: $stdout)
  end
end