-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEvalController.j
38 lines (32 loc) · 1.71 KB
/
EvalController.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// (c) 2010-2011 by Anton Korenyushkin
@import "BaseConsoleController.j"
@import "HTTPRequest.j"
@implementation EvalController : BaseConsoleController
- (id)initWithApp:(App)anApp buffer:(Buffer)aBuffer // public
{
return [super initWithApp:anApp
buffer:aBuffer
infoBoxWidth:400
message:"Evaluate JavaScript expressions in the \"" + aBuffer.env.name + "\" environment."
comment:("Your app has a number of isolated environments. The \"release\" "+
"environment operates on the \"master\" branch of the app's repository; " +
"it's intended for serving your users. Other environments operate on " +
"the working tree; they're intended for testing and debugging. Click on " +
"an environment item in the navigator to open its evaluator. Alt-click " +
"on it to open its preview tab.")
inputButtonTitle:"Evaluate"];
}
- (void)handleInput:(CPString)input // protected
{
var request = [[HTTPRequest alloc] initWithMethod:"POST"
URL:[app URL] + "envs/" + buffer.env.name
target:self
action:@selector(didReceiveResponse:forQuestionNumber:)];
[request setContext:[outputView addQuestion:input]];
[request send:{action: "eval", expr: input}];
}
- (void)didReceiveResponse:(JSObject)data forQuestionNumber:(unsigned)questionNumber // private
{
[outputView setAnswer:data.result negative:!data.ok forQuestionNumber:questionNumber];
}
@end