Class: Clementine::ClojureScriptEngine

Inherits:
ClojureScriptEngineBase show all
Defined in:
lib/clementine/clojurescript_engine/mri.rb,
lib/clementine/clojurescript_engine/jruby.rb

Instance Method Summary collapse

Methods inherited from ClojureScriptEngineBase

#default_opts

Constructor Details

#initialize(file, options) ⇒ ClojureScriptEngine

Returns a new instance of ClojureScriptEngine.



11
12
13
14
15
# File 'lib/clementine/clojurescript_engine/mri.rb', line 11

def initialize(file, options)
  @file = file
  @options = options
  @classpath = CLASSPATH
end

Instance Method Details

#commandObject



45
46
47
48
49
50
51
52
# File 'lib/clementine/clojurescript_engine/mri.rb', line 45

def command
  if defined? Nailgun
    setup_classpath_for_ng
    [nailgun_prefix, 'clojure.main', "#{CLOJURESCRIPT_HOME}/bin/cljsc.clj"].flatten.join(' ')
  else
    ["java", '-cp', "\"#{@classpath.join ":"}\"", 'clojure.main', "#{CLOJURESCRIPT_HOME}/bin/cljsc.clj"].flatten.join(' ')
  end
end

#compileObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/clementine/clojurescript_engine/mri.rb', line 17

def compile
  @options = default_opts.merge(Clementine.options) if Clementine.options
  begin
    cmd = %Q{#{command} #{@file} '#{convert_options(@options)}' 2>&1}
    result = `#{cmd}`
  rescue Exception
    raise Error, "compression failed: #{result || $!}"
  end
  unless $?.exitstatus.zero?
    raise Error, result
  end
  result
end

#convert_options(options) ⇒ Object

private



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/clementine/clojurescript_engine/mri.rb', line 55

def convert_options(options)
  opts = ""
  options.each do |k, v|
    cl_key = ":" + Clementine.ruby2clj(k.to_s)
    case
    when (v.kind_of? Symbol)
      cl_value = ":" + Clementine.ruby2clj(v.to_s)
    when v.is_a?(TrueClass) || v.is_a?(FalseClass)
      cl_value = v.to_s
    else
      cl_value = "\"" + v + "\""
    end
    opts += cl_key + " " + cl_value + " "
  end
  "{" + opts.chop! + "}"
end

#nailgun_prefixObject



31
32
33
34
35
# File 'lib/clementine/clojurescript_engine/mri.rb', line 31

def nailgun_prefix
  server_address = Nailgun::NailgunConfig.options[:server_address]
  port_no  = Nailgun::NailgunConfig.options[:port_no]
  "#{Nailgun::NgCommand::NGPATH} --nailgun-port #{port_no} --nailgun-server #{server_address}"
end

#setup_classpath_for_ngObject



37
38
39
40
41
42
43
# File 'lib/clementine/clojurescript_engine/mri.rb', line 37

def setup_classpath_for_ng
  current_cp = `#{nailgun_prefix} ng-cp`
  unless current_cp.include? "clojure.jar"
    puts "Initializing nailgun classpath, required clementine dependencies missing"
    `#{nailgun_prefix} ng-cp #{@classpath.join " "}`
  end
end