Class: PostCss::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-postcss/socket.rb

Defined Under Namespace

Classes: PostCssRuntimeError

Constant Summary collapse

START_SCRIPT =
File.expand_path("../../bin/command", __dir__)
POSTCSS_SCRIPT =
File.expand_path("../../bin/postcss", __dir__)

Instance Method Summary collapse

Constructor Details

#initializeSocket

Returns a new instance of Socket.



12
13
14
# File 'lib/jekyll-postcss/socket.rb', line 12

def initialize
  start_dev_server if development?
end

Instance Method Details

#readObject



26
27
28
29
30
31
32
33
34
# File 'lib/jekyll-postcss/socket.rb', line 26

def read
  if development?
    decode(@postcss.gets.chomp)
  else
    raise "You must call PostCss#write before calling PostCss#read" if @compiled_css.nil?

    decode(@compiled_css)
  end
end

#write(data) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/jekyll-postcss/socket.rb', line 16

def write(data)
  if development?
    @postcss.puts encode(data)
  else
    @compiled_css = `#{POSTCSS_SCRIPT} '#{encode(data)}'`
  end

  nil
end