Class: Jscon::Repl
Defined Under Namespace
Classes: NoServer
Instance Method Summary collapse
- #after_input ⇒ Object
- #before_input ⇒ Object
- #compile(input) ⇒ Object
-
#initialize(options) ⇒ Repl
constructor
A new instance of Repl.
- #process_input(input) ⇒ Object
- #repl_write(value) ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
Constructor Details
Instance Method Details
#after_input ⇒ Object
50 51 52 53 |
# File 'lib/jscon/repl.rb', line 50 def after_input @asset_server.close @asset_server = NoServer end |
#before_input ⇒ Object
25 26 27 |
# File 'lib/jscon/repl.rb', line 25 def before_input @asset_server = Jscon::AssetServer.start if @asset_server == NoServer end |
#compile(input) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jscon/repl.rb', line 38 def compile(input) input = input.gsub('\n', ?\n) begin input = CoffeeScript.compile(input, bare: true) if @options.coffee? rescue ExecJS::RuntimeError => runtime_error repl_write runtime_error. throw :skip_process_input end repl_write input if @options.showjs? return input end |
#process_input(input) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/jscon/repl.rb', line 29 def process_input(input) File.open(@pipe_in, "w+") do |pipe| input = compile(input) pipe.write(input) pipe.flush end repl_write IO.read(@pipe_out) end |
#repl_write(value) ⇒ Object
14 |
# File 'lib/jscon/repl.rb', line 14 def repl_write(value); puts value; end |
#setup ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/jscon/repl.rb', line 16 def setup @pipe_in, @pipe_out = Jscon::Pipes.create_set("js_repl") repl_write "loading" @asset_server = Jscon::AssetServer.start = "" = "application" if @asset_server.is_started? @phantom_pid = Jscon::Phantom.run_exec(Jscon::Dir.path, ) end |
#teardown ⇒ Object
55 56 57 |
# File 'lib/jscon/repl.rb', line 55 def teardown Process.kill(term=15, @phantom_pid) end |