Sha256: 41d1229373862ec2847ea16836e6877bd2e6ab2c52d4de19b33a068432ee8cdc

Contents?: true

Size: 947 Bytes

Versions: 1

Compression:

Stored size: 947 Bytes

Contents

require "sibilant/version"
require 'json'
require 'open3'

module Sibilant
  class CompilationError < RuntimeError; end

  class << self
    def [](sibilant_code)
      Sibilant::Compiler.new.translate sibilant_code
    end
  end

  class Compiler
    def sibilant_js_root
      File.join File.dirname(__FILE__), '..', 'js', 'sibilant'
    end

    def package_json_file
      File.open File.join(sibilant_js_root, 'package.json')
    end

    def package_json
      JSON.parse package_json_file.read
    end

    def version
      package_json[:version]
    end

    def sibilant_cli
      File.join sibilant_js_root, 'bin', 'sibilant'
    end

    def translate(sibilant_code)
      Open3.popen3 sibilant_cli, '-i' do |i,o,e,t|
        i.puts sibilant_code
        i.close_write

        if t.value.success?
          o.read.strip
        else
          raise Sibilant::CompilationError.new(e.read.strip)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sibilant-0.0.4 lib/sibilant.rb