Permalink
Browse files

Move eval from a legacy action to POST /eval.

  • Loading branch information...
eventualbuddha committed Mar 18, 2012
1 parent e51713d commit 4cfd4c94199cbaa908f91bd75a5f5ddb98fcb7b5
Showing with 30 additions and 34 deletions.
  1. +25 −32 application/chrome/content/wesabe/download/Controller.coffee
  2. +4 −1 script/api.rb
  3. +1 −1 script/console.rb
@@ -38,10 +38,33 @@ class Controller
@[action]? @server.request.json.body, (resdata) =>
@server.deliver resdata
else
- throw new Server.NotFoundError "Unrecognized request action #{inspect action}"
+ message = "Unrecognized legacy action #{inspect action}"
+ logger.error message
+ throw new Server.NotFoundError message
- return true
+ @server.post '/eval', =>
+ params = @server.request.json
+ script = params.script
+ @scope ||=
+ logger: Logger.loggerForFile('repl'),
+ __filename: 'repl',
+ __dirname: '.'
+ @scope.job = @job
+
+ if params.type is 'text/coffeescript'
+ script = string.trim(CoffeeScript.compile "(-> #{script})()", bare: on)
+ else
+ script = "(function(){#{script}})()" if /[;\n]/.test script
+
+ script = "return #{script}"
+ result = func.callWithScope script, @scope, @scope
+
+ @scope._ = result
+
+ @server.deliver {result: inspect(result, undefined, undefined, color: params.color)}
+
+ return true
job_start: (data, respond) ->
try
@@ -202,34 +225,4 @@ class Controller
status: 'error'
error: e.toString()
- eval: (data, respond) ->
- try
- script = data.script
- @scope ||=
- logger: Logger.loggerForFile('repl'),
- __filename: 'repl',
- __dirname: '.'
- @scope.job = @job
-
- if data.type is 'text/coffeescript'
- script = string.trim(CoffeeScript.compile "(-> #{script})()", bare: on)
- else
- script = "(function(){#{script}})()" if /[;\n]/.test script
-
- script = "return #{script}"
- result = func.callWithScope script, @scope, @scope
-
- @scope._ = result
-
- respond response:
- status: 'ok'
- eval: inspect(result, undefined, undefined, color: data.color)
-
- catch e
- logger.error 'eval: error: ', e
- respond response:
- status: 'error'
- error: e.toString()
-
-
module.exports = Controller
View
@@ -14,7 +14,10 @@ def port=(port)
end
def profile
- self['eval', {:script => '(require "io/Dir").profile.path', :type => 'text/coffeescript'}]
+ response = post '/eval', :script => '(require "io/Dir").profile.path',
+ :type => 'text/coffeescript'
+
+ JSON.parse(response.body)['result']
end
def post(path, data=nil)
View
@@ -70,7 +70,7 @@ def start_script_repl(command, type)
history << script
begin
- puts Api['eval', {:script => script, :type => type, :color => $stdin.tty?}]
+ puts post('/eval', :script => script, :type => type, :color => $stdin.tty?)['result']
rescue Api::Error => e
puts e
rescue => e

0 comments on commit 4cfd4c9

Please sign in to comment.