class ElmCompiler
Constants
- ELM_COMMAND
Public Class Methods
new(content)
click to toggle source
# File lib/elm_compiler.rb, line 7 def initialize(content) setup_dir @content = content end
Public Instance Methods
process!()
click to toggle source
# File lib/elm_compiler.rb, line 13 def process! output = '', status = nil with_error_handling do result = File.open(tmp_path, 'w') { |f| f.write(@content) } out, err, status = Open3.capture3("#{ELM_COMMAND} #{tmp_path} --output #{dest_path}") if status.success? output = File.read(dest_path) File.delete(dest_path) else puts '*** ERROR: Elm' puts "** OUT:\n#{out}" puts "** ERR:\n#{err}" end end output end
Private Instance Methods
dest_path()
click to toggle source
# File lib/elm_compiler.rb, line 68 def dest_path File.join(elm_dir, 'build', "#{tmp_file}.html") end
elm_dir()
click to toggle source
# File lib/elm_compiler.rb, line 56 def elm_dir '_elm' end
in_elm_dir() { || ... }
click to toggle source
# File lib/elm_compiler.rb, line 50 def in_elm_dir Dir.chdir(elm_dir) yield Dir.chdir('..') end
setup_dir()
click to toggle source
# File lib/elm_compiler.rb, line 36 def setup_dir Dir.mkdir(elm_dir) unless File.exist?(elm_dir) && File.directory?(elm_dir) end
tmp_file()
click to toggle source
# File lib/elm_compiler.rb, line 60 def tmp_file @tmp_file ||= SecureRandom.hex(16) end
tmp_path()
click to toggle source
# File lib/elm_compiler.rb, line 64 def tmp_path File.join(elm_dir, "#{tmp_file}.elm") end
with_error_handling() { || ... }
click to toggle source
# File lib/elm_compiler.rb, line 40 def with_error_handling begin yield rescue Errno::ENOENT => e puts "*** ERROR Elm: #{e.inspect}" ensure File.delete(tmp_path) end end