Sha256: 727ee270143dd719f39df95bb9223e9926c9c207c8f95dd2ab14f13b56cc9f78
Contents?: true
Size: 1005 Bytes
Versions: 1
Compression:
Stored size: 1005 Bytes
Contents
require 'elm/compiler/exceptions' require 'open3' require 'tempfile' require 'mkmf' module Elm class Compiler class << self def compile(elm_files, output_path = nil) fail ExecutableNotFound unless elm_executable_exists? if output_path elm_make(elm_files, output_path) else compile_to_string(elm_files) end end private def elm_executable_exists? !find_executable0('elm-make').nil? end def compile_to_string(elm_files) output = '' Tempfile.open(['elm', '.js']) do |tempfile| elm_make(elm_files, tempfile.path) output = File.read tempfile.path end output end def elm_make(elm_files, output_path) Open3.popen3('elm-make', *elm_files, '--yes', '--output', output_path) do |_stdin, _stdout, stderr, wait_thr| fail CompileError, stderr.gets(nil) if wait_thr.value.exitstatus != 0 end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
elm-compiler-0.1.2 | lib/elm/compiler.rb |