Sha256: aa2abb498aa835aeee8fe60aa0b68e7c898caf851b9cca9c5345542aac7f9a34

Contents?: true

Size: 711 Bytes

Versions: 1

Compression:

Stored size: 711 Bytes

Contents

# frozen_string_literal: true

require "socket"
require "json"

module PostCss
  class Socket
    START_SCRIPT = File.expand_path("../../bin/command", __dir__)
    POSTCSS_SCRIPT = File.expand_path("../../bin/postcss", __dir__)

    def initialize
      Thread.new do
        system "#{START_SCRIPT} #{POSTCSS_SCRIPT}"
      end

      @postcss = nil
      while @postcss.nil?
        begin
          @postcss = TCPSocket.open("localhost", 8124)
        rescue StandardError
          nil # Suppressing exceptions
        end
      end
    end

    def write(data)
      @postcss.puts JSON.dump(:raw_content => data)
    end

    def read
      JSON.parse(@postcss.gets.chomp)["compiled_css"]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-postcss-0.3.0 lib/jekyll-postcss/socket.rb