2
0

AmberCli.js 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. smalltalk.addPackage('AmberCli');
  2. smalltalk.addClass('AmberCli', smalltalk.Object, [], 'AmberCli');
  3. smalltalk.AmberCli.comment="I am the Amber CLI (CommandLine Interface) tool which runs on Node.js.\x0a\x0aMy responsibility is to start different Amber programs like the FileServer or the Repl.\x0aWhich program to start is determined by the first commandline parameters passed to the AmberCli executable.\x0aUse `help` to get a list of all available options.\x0aAny further commandline parameters are passed to the specific program.\x0a\x0a## Commands\x0a\x0aNew commands can be added by creating a class side method in the `commands` protocol which takes one parameter.\x0aThis parameter is an array of all commandline options + values passed on to the program.\x0aAny `camelCaseCommand` is transformed into a commandline parameter of the form `camel-case-command` and vice versa."
  4. smalltalk.addMethod(
  5. smalltalk.method({
  6. selector: "commandLineSwitches",
  7. category: 'commandline',
  8. fn: function (){
  9. var self=this;
  10. var switches;
  11. return smalltalk.withContext(function($ctx1) {
  12. var $1;
  13. switches=_st(_st(_st(self)._class())._methodsInProtocol_("commands"))._collect_((function(each){
  14. return smalltalk.withContext(function($ctx2) {
  15. return _st(each)._selector();
  16. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  17. switches=_st(switches)._select_((function(each){
  18. return smalltalk.withContext(function($ctx2) {
  19. return _st(each)._match_("^[^:]*:$");
  20. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  21. switches=_st(switches)._collect_((function(each){
  22. return smalltalk.withContext(function($ctx2) {
  23. return _st(_st(_st(each)._allButLast())._replace_with_("([A-Z])","-$1"))._asLowercase();
  24. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  25. $1=switches;
  26. return $1;
  27. }, function($ctx1) {$ctx1.fill(self,"commandLineSwitches",{switches:switches},smalltalk.AmberCli.klass)})},
  28. args: [],
  29. source: "commandLineSwitches\x0a\x09\x22Collect all methodnames from the 'commands' protocol of the class\x0a\x09 and select the ones with only one parameter.\x0a\x09 Then remove the ':' at the end of the name.\x0a\x09 Additionally all uppercase letters are made lowercase and preceded by a '-'.\x0a\x09 Example: fallbackPage: becomes --fallback-page.\x0a\x09 Return the Array containing the commandline switches.\x22\x0a\x09| switches |\x0a\x09switches := ((self class methodsInProtocol: 'commands') collect: [ :each | each selector]).\x0a\x09switches := switches select: [ :each | each match: '^[^:]*:$'].\x0a\x09switches :=switches collect: [ :each |\x0a\x09\x09(each allButLast replace: '([A-Z])' with: '-$1') asLowercase].\x0a\x09^switches",
  30. messageSends: ["collect:", "selector", "methodsInProtocol:", "class", "select:", "match:", "asLowercase", "replace:with:", "allButLast"],
  31. referencedClasses: []
  32. }),
  33. smalltalk.AmberCli.klass);
  34. smalltalk.addMethod(
  35. smalltalk.method({
  36. selector: "handleArguments:",
  37. category: 'commandline',
  38. fn: function (args){
  39. var self=this;
  40. var selector;
  41. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  42. return smalltalk.withContext(function($ctx1) {
  43. selector=_st(self)._selectorForCommandLineSwitch_(_st(args)._first());
  44. _st(args)._remove_(_st(args)._first());
  45. _st(self)._perform_withArguments_(selector,_st($Array())._with_(args));
  46. return self}, function($ctx1) {$ctx1.fill(self,"handleArguments:",{args:args,selector:selector},smalltalk.AmberCli.klass)})},
  47. args: ["args"],
  48. source: "handleArguments: args\x0a\x09| selector |\x0a\x0a\x09selector := self selectorForCommandLineSwitch: (args first).\x0a\x09args remove: args first.\x0a\x09self perform: selector withArguments: (Array with: args)",
  49. messageSends: ["selectorForCommandLineSwitch:", "first", "remove:", "perform:withArguments:", "with:"],
  50. referencedClasses: ["Array"]
  51. }),
  52. smalltalk.AmberCli.klass);
  53. smalltalk.addMethod(
  54. smalltalk.method({
  55. selector: "help:",
  56. category: 'commands',
  57. fn: function (args){
  58. var self=this;
  59. return smalltalk.withContext(function($ctx1) {
  60. _st(console)._log_("Available Commands:");
  61. _st(_st(self)._commandLineSwitches())._do_((function(each){
  62. return smalltalk.withContext(function($ctx2) {
  63. return _st(console)._log_(each);
  64. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  65. return self}, function($ctx1) {$ctx1.fill(self,"help:",{args:args},smalltalk.AmberCli.klass)})},
  66. args: ["args"],
  67. source: "help: args\x0a\x09console log: 'Available Commands:'.\x0a\x09self commandLineSwitches do: [ :each | console log: each ]",
  68. messageSends: ["log:", "do:", "commandLineSwitches"],
  69. referencedClasses: []
  70. }),
  71. smalltalk.AmberCli.klass);
  72. smalltalk.addMethod(
  73. smalltalk.method({
  74. selector: "main",
  75. category: 'startup',
  76. fn: function (){
  77. var self=this;
  78. var args;
  79. return smalltalk.withContext(function($ctx1) {
  80. var $1,$2;
  81. args=_st(process)._argv();
  82. _st(args)._removeFrom_to_((1),(3));
  83. $1=_st(args)._isEmpty();
  84. if(smalltalk.assert($1)){
  85. _st(self)._help_(nil);
  86. } else {
  87. $2=_st(self)._handleArguments_(args);
  88. return $2;
  89. };
  90. return self}, function($ctx1) {$ctx1.fill(self,"main",{args:args},smalltalk.AmberCli.klass)})},
  91. args: [],
  92. source: "main\x0a\x09\x22Main entry point for Amber applications.\x0a\x09Parses commandline arguments and starts the according subprogram.\x22\x0a\x09| args |\x0a\x09args := process argv.\x0a\x09\x22Remove the first args which contain the path to the node executable and the script file.\x22\x0a\x09args removeFrom: 1 to: 3.\x0a\x09\x0a\x09(args isEmpty)\x0a\x09\x09ifTrue: [self help: nil]\x0a\x09\x09ifFalse: [^self handleArguments: args]",
  93. messageSends: ["argv", "removeFrom:to:", "ifTrue:ifFalse:", "help:", "handleArguments:", "isEmpty"],
  94. referencedClasses: []
  95. }),
  96. smalltalk.AmberCli.klass);
  97. smalltalk.addMethod(
  98. smalltalk.method({
  99. selector: "repl:",
  100. category: 'commands',
  101. fn: function (args){
  102. var self=this;
  103. function $Repl(){return smalltalk.Repl||(typeof Repl=="undefined"?nil:Repl)}
  104. return smalltalk.withContext(function($ctx1) {
  105. var $1;
  106. $1=_st(_st($Repl())._new())._createInterface();
  107. return $1;
  108. }, function($ctx1) {$ctx1.fill(self,"repl:",{args:args},smalltalk.AmberCli.klass)})},
  109. args: ["args"],
  110. source: "repl: args\x0a\x09^Repl new createInterface",
  111. messageSends: ["createInterface", "new"],
  112. referencedClasses: ["Repl"]
  113. }),
  114. smalltalk.AmberCli.klass);
  115. smalltalk.addMethod(
  116. smalltalk.method({
  117. selector: "selectorForCommandLineSwitch:",
  118. category: 'commandline',
  119. fn: function (aSwitch){
  120. var self=this;
  121. var command,selector;
  122. return smalltalk.withContext(function($ctx1) {
  123. var $1,$2;
  124. $1=_st(_st(self)._commandLineSwitches())._includes_(aSwitch);
  125. if(smalltalk.assert($1)){
  126. selector=_st(_st(aSwitch)._replace_with_("-[a-z]",(function(each){
  127. return smalltalk.withContext(function($ctx2) {
  128. return _st(_st(each)._second())._asUppercase();
  129. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}))).__comma(":");
  130. selector;
  131. } else {
  132. selector="help:";
  133. selector;
  134. };
  135. $2=selector;
  136. return $2;
  137. }, function($ctx1) {$ctx1.fill(self,"selectorForCommandLineSwitch:",{aSwitch:aSwitch,command:command,selector:selector},smalltalk.AmberCli.klass)})},
  138. args: ["aSwitch"],
  139. source: "selectorForCommandLineSwitch: aSwitch\x0a\x09\x22Add ':' at the end and replace all occurences of a lowercase letter preceded by a '-' with the Uppercase letter.\x0a\x09 Example: fallback-page becomes fallbackPage:.\x0a\x09 If no correct selector is found return 'help:'\x22\x0a\x09 | command selector |\x0a\x0a\x09 (self commandLineSwitches includes: aSwitch)\x0a\x09 ifTrue: [ selector := (aSwitch replace: '-[a-z]' with: [ :each | each second asUppercase ]), ':']\x0a\x09 ifFalse: [ selector := 'help:' ].\x0a\x09^selector",
  140. messageSends: ["ifTrue:ifFalse:", ",", "replace:with:", "asUppercase", "second", "includes:", "commandLineSwitches"],
  141. referencedClasses: []
  142. }),
  143. smalltalk.AmberCli.klass);
  144. smalltalk.addMethod(
  145. smalltalk.method({
  146. selector: "serve:",
  147. category: 'commands',
  148. fn: function (args){
  149. var self=this;
  150. function $FileServer(){return smalltalk.FileServer||(typeof FileServer=="undefined"?nil:FileServer)}
  151. return smalltalk.withContext(function($ctx1) {
  152. var $1;
  153. $1=_st(_st($FileServer())._createServerWithArguments_(args))._start();
  154. return $1;
  155. }, function($ctx1) {$ctx1.fill(self,"serve:",{args:args},smalltalk.AmberCli.klass)})},
  156. args: ["args"],
  157. source: "serve: args\x0a\x09^(FileServer createServerWithArguments: args) start",
  158. messageSends: ["start", "createServerWithArguments:"],
  159. referencedClasses: ["FileServer"]
  160. }),
  161. smalltalk.AmberCli.klass);
  162. smalltalk.addClass('FileServer', smalltalk.Object, ['path', 'http', 'fs', 'url', 'host', 'port', 'basePath', 'util', 'username', 'password', 'fallbackPage'], 'AmberCli');
  163. smalltalk.FileServer.comment="I am the Amber Smalltalk FileServer.\x0aMy runtime requirement is a functional Node.js executable.\x0a\x0aTo start a FileServer instance on port `4000` use the following code:\x0a\x0a FileServer new start\x0a\x0aA parameterized instance can be created with the following code:\x0a\x0a FileServer createServerWithArguments: options\x0a\x0aHere, `options` is an array of commandline style strings each followed by a value e.g. `#('--port', '6000', '--host', '0.0.0.0')`.\x0aA list of all available parameters can be printed to the commandline by passing `--help` as parameter.\x0aSee the `Options` section for further details on how options are mapped to instance methods.\x0a\x0aAfter startup FileServer checks if the directory layout required by Amber is present and logs a warning on absence.\x0a\x0a\x0a## Options\x0a\x0aEach option is of the form `--some-option-string` which is transformed into a selector of the format `someOptionString:`.\x0aThe trailing `--` gets removed, each `-[a-z]` gets transformed into the according uppercase letter, and a `:` is appended to create a selector which takes a single argument.\x0aAfterwards, the selector gets executed on the `FileServer` instance with the value following in the options array as parameter.\x0a\x0a## Adding new commandline parameters\x0a\x0aAdding new commandline parameters to `FileServer` is as easy as adding a new single parameter method to the `accessing` protocol."
  164. smalltalk.addMethod(
  165. smalltalk.method({
  166. selector: "base64Decode:",
  167. category: 'private',
  168. fn: function (aString){
  169. var self=this;
  170. return smalltalk.withContext(function($ctx1) {
  171. return (new Buffer(aString, 'base64').toString());
  172. return self}, function($ctx1) {$ctx1.fill(self,"base64Decode:",{aString:aString},smalltalk.FileServer)})},
  173. args: ["aString"],
  174. source: "base64Decode: aString\x0a\x09<return (new Buffer(aString, 'base64').toString())>",
  175. messageSends: [],
  176. referencedClasses: []
  177. }),
  178. smalltalk.FileServer);
  179. smalltalk.addMethod(
  180. smalltalk.method({
  181. selector: "basePath",
  182. category: 'accessing',
  183. fn: function (){
  184. var self=this;
  185. return smalltalk.withContext(function($ctx1) {
  186. var $2,$1;
  187. $2=self["@basePath"];
  188. if(($receiver = $2) == nil || $receiver == undefined){
  189. $1="./";
  190. } else {
  191. $1=$2;
  192. };
  193. return $1;
  194. }, function($ctx1) {$ctx1.fill(self,"basePath",{},smalltalk.FileServer)})},
  195. args: [],
  196. source: "basePath\x0a\x09^basePath ifNil: ['./']",
  197. messageSends: ["ifNil:"],
  198. referencedClasses: []
  199. }),
  200. smalltalk.FileServer);
  201. smalltalk.addMethod(
  202. smalltalk.method({
  203. selector: "basePath:",
  204. category: 'accessing',
  205. fn: function (aString){
  206. var self=this;
  207. return smalltalk.withContext(function($ctx1) {
  208. self["@basePath"]=aString;
  209. return self}, function($ctx1) {$ctx1.fill(self,"basePath:",{aString:aString},smalltalk.FileServer)})},
  210. args: ["aString"],
  211. source: "basePath: aString\x0a\x09basePath := aString",
  212. messageSends: [],
  213. referencedClasses: []
  214. }),
  215. smalltalk.FileServer);
  216. smalltalk.addMethod(
  217. smalltalk.method({
  218. selector: "checkDirectoryLayout",
  219. category: 'initialization',
  220. fn: function (){
  221. var self=this;
  222. return smalltalk.withContext(function($ctx1) {
  223. var $1,$2,$3;
  224. $1=_st(self["@fs"])._existsSync_(_st(_st(self)._basePath()).__comma("index.html"));
  225. if(! smalltalk.assert($1)){
  226. _st(console)._warn_("Warning: project directory does not contain index.html");
  227. };
  228. $2=_st(self["@fs"])._existsSync_(_st(_st(self)._basePath()).__comma("st"));
  229. if(! smalltalk.assert($2)){
  230. _st(console)._warn_("Warning: project directory is missing an \x22st\x22 directory");
  231. };
  232. $3=_st(self["@fs"])._existsSync_(_st(_st(self)._basePath()).__comma("js"));
  233. if(! smalltalk.assert($3)){
  234. _st(console)._warn_("Warning: project directory is missing a \x22js\x22 directory");
  235. };
  236. return self}, function($ctx1) {$ctx1.fill(self,"checkDirectoryLayout",{},smalltalk.FileServer)})},
  237. args: [],
  238. source: "checkDirectoryLayout\x0a\x09(fs existsSync: self basePath, 'index.html') ifFalse: [\x0a\x09\x09console warn: 'Warning: project directory does not contain index.html'].\x0a\x09(fs existsSync: self basePath, 'st') ifFalse: [\x0a\x09\x09console warn: 'Warning: project directory is missing an \x22st\x22 directory'].\x0a\x09(fs existsSync: self basePath, 'js') ifFalse: [\x0a\x09\x09console warn: 'Warning: project directory is missing a \x22js\x22 directory'].",
  239. messageSends: ["ifFalse:", "warn:", "existsSync:", ",", "basePath"],
  240. referencedClasses: []
  241. }),
  242. smalltalk.FileServer);
  243. smalltalk.addMethod(
  244. smalltalk.method({
  245. selector: "fallbackPage",
  246. category: 'accessing',
  247. fn: function (){
  248. var self=this;
  249. return smalltalk.withContext(function($ctx1) {
  250. var $1;
  251. $1=self["@fallbackPage"];
  252. return $1;
  253. }, function($ctx1) {$ctx1.fill(self,"fallbackPage",{},smalltalk.FileServer)})},
  254. args: [],
  255. source: "fallbackPage\x0a\x09^fallbackPage",
  256. messageSends: [],
  257. referencedClasses: []
  258. }),
  259. smalltalk.FileServer);
  260. smalltalk.addMethod(
  261. smalltalk.method({
  262. selector: "fallbackPage:",
  263. category: 'accessing',
  264. fn: function (aString){
  265. var self=this;
  266. return smalltalk.withContext(function($ctx1) {
  267. self["@fallbackPage"]=aString;
  268. return self}, function($ctx1) {$ctx1.fill(self,"fallbackPage:",{aString:aString},smalltalk.FileServer)})},
  269. args: ["aString"],
  270. source: "fallbackPage: aString\x0a\x09fallbackPage := aString",
  271. messageSends: [],
  272. referencedClasses: []
  273. }),
  274. smalltalk.FileServer);
  275. smalltalk.addMethod(
  276. smalltalk.method({
  277. selector: "handleGETRequest:respondTo:",
  278. category: 'request handling',
  279. fn: function (aRequest,aResponse){
  280. var self=this;
  281. var uri,filename;
  282. return smalltalk.withContext(function($ctx1) {
  283. var $1;
  284. uri=_st(_st(self["@url"])._parse_(_st(aRequest)._url()))._pathname();
  285. filename=_st(self["@path"])._join_with_(_st(self)._basePath(),uri);
  286. _st(self["@fs"])._exists_do_(filename,(function(aBoolean){
  287. return smalltalk.withContext(function($ctx2) {
  288. $1=aBoolean;
  289. if(smalltalk.assert($1)){
  290. return _st(self)._respondFileNamed_to_(filename,aResponse);
  291. } else {
  292. return _st(self)._respondNotFoundTo_(aResponse);
  293. };
  294. }, function($ctx2) {$ctx2.fillBlock({aBoolean:aBoolean},$ctx1)})}));
  295. return self}, function($ctx1) {$ctx1.fill(self,"handleGETRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse,uri:uri,filename:filename},smalltalk.FileServer)})},
  296. args: ["aRequest", "aResponse"],
  297. source: "handleGETRequest: aRequest respondTo: aResponse\x0a\x09| uri filename |\x0a\x09uri := (url parse: aRequest url) pathname.\x0a\x09filename := path join: self basePath with: uri.\x0a\x09fs exists: filename do: [:aBoolean |\x0a\x09\x09aBoolean\x0a\x09\x09\x09ifFalse: [self respondNotFoundTo: aResponse]\x0a\x09\x09\x09ifTrue: [self respondFileNamed: filename to: aResponse]]",
  298. messageSends: ["pathname", "parse:", "url", "join:with:", "basePath", "exists:do:", "ifFalse:ifTrue:", "respondNotFoundTo:", "respondFileNamed:to:"],
  299. referencedClasses: []
  300. }),
  301. smalltalk.FileServer);
  302. smalltalk.addMethod(
  303. smalltalk.method({
  304. selector: "handleOPTIONSRequest:respondTo:",
  305. category: 'request handling',
  306. fn: function (aRequest,aResponse){
  307. var self=this;
  308. return smalltalk.withContext(function($ctx1) {
  309. _st(aResponse)._writeHead_options_((200),smalltalk.HashedCollection._fromPairs_([_st("Access-Control-Allow-Origin").__minus_gt("*"),_st("Access-Control-Allow-Methods").__minus_gt("GET, PUT, POST, DELETE, OPTIONS"),_st("Access-Control-Allow-Headers").__minus_gt("Content-Type, Accept"),_st("Content-Length").__minus_gt((0)),_st("Access-Control-Max-Age").__minus_gt((10))]));
  310. _st(aResponse)._end();
  311. return self}, function($ctx1) {$ctx1.fill(self,"handleOPTIONSRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse},smalltalk.FileServer)})},
  312. args: ["aRequest", "aResponse"],
  313. source: "handleOPTIONSRequest: aRequest respondTo: aResponse\x0a\x09aResponse writeHead: 200 options: #{'Access-Control-Allow-Origin' -> '*'.\x0a\x09\x09\x09\x09\x09'Access-Control-Allow-Methods' -> 'GET, PUT, POST, DELETE, OPTIONS'.\x0a\x09\x09\x09\x09\x09'Access-Control-Allow-Headers' -> 'Content-Type, Accept'.\x0a\x09\x09\x09\x09\x09'Content-Length' -> 0.\x0a\x09\x09\x09\x09\x09'Access-Control-Max-Age' -> 10}.\x0a\x09aResponse end",
  314. messageSends: ["writeHead:options:", "->", "end"],
  315. referencedClasses: []
  316. }),
  317. smalltalk.FileServer);
  318. smalltalk.addMethod(
  319. smalltalk.method({
  320. selector: "handlePUTRequest:respondTo:",
  321. category: 'request handling',
  322. fn: function (aRequest,aResponse){
  323. var self=this;
  324. var file,stream;
  325. return smalltalk.withContext(function($ctx1) {
  326. var $1,$2;
  327. $1=_st(self)._isAuthenticated_(aRequest);
  328. if(! smalltalk.assert($1)){
  329. _st(self)._respondAuthenticationRequiredTo_(aResponse);
  330. return nil;
  331. };
  332. file=_st(".").__comma(_st(aRequest)._url());
  333. stream=_st(self["@fs"])._createWriteStream_(file);
  334. _st(stream)._on_do_("error",(function(error){
  335. return smalltalk.withContext(function($ctx2) {
  336. _st(console)._warn_(_st("Error creating WriteStream for file ").__comma(file));
  337. _st(console)._warn_(" Did you forget to create the necessary js/ or st/ directory in your project?");
  338. _st(console)._warn_(_st(" The exact error is: ").__comma(error));
  339. return _st(self)._respondNotCreatedTo_(aResponse);
  340. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1)})}));
  341. _st(stream)._on_do_("close",(function(){
  342. return smalltalk.withContext(function($ctx2) {
  343. return _st(self)._respondCreatedTo_(aResponse);
  344. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  345. _st(aRequest)._setEncoding_("utf8");
  346. _st(aRequest)._on_do_("data",(function(data){
  347. return smalltalk.withContext(function($ctx2) {
  348. return _st(stream)._write_(data);
  349. }, function($ctx2) {$ctx2.fillBlock({data:data},$ctx1)})}));
  350. _st(aRequest)._on_do_("end",(function(){
  351. return smalltalk.withContext(function($ctx2) {
  352. $2=_st(stream)._writable();
  353. if(smalltalk.assert($2)){
  354. return _st(stream)._end();
  355. };
  356. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  357. return self}, function($ctx1) {$ctx1.fill(self,"handlePUTRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse,file:file,stream:stream},smalltalk.FileServer)})},
  358. args: ["aRequest", "aResponse"],
  359. source: "handlePUTRequest: aRequest respondTo: aResponse\x0a\x09| file stream |\x0a\x09(self isAuthenticated: aRequest)\x0a\x09\x09ifFalse: [self respondAuthenticationRequiredTo: aResponse. ^nil].\x0a\x0a\x09file := '.', aRequest url.\x0a\x09stream := fs createWriteStream: file.\x0a\x0a\x09stream on: 'error' do: [:error |\x0a\x09\x09console warn: 'Error creating WriteStream for file ', file.\x0a\x09\x09console warn: ' Did you forget to create the necessary js/ or st/ directory in your project?'.\x0a\x09\x09console warn: ' The exact error is: ', error.\x0a\x09\x09self respondNotCreatedTo: aResponse].\x0a\x0a\x09stream on: 'close' do: [\x0a\x09\x09self respondCreatedTo: aResponse].\x0a\x0a\x09aRequest setEncoding: 'utf8'.\x0a\x09aRequest on: 'data' do: [:data |\x0a\x09\x09stream write: data].\x0a\x0a\x09aRequest on: 'end' do: [\x0a\x09\x09stream writable ifTrue: [stream end]]",
  360. messageSends: ["ifFalse:", "respondAuthenticationRequiredTo:", "isAuthenticated:", ",", "url", "createWriteStream:", "on:do:", "warn:", "respondNotCreatedTo:", "respondCreatedTo:", "setEncoding:", "write:", "ifTrue:", "end", "writable"],
  361. referencedClasses: []
  362. }),
  363. smalltalk.FileServer);
  364. smalltalk.addMethod(
  365. smalltalk.method({
  366. selector: "handleRequest:respondTo:",
  367. category: 'request handling',
  368. fn: function (aRequest,aResponse){
  369. var self=this;
  370. return smalltalk.withContext(function($ctx1) {
  371. var $1,$2,$3;
  372. $1=_st(_st(aRequest)._method()).__eq("PUT");
  373. if(smalltalk.assert($1)){
  374. _st(self)._handlePUTRequest_respondTo_(aRequest,aResponse);
  375. };
  376. $2=_st(_st(aRequest)._method()).__eq("GET");
  377. if(smalltalk.assert($2)){
  378. _st(self)._handleGETRequest_respondTo_(aRequest,aResponse);
  379. };
  380. $3=_st(_st(aRequest)._method()).__eq("OPTIONS");
  381. if(smalltalk.assert($3)){
  382. _st(self)._handleOPTIONSRequest_respondTo_(aRequest,aResponse);
  383. };
  384. return self}, function($ctx1) {$ctx1.fill(self,"handleRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse},smalltalk.FileServer)})},
  385. args: ["aRequest", "aResponse"],
  386. source: "handleRequest: aRequest respondTo: aResponse\x0a\x09aRequest method = 'PUT'\x0a\x09\x09ifTrue: [self handlePUTRequest: aRequest respondTo: aResponse].\x0a\x09aRequest method = 'GET'\x0a\x09\x09ifTrue:[self handleGETRequest: aRequest respondTo: aResponse].\x0a\x09aRequest method = 'OPTIONS'\x0a\x09\x09ifTrue:[self handleOPTIONSRequest: aRequest respondTo: aResponse]",
  387. messageSends: ["ifTrue:", "handlePUTRequest:respondTo:", "=", "method", "handleGETRequest:respondTo:", "handleOPTIONSRequest:respondTo:"],
  388. referencedClasses: []
  389. }),
  390. smalltalk.FileServer);
  391. smalltalk.addMethod(
  392. smalltalk.method({
  393. selector: "host",
  394. category: 'accessing',
  395. fn: function (){
  396. var self=this;
  397. return smalltalk.withContext(function($ctx1) {
  398. var $1;
  399. $1=self["@host"];
  400. return $1;
  401. }, function($ctx1) {$ctx1.fill(self,"host",{},smalltalk.FileServer)})},
  402. args: [],
  403. source: "host\x0a\x09^host",
  404. messageSends: [],
  405. referencedClasses: []
  406. }),
  407. smalltalk.FileServer);
  408. smalltalk.addMethod(
  409. smalltalk.method({
  410. selector: "host:",
  411. category: 'accessing',
  412. fn: function (hostname){
  413. var self=this;
  414. return smalltalk.withContext(function($ctx1) {
  415. self["@host"]=hostname;
  416. return self}, function($ctx1) {$ctx1.fill(self,"host:",{hostname:hostname},smalltalk.FileServer)})},
  417. args: ["hostname"],
  418. source: "host: hostname\x0a\x09host := hostname",
  419. messageSends: [],
  420. referencedClasses: []
  421. }),
  422. smalltalk.FileServer);
  423. smalltalk.addMethod(
  424. smalltalk.method({
  425. selector: "initialize",
  426. category: 'initialization',
  427. fn: function (){
  428. var self=this;
  429. return smalltalk.withContext(function($ctx1) {
  430. smalltalk.Object.fn.prototype._initialize.apply(_st(self), []);
  431. self["@path"]=_st(self)._require_("path");
  432. self["@http"]=_st(self)._require_("http");
  433. self["@fs"]=_st(self)._require_("fs");
  434. self["@util"]=_st(self)._require_("util");
  435. self["@url"]=_st(self)._require_("url");
  436. self["@host"]=_st(_st(self)._class())._defaultHost();
  437. self["@port"]=_st(_st(self)._class())._defaultPort();
  438. self["@username"]=nil;
  439. self["@password"]=nil;
  440. self["@fallbackPage"]=nil;
  441. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.FileServer)})},
  442. args: [],
  443. source: "initialize\x0a\x09super initialize.\x0a\x09path := self require: 'path'.\x0a\x09http := self require: 'http'.\x0a\x09fs := self require: 'fs'.\x0a\x09util := self require: 'util'.\x0a\x09url := self require: 'url'.\x0a\x09host := self class defaultHost.\x0a\x09port := self class defaultPort.\x0a\x09username := nil.\x0a\x09password := nil.\x0a\x09fallbackPage := nil.",
  444. messageSends: ["initialize", "require:", "defaultHost", "class", "defaultPort"],
  445. referencedClasses: []
  446. }),
  447. smalltalk.FileServer);
  448. smalltalk.addMethod(
  449. smalltalk.method({
  450. selector: "isAuthenticated:",
  451. category: 'private',
  452. fn: function (aRequest){
  453. var self=this;
  454. var header,token,auth,parts;
  455. return smalltalk.withContext(function($ctx1) {
  456. var $1,$2,$3,$4,$5;
  457. $1=_st(_st(self["@username"])._isNil())._and_((function(){
  458. return smalltalk.withContext(function($ctx2) {
  459. return _st(self["@password"])._isNil();
  460. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  461. if(smalltalk.assert($1)){
  462. return true;
  463. };
  464. $2=_st(_st(aRequest)._headers())._at_("authorization");
  465. if(($receiver = $2) == nil || $receiver == undefined){
  466. header="";
  467. } else {
  468. header=$2;
  469. };
  470. $3=_st(header)._isEmpty();
  471. if(smalltalk.assert($3)){
  472. return false;
  473. } else {
  474. $4=_st(header)._tokenize_(" ");
  475. if(($receiver = $4) == nil || $receiver == undefined){
  476. token="";
  477. } else {
  478. token=$4;
  479. };
  480. token;
  481. auth=_st(self)._base64Decode_(_st(token)._at_((2)));
  482. auth;
  483. parts=_st(auth)._tokenize_(":");
  484. parts;
  485. $5=_st(_st(self["@username"]).__eq(_st(parts)._at_((1))))._and_((function(){
  486. return smalltalk.withContext(function($ctx2) {
  487. return _st(self["@password"]).__eq(_st(parts)._at_((2)));
  488. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  489. if(smalltalk.assert($5)){
  490. return true;
  491. } else {
  492. return false;
  493. };
  494. };
  495. return self}, function($ctx1) {$ctx1.fill(self,"isAuthenticated:",{aRequest:aRequest,header:header,token:token,auth:auth,parts:parts},smalltalk.FileServer)})},
  496. args: ["aRequest"],
  497. source: "isAuthenticated: aRequest\x0a\x09\x22Basic HTTP Auth: http://stackoverflow.com/a/5957629/293175\x0a\x09 and https://gist.github.com/1686663\x22\x0a\x09| header token auth parts|\x0a\x0a\x09(username isNil and: [password isNil]) ifTrue: [^true].\x0a\x0a\x09\x22get authentication header\x22\x0a\x09header := (aRequest headers at: 'authorization') ifNil:[''].\x0a\x09(header isEmpty)\x0a\x09ifTrue: [^false]\x0a\x09ifFalse: [\x0a\x09\x09\x22get authentication token\x22\x0a\x09\x09token := (header tokenize: ' ') ifNil:[''].\x0a\x09\x09\x22convert back from base64\x22\x0a\x09\x09auth := self base64Decode: (token at: 2).\x0a\x09\x09\x22split token at colon\x22\x0a\x09\x09parts := auth tokenize: ':'.\x0a\x0a\x09\x09((username = (parts at: 1)) and: [password = (parts at: 2)])\x0a\x09\x09\x09ifTrue: [^true]\x0a\x09\x09\x09ifFalse: [^false]\x0a\x09].",
  498. messageSends: ["ifTrue:", "and:", "isNil", "ifNil:", "at:", "headers", "ifTrue:ifFalse:", "tokenize:", "base64Decode:", "=", "isEmpty"],
  499. referencedClasses: []
  500. }),
  501. smalltalk.FileServer);
  502. smalltalk.addMethod(
  503. smalltalk.method({
  504. selector: "password:",
  505. category: 'accessing',
  506. fn: function (aPassword){
  507. var self=this;
  508. return smalltalk.withContext(function($ctx1) {
  509. self["@password"]=aPassword;
  510. return self}, function($ctx1) {$ctx1.fill(self,"password:",{aPassword:aPassword},smalltalk.FileServer)})},
  511. args: ["aPassword"],
  512. source: "password: aPassword\x0a\x09password := aPassword.",
  513. messageSends: [],
  514. referencedClasses: []
  515. }),
  516. smalltalk.FileServer);
  517. smalltalk.addMethod(
  518. smalltalk.method({
  519. selector: "port",
  520. category: 'accessing',
  521. fn: function (){
  522. var self=this;
  523. return smalltalk.withContext(function($ctx1) {
  524. var $1;
  525. $1=self["@port"];
  526. return $1;
  527. }, function($ctx1) {$ctx1.fill(self,"port",{},smalltalk.FileServer)})},
  528. args: [],
  529. source: "port\x0a\x09^port",
  530. messageSends: [],
  531. referencedClasses: []
  532. }),
  533. smalltalk.FileServer);
  534. smalltalk.addMethod(
  535. smalltalk.method({
  536. selector: "port:",
  537. category: 'accessing',
  538. fn: function (aNumber){
  539. var self=this;
  540. return smalltalk.withContext(function($ctx1) {
  541. self["@port"]=aNumber;
  542. return self}, function($ctx1) {$ctx1.fill(self,"port:",{aNumber:aNumber},smalltalk.FileServer)})},
  543. args: ["aNumber"],
  544. source: "port: aNumber\x0a\x09port := aNumber",
  545. messageSends: [],
  546. referencedClasses: []
  547. }),
  548. smalltalk.FileServer);
  549. smalltalk.addMethod(
  550. smalltalk.method({
  551. selector: "require:",
  552. category: 'private',
  553. fn: function (aModuleString){
  554. var self=this;
  555. return smalltalk.withContext(function($ctx1) {
  556. var $1;
  557. $1=_st(require)._value_(aModuleString);
  558. return $1;
  559. }, function($ctx1) {$ctx1.fill(self,"require:",{aModuleString:aModuleString},smalltalk.FileServer)})},
  560. args: ["aModuleString"],
  561. source: "require: aModuleString\x0a\x09\x22call to the require function\x22\x0a\x09^require value: aModuleString",
  562. messageSends: ["value:"],
  563. referencedClasses: []
  564. }),
  565. smalltalk.FileServer);
  566. smalltalk.addMethod(
  567. smalltalk.method({
  568. selector: "respondAuthenticationRequiredTo:",
  569. category: 'request handling',
  570. fn: function (aResponse){
  571. var self=this;
  572. return smalltalk.withContext(function($ctx1) {
  573. var $1,$2;
  574. $1=aResponse;
  575. _st($1)._writeHead_options_((401),smalltalk.HashedCollection._fromPairs_([_st("WWW-Authenticate").__minus_gt("Basic realm=\x22Secured Developer Area\x22")]));
  576. _st($1)._write_("<html><body>Authentication needed</body></html>");
  577. $2=_st($1)._end();
  578. return self}, function($ctx1) {$ctx1.fill(self,"respondAuthenticationRequiredTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  579. args: ["aResponse"],
  580. source: "respondAuthenticationRequiredTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 401 options: #{'WWW-Authenticate' -> 'Basic realm=\x22Secured Developer Area\x22'};\x0a\x09\x09write: '<html><body>Authentication needed</body></html>';\x0a\x09\x09end.",
  581. messageSends: ["writeHead:options:", "->", "write:", "end"],
  582. referencedClasses: []
  583. }),
  584. smalltalk.FileServer);
  585. smalltalk.addMethod(
  586. smalltalk.method({
  587. selector: "respondCreatedTo:",
  588. category: 'request handling',
  589. fn: function (aResponse){
  590. var self=this;
  591. return smalltalk.withContext(function($ctx1) {
  592. var $1,$2;
  593. $1=aResponse;
  594. _st($1)._writeHead_options_((201),smalltalk.HashedCollection._fromPairs_([_st("Content-Type").__minus_gt("text/plain"),_st("Access-Control-Allow-Origin").__minus_gt("*")]));
  595. $2=_st($1)._end();
  596. return self}, function($ctx1) {$ctx1.fill(self,"respondCreatedTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  597. args: ["aResponse"],
  598. source: "respondCreatedTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 201 options: #{'Content-Type' -> 'text/plain'. 'Access-Control-Allow-Origin' -> '*'};\x0a\x09\x09end.",
  599. messageSends: ["writeHead:options:", "->", "end"],
  600. referencedClasses: []
  601. }),
  602. smalltalk.FileServer);
  603. smalltalk.addMethod(
  604. smalltalk.method({
  605. selector: "respondFileNamed:to:",
  606. category: 'request handling',
  607. fn: function (aFilename,aResponse){
  608. var self=this;
  609. var type,filename;
  610. return smalltalk.withContext(function($ctx1) {
  611. var $1,$2,$3,$4,$5;
  612. filename=aFilename;
  613. $1=_st(_st(self["@fs"])._statSync_(aFilename))._isDirectory();
  614. if(smalltalk.assert($1)){
  615. filename=_st(filename).__comma("index.html");
  616. filename;
  617. };
  618. _st(self["@fs"])._readFile_do_(filename,(function(ex,file){
  619. return smalltalk.withContext(function($ctx2) {
  620. $2=_st(ex)._notNil();
  621. if(smalltalk.assert($2)){
  622. _st(console)._log_(_st(filename).__comma(" does not exist"));
  623. return _st(self)._respondInternalErrorTo_(aResponse);
  624. } else {
  625. type=_st(_st(self)._class())._mimeTypeFor_(filename);
  626. type;
  627. $3=_st(type).__eq("application/javascript");
  628. if(smalltalk.assert($3)){
  629. type=_st(type).__comma(";charset=utf-8");
  630. type;
  631. };
  632. $4=aResponse;
  633. _st($4)._writeHead_options_((200),smalltalk.HashedCollection._fromPairs_([_st("Content-Type").__minus_gt(type)]));
  634. _st($4)._write_encoding_(file,"binary");
  635. $5=_st($4)._end();
  636. return $5;
  637. };
  638. }, function($ctx2) {$ctx2.fillBlock({ex:ex,file:file},$ctx1)})}));
  639. return self}, function($ctx1) {$ctx1.fill(self,"respondFileNamed:to:",{aFilename:aFilename,aResponse:aResponse,type:type,filename:filename},smalltalk.FileServer)})},
  640. args: ["aFilename", "aResponse"],
  641. source: "respondFileNamed: aFilename to: aResponse\x0a\x09| type filename |\x0a\x0a\x09filename := aFilename.\x0a\x09(fs statSync: aFilename) isDirectory ifTrue: [\x0a\x09\x09filename := filename, 'index.html'].\x0a\x0a\x09fs readFile: filename do: [:ex :file |\x0a\x09\x09ex notNil \x0a\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09console log: filename, ' does not exist'.\x0a\x09\x09\x09\x09self respondInternalErrorTo: aResponse]\x0a\x09\x09\x09ifFalse: [\x0a\x09\x09\x09\x09type := self class mimeTypeFor: filename.\x0a\x09\x09\x09\x09type = 'application/javascript'\x0a\x09\x09\x09\x09\x09ifTrue: [ type:=type,';charset=utf-8' ].\x0a\x09\x09\x09\x09aResponse \x0a\x09\x09\x09\x09\x09writeHead: 200 options: #{'Content-Type' -> type};\x0a\x09\x09\x09\x09\x09write: file encoding: 'binary';\x0a\x09\x09\x09\x09\x09end]]",
  642. messageSends: ["ifTrue:", ",", "isDirectory", "statSync:", "readFile:do:", "ifTrue:ifFalse:", "log:", "respondInternalErrorTo:", "mimeTypeFor:", "class", "=", "writeHead:options:", "->", "write:encoding:", "end", "notNil"],
  643. referencedClasses: []
  644. }),
  645. smalltalk.FileServer);
  646. smalltalk.addMethod(
  647. smalltalk.method({
  648. selector: "respondInternalErrorTo:",
  649. category: 'request handling',
  650. fn: function (aResponse){
  651. var self=this;
  652. return smalltalk.withContext(function($ctx1) {
  653. var $1,$2;
  654. $1=aResponse;
  655. _st($1)._writeHead_options_((500),smalltalk.HashedCollection._fromPairs_([_st("Content-Type").__minus_gt("text/plain")]));
  656. _st($1)._write_("500 Internal server error");
  657. $2=_st($1)._end();
  658. return self}, function($ctx1) {$ctx1.fill(self,"respondInternalErrorTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  659. args: ["aResponse"],
  660. source: "respondInternalErrorTo: aResponse\x0a\x09aResponse \x0a\x09\x09writeHead: 500 options: #{'Content-Type' -> 'text/plain'};\x0a\x09\x09write: '500 Internal server error';\x0a\x09\x09end",
  661. messageSends: ["writeHead:options:", "->", "write:", "end"],
  662. referencedClasses: []
  663. }),
  664. smalltalk.FileServer);
  665. smalltalk.addMethod(
  666. smalltalk.method({
  667. selector: "respondNotCreatedTo:",
  668. category: 'request handling',
  669. fn: function (aResponse){
  670. var self=this;
  671. return smalltalk.withContext(function($ctx1) {
  672. var $1,$2;
  673. $1=aResponse;
  674. _st($1)._writeHead_options_((400),smalltalk.HashedCollection._fromPairs_([_st("Content-Type").__minus_gt("text/plain")]));
  675. _st($1)._write_("File could not be created. Did you forget to create the st/js directories on the server?");
  676. $2=_st($1)._end();
  677. return self}, function($ctx1) {$ctx1.fill(self,"respondNotCreatedTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  678. args: ["aResponse"],
  679. source: "respondNotCreatedTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 400 options: #{'Content-Type' -> 'text/plain'};\x0a\x09\x09write: 'File could not be created. Did you forget to create the st/js directories on the server?';\x0a\x09\x09end.",
  680. messageSends: ["writeHead:options:", "->", "write:", "end"],
  681. referencedClasses: []
  682. }),
  683. smalltalk.FileServer);
  684. smalltalk.addMethod(
  685. smalltalk.method({
  686. selector: "respondNotFoundTo:",
  687. category: 'request handling',
  688. fn: function (aResponse){
  689. var self=this;
  690. return smalltalk.withContext(function($ctx1) {
  691. var $1,$2,$3,$4;
  692. $1=_st(_st(self)._fallbackPage())._isNil();
  693. if(! smalltalk.assert($1)){
  694. $2=_st(self)._respondFileNamed_to_(_st(self)._fallbackPage(),aResponse);
  695. return $2;
  696. };
  697. $3=aResponse;
  698. _st($3)._writeHead_options_((404),smalltalk.HashedCollection._fromPairs_([_st("Content-Type").__minus_gt("text/plain")]));
  699. _st($3)._write_("404 Not found");
  700. $4=_st($3)._end();
  701. return self}, function($ctx1) {$ctx1.fill(self,"respondNotFoundTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  702. args: ["aResponse"],
  703. source: "respondNotFoundTo: aResponse\x0a\x09self fallbackPage isNil ifFalse: [^self respondFileNamed: self fallbackPage to: aResponse].\x0a\x09aResponse \x0a\x09\x09writeHead: 404 options: #{'Content-Type' -> 'text/plain'};\x0a\x09\x09write: '404 Not found';\x0a\x09\x09end",
  704. messageSends: ["ifFalse:", "respondFileNamed:to:", "fallbackPage", "isNil", "writeHead:options:", "->", "write:", "end"],
  705. referencedClasses: []
  706. }),
  707. smalltalk.FileServer);
  708. smalltalk.addMethod(
  709. smalltalk.method({
  710. selector: "respondOKTo:",
  711. category: 'request handling',
  712. fn: function (aResponse){
  713. var self=this;
  714. return smalltalk.withContext(function($ctx1) {
  715. var $1,$2;
  716. $1=aResponse;
  717. _st($1)._writeHead_options_((200),smalltalk.HashedCollection._fromPairs_([_st("Content-Type").__minus_gt("text/plain"),_st("Access-Control-Allow-Origin").__minus_gt("*")]));
  718. $2=_st($1)._end();
  719. return self}, function($ctx1) {$ctx1.fill(self,"respondOKTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  720. args: ["aResponse"],
  721. source: "respondOKTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 200 options: #{'Content-Type' -> 'text/plain'. 'Access-Control-Allow-Origin' -> '*'};\x0a\x09\x09end.",
  722. messageSends: ["writeHead:options:", "->", "end"],
  723. referencedClasses: []
  724. }),
  725. smalltalk.FileServer);
  726. smalltalk.addMethod(
  727. smalltalk.method({
  728. selector: "start",
  729. category: 'starting',
  730. fn: function (){
  731. var self=this;
  732. return smalltalk.withContext(function($ctx1) {
  733. var $1,$2;
  734. _st(self)._checkDirectoryLayout();
  735. $1=_st(self["@http"])._createServer_((function(request,response){
  736. return smalltalk.withContext(function($ctx2) {
  737. return _st(self)._handleRequest_respondTo_(request,response);
  738. }, function($ctx2) {$ctx2.fillBlock({request:request,response:response},$ctx1)})}));
  739. _st($1)._on_do_("error",(function(error){
  740. return smalltalk.withContext(function($ctx2) {
  741. return _st(console)._log_(_st("Error starting server: ").__comma(error));
  742. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1)})}));
  743. _st($1)._on_do_("listening",(function(){
  744. return smalltalk.withContext(function($ctx2) {
  745. return _st(console)._log_(_st(_st(_st("Starting file server on ").__comma(_st(self)._host())).__comma(":")).__comma(_st(_st(self)._port())._asString()));
  746. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  747. $2=_st($1)._listen_host_(_st(self)._port(),_st(self)._host());
  748. return self}, function($ctx1) {$ctx1.fill(self,"start",{},smalltalk.FileServer)})},
  749. args: [],
  750. source: "start\x0a\x09\x22Checks if required directory layout is present (issue warning if not).\x0a\x09 Afterwards start the server.\x22\x0a\x09self checkDirectoryLayout.\x0a\x09(http createServer: [:request :response |\x0a\x09 self handleRequest: request respondTo: response])\x0a\x09 on: 'error' do: [:error | console log: 'Error starting server: ', error];\x0a\x09 on: 'listening' do: [console log: 'Starting file server on ', self host, ':', self port asString];\x0a\x09 listen: self port host: self host.",
  751. messageSends: ["checkDirectoryLayout", "on:do:", "log:", ",", "createServer:", "handleRequest:respondTo:", "asString", "port", "host", "listen:host:"],
  752. referencedClasses: []
  753. }),
  754. smalltalk.FileServer);
  755. smalltalk.addMethod(
  756. smalltalk.method({
  757. selector: "startOn:",
  758. category: 'starting',
  759. fn: function (aPort){
  760. var self=this;
  761. return smalltalk.withContext(function($ctx1) {
  762. _st(self)._port_(aPort);
  763. _st(self)._start();
  764. return self}, function($ctx1) {$ctx1.fill(self,"startOn:",{aPort:aPort},smalltalk.FileServer)})},
  765. args: ["aPort"],
  766. source: "startOn: aPort\x0a\x09self port: aPort.\x0a\x09self start",
  767. messageSends: ["port:", "start"],
  768. referencedClasses: []
  769. }),
  770. smalltalk.FileServer);
  771. smalltalk.addMethod(
  772. smalltalk.method({
  773. selector: "username:",
  774. category: 'accessing',
  775. fn: function (aUsername){
  776. var self=this;
  777. return smalltalk.withContext(function($ctx1) {
  778. self["@username"]=aUsername;
  779. return self}, function($ctx1) {$ctx1.fill(self,"username:",{aUsername:aUsername},smalltalk.FileServer)})},
  780. args: ["aUsername"],
  781. source: "username: aUsername\x0a\x09username := aUsername.",
  782. messageSends: [],
  783. referencedClasses: []
  784. }),
  785. smalltalk.FileServer);
  786. smalltalk.addMethod(
  787. smalltalk.method({
  788. selector: "writeData:toFileNamed:",
  789. category: 'private',
  790. fn: function (data,aFilename){
  791. var self=this;
  792. return smalltalk.withContext(function($ctx1) {
  793. _st(console)._log_(aFilename);
  794. return self}, function($ctx1) {$ctx1.fill(self,"writeData:toFileNamed:",{data:data,aFilename:aFilename},smalltalk.FileServer)})},
  795. args: ["data", "aFilename"],
  796. source: "writeData: data toFileNamed: aFilename\x0a\x09console log: aFilename",
  797. messageSends: ["log:"],
  798. referencedClasses: []
  799. }),
  800. smalltalk.FileServer);
  801. smalltalk.FileServer.klass.iVarNames = ['mimeTypes'];
  802. smalltalk.addMethod(
  803. smalltalk.method({
  804. selector: "commandLineSwitches",
  805. category: 'accessing',
  806. fn: function (){
  807. var self=this;
  808. var switches;
  809. return smalltalk.withContext(function($ctx1) {
  810. var $1;
  811. switches=_st(_st(self)._methodsInProtocol_("accessing"))._collect_((function(each){
  812. return smalltalk.withContext(function($ctx2) {
  813. return _st(each)._selector();
  814. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  815. switches=_st(switches)._select_((function(each){
  816. return smalltalk.withContext(function($ctx2) {
  817. return _st(each)._match_("^[^:]*:$");
  818. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  819. switches=_st(switches)._collect_((function(each){
  820. return smalltalk.withContext(function($ctx2) {
  821. return _st(_st(_st(_st(each)._allButLast())._replace_with_("([A-Z])","-$1"))._asLowercase())._replace_with_("^([a-z])","--$1");
  822. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  823. $1=switches;
  824. return $1;
  825. }, function($ctx1) {$ctx1.fill(self,"commandLineSwitches",{switches:switches},smalltalk.FileServer.klass)})},
  826. args: [],
  827. source: "commandLineSwitches\x0a\x09\x22Collect all methodnames from the 'accessing' protocol\x0a\x09 and select the ones with only one parameter.\x0a\x09 Then remove the ':' at the end of the name\x0a\x09 and add a '--' at the beginning.\x0a\x09 Additionally all uppercase letters are made lowercase and preceded by a '-'.\x0a\x09 Example: fallbackPage: becomes --fallback-page.\x0a\x09 Return the Array containing the commandline switches.\x22\x0a\x09| switches |\x0a\x09switches := ((self methodsInProtocol: 'accessing') collect: [ :each | each selector]).\x0a\x09switches := switches select: [ :each | each match: '^[^:]*:$'].\x0a\x09switches :=switches collect: [ :each |\x0a\x09\x09(each allButLast replace: '([A-Z])' with: '-$1') asLowercase replace: '^([a-z])' with: '--$1' ].\x0a\x09^switches",
  828. messageSends: ["collect:", "selector", "methodsInProtocol:", "select:", "match:", "replace:with:", "asLowercase", "allButLast"],
  829. referencedClasses: []
  830. }),
  831. smalltalk.FileServer.klass);
  832. smalltalk.addMethod(
  833. smalltalk.method({
  834. selector: "createServerWithArguments:",
  835. category: 'initialization',
  836. fn: function (options){
  837. var self=this;
  838. var server,popFront,front,optionName,optionValue,switches;
  839. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  840. return smalltalk.withContext(function($ctx1) {
  841. var $1,$2,$3,$4,$5;
  842. var $early={};
  843. try {
  844. switches=_st(self)._commandLineSwitches();
  845. server=_st(self)._new();
  846. _st(options)._ifEmpty_((function(){
  847. return smalltalk.withContext(function($ctx2) {
  848. $1=server;
  849. throw $early=[$1];
  850. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  851. $2=_st(_st(options)._size())._even();
  852. if(! smalltalk.assert($2)){
  853. _st(console)._log_("Using default parameters.");
  854. _st(console)._log_(_st("Wrong commandline options or not enough arguments for: ").__comma(options));
  855. _st(console)._log_(_st("Use any of the following ones: ").__comma(switches));
  856. $3=server;
  857. return $3;
  858. };
  859. popFront=(function(args){
  860. return smalltalk.withContext(function($ctx2) {
  861. front=_st(args)._first();
  862. front;
  863. _st(args)._remove_(front);
  864. return front;
  865. }, function($ctx2) {$ctx2.fillBlock({args:args},$ctx1)})});
  866. _st((function(){
  867. return smalltalk.withContext(function($ctx2) {
  868. return _st(options)._notEmpty();
  869. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  870. return smalltalk.withContext(function($ctx2) {
  871. optionName=_st(popFront)._value_(options);
  872. optionName;
  873. optionValue=_st(popFront)._value_(options);
  874. optionValue;
  875. $4=_st(switches)._includes_(optionName);
  876. if(smalltalk.assert($4)){
  877. optionName=_st(self)._selectorForCommandLineSwitch_(optionName);
  878. optionName;
  879. return _st(server)._perform_withArguments_(optionName,_st($Array())._with_(optionValue));
  880. } else {
  881. _st(console)._log_(_st(optionName).__comma(" is not a valid commandline option"));
  882. return _st(console)._log_(_st("Use any of the following ones: ").__comma(switches));
  883. };
  884. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  885. $5=server;
  886. return $5;
  887. }
  888. catch(e) {if(e===$early)return e[0]; throw e}
  889. }, function($ctx1) {$ctx1.fill(self,"createServerWithArguments:",{options:options,server:server,popFront:popFront,front:front,optionName:optionName,optionValue:optionValue,switches:switches},smalltalk.FileServer.klass)})},
  890. args: ["options"],
  891. source: "createServerWithArguments: options\x0a\x09\x22If options are empty return a default FileServer instance.\x0a\x09 If options are given loop through them and set the passed in values\x0a\x09 on the FileServer instance.\x0a\x09 \x0a\x09 Commanline options map directly to methods in the 'accessing' protocol\x0a\x09 taking one parameter.\x0a\x09 Adding a method to this protocol makes it directly settable through\x0a\x09 command line options.\x0a\x09 \x22\x0a\x09| server popFront front optionName optionValue switches |\x0a\x0a\x09switches := self commandLineSwitches.\x0a\x0a\x09server := self new.\x0a\x0a\x09options ifEmpty: [^server].\x0a\x0a\x09(options size even) ifFalse: [\x0a\x09\x09console log: 'Using default parameters.'.\x0a\x09\x09console log: 'Wrong commandline options or not enough arguments for: ' , options.\x0a\x09\x09console log: 'Use any of the following ones: ', switches.\x0a\x09\x09^server].\x0a\x0a\x09popFront := [:args |\x0a\x09\x09front := args first.\x0a\x09\x09args remove: front.\x0a\x09\x09front].\x0a\x0a\x09[options notEmpty] whileTrue: [\x0a\x09\x09optionName := popFront value: options.\x0a\x09\x09optionValue := popFront value: options.\x0a\x0a\x09\x09(switches includes: optionName) ifTrue: [\x0a\x09\x09\x09optionName := self selectorForCommandLineSwitch: optionName.\x0a\x09\x09\x09server perform: optionName withArguments: (Array with: optionValue)]\x0a\x09\x09\x09ifFalse: [\x0a\x09\x09\x09\x09console log: optionName, ' is not a valid commandline option'.\x0a\x09\x09\x09\x09console log: 'Use any of the following ones: ', switches ]].\x0a\x09^server.",
  892. messageSends: ["commandLineSwitches", "new", "ifEmpty:", "ifFalse:", "log:", ",", "even", "size", "first", "remove:", "whileTrue:", "value:", "ifTrue:ifFalse:", "selectorForCommandLineSwitch:", "perform:withArguments:", "with:", "includes:", "notEmpty"],
  893. referencedClasses: ["Array"]
  894. }),
  895. smalltalk.FileServer.klass);
  896. smalltalk.addMethod(
  897. smalltalk.method({
  898. selector: "defaultHost",
  899. category: 'accessing',
  900. fn: function (){
  901. var self=this;
  902. return smalltalk.withContext(function($ctx1) {
  903. return "127.0.0.1";
  904. }, function($ctx1) {$ctx1.fill(self,"defaultHost",{},smalltalk.FileServer.klass)})},
  905. args: [],
  906. source: "defaultHost\x0a\x09^'127.0.0.1'",
  907. messageSends: [],
  908. referencedClasses: []
  909. }),
  910. smalltalk.FileServer.klass);
  911. smalltalk.addMethod(
  912. smalltalk.method({
  913. selector: "defaultMimeTypes",
  914. category: 'accessing',
  915. fn: function (){
  916. var self=this;
  917. return smalltalk.withContext(function($ctx1) {
  918. var $1;
  919. $1=smalltalk.HashedCollection._fromPairs_([_st("%").__minus_gt("application/x-trash"),_st("323").__minus_gt("text/h323"),_st("abw").__minus_gt("application/x-abiword"),_st("ai").__minus_gt("application/postscript"),_st("aif").__minus_gt("audio/x-aiff"),_st("aifc").__minus_gt("audio/x-aiff"),_st("aiff").__minus_gt("audio/x-aiff"),_st("alc").__minus_gt("chemical/x-alchemy"),_st("art").__minus_gt("image/x-jg"),_st("asc").__minus_gt("text/plain"),_st("asf").__minus_gt("video/x-ms-asf"),_st("asn").__minus_gt("chemical/x-ncbi-asn1-spec"),_st("aso").__minus_gt("chemical/x-ncbi-asn1-binary"),_st("asx").__minus_gt("video/x-ms-asf"),_st("au").__minus_gt("audio/basic"),_st("avi").__minus_gt("video/x-msvideo"),_st("b").__minus_gt("chemical/x-molconn-Z"),_st("bak").__minus_gt("application/x-trash"),_st("bat").__minus_gt("application/x-msdos-program"),_st("bcpio").__minus_gt("application/x-bcpio"),_st("bib").__minus_gt("text/x-bibtex"),_st("bin").__minus_gt("application/octet-stream"),_st("bmp").__minus_gt("image/x-ms-bmp"),_st("book").__minus_gt("application/x-maker"),_st("bsd").__minus_gt("chemical/x-crossfire"),_st("c").__minus_gt("text/x-csrc"),_st("c++").__minus_gt("text/x-c++src"),_st("c3d").__minus_gt("chemical/x-chem3d"),_st("cac").__minus_gt("chemical/x-cache"),_st("cache").__minus_gt("chemical/x-cache"),_st("cascii").__minus_gt("chemical/x-cactvs-binary"),_st("cat").__minus_gt("application/vnd.ms-pki.seccat"),_st("cbin").__minus_gt("chemical/x-cactvs-binary"),_st("cc").__minus_gt("text/x-c++src"),_st("cdf").__minus_gt("application/x-cdf"),_st("cdr").__minus_gt("image/x-coreldraw"),_st("cdt").__minus_gt("image/x-coreldrawtemplate"),_st("cdx").__minus_gt("chemical/x-cdx"),_st("cdy").__minus_gt("application/vnd.cinderella"),_st("cef").__minus_gt("chemical/x-cxf"),_st("cer").__minus_gt("chemical/x-cerius"),_st("chm").__minus_gt("chemical/x-chemdraw"),_st("chrt").__minus_gt("application/x-kchart"),_st("cif").__minus_gt("chemical/x-cif"),_st("class").__minus_gt("application/java-vm"),_st("cls").__minus_gt("text/x-tex"),_st("cmdf").__minus_gt("chemical/x-cmdf"),_st("cml").__minus_gt("chemical/x-cml"),_st("cod").__minus_gt("application/vnd.rim.cod"),_st("com").__minus_gt("application/x-msdos-program"),_st("cpa").__minus_gt("chemical/x-compass"),_st("cpio").__minus_gt("application/x-cpio"),_st("cpp").__minus_gt("text/x-c++src"),_st("cpt").__minus_gt("image/x-corelphotopaint"),_st("crl").__minus_gt("application/x-pkcs7-crl"),_st("crt").__minus_gt("application/x-x509-ca-cert"),_st("csf").__minus_gt("chemical/x-cache-csf"),_st("csh").__minus_gt("text/x-csh"),_st("csm").__minus_gt("chemical/x-csml"),_st("csml").__minus_gt("chemical/x-csml"),_st("css").__minus_gt("text/css"),_st("csv").__minus_gt("text/comma-separated-values"),_st("ctab").__minus_gt("chemical/x-cactvs-binary"),_st("ctx").__minus_gt("chemical/x-ctx"),_st("cu").__minus_gt("application/cu-seeme"),_st("cub").__minus_gt("chemical/x-gaussian-cube"),_st("cxf").__minus_gt("chemical/x-cxf"),_st("cxx").__minus_gt("text/x-c++src"),_st("dat").__minus_gt("chemical/x-mopac-input"),_st("dcr").__minus_gt("application/x-director"),_st("deb").__minus_gt("application/x-debian-package"),_st("dif").__minus_gt("video/dv"),_st("diff").__minus_gt("text/plain"),_st("dir").__minus_gt("application/x-director"),_st("djv").__minus_gt("image/vnd.djvu"),_st("djvu").__minus_gt("image/vnd.djvu"),_st("dl").__minus_gt("video/dl"),_st("dll").__minus_gt("application/x-msdos-program"),_st("dmg").__minus_gt("application/x-apple-diskimage"),_st("dms").__minus_gt("application/x-dms"),_st("doc").__minus_gt("application/msword"),_st("dot").__minus_gt("application/msword"),_st("dv").__minus_gt("video/dv"),_st("dvi").__minus_gt("application/x-dvi"),_st("dx").__minus_gt("chemical/x-jcamp-dx"),_st("dxr").__minus_gt("application/x-director"),_st("emb").__minus_gt("chemical/x-embl-dl-nucleotide"),_st("embl").__minus_gt("chemical/x-embl-dl-nucleotide"),_st("ent").__minus_gt("chemical/x-pdb"),_st("eps").__minus_gt("application/postscript"),_st("etx").__minus_gt("text/x-setext"),_st("exe").__minus_gt("application/x-msdos-program"),_st("ez").__minus_gt("application/andrew-inset"),_st("fb").__minus_gt("application/x-maker"),_st("fbdoc").__minus_gt("application/x-maker"),_st("fch").__minus_gt("chemical/x-gaussian-checkpoint"),_st("fchk").__minus_gt("chemical/x-gaussian-checkpoint"),_st("fig").__minus_gt("application/x-xfig"),_st("flac").__minus_gt("application/x-flac"),_st("fli").__minus_gt("video/fli"),_st("fm").__minus_gt("application/x-maker"),_st("frame").__minus_gt("application/x-maker"),_st("frm").__minus_gt("application/x-maker"),_st("gal").__minus_gt("chemical/x-gaussian-log"),_st("gam").__minus_gt("chemical/x-gamess-input"),_st("gamin").__minus_gt("chemical/x-gamess-input"),_st("gau").__minus_gt("chemical/x-gaussian-input"),_st("gcd").__minus_gt("text/x-pcs-gcd"),_st("gcf").__minus_gt("application/x-graphing-calculator"),_st("gcg").__minus_gt("chemical/x-gcg8-sequence"),_st("gen").__minus_gt("chemical/x-genbank"),_st("gf").__minus_gt("application/x-tex-gf"),_st("gif").__minus_gt("image/gif"),_st("gjc").__minus_gt("chemical/x-gaussian-input"),_st("gjf").__minus_gt("chemical/x-gaussian-input"),_st("gl").__minus_gt("video/gl"),_st("gnumeric").__minus_gt("application/x-gnumeric"),_st("gpt").__minus_gt("chemical/x-mopac-graph"),_st("gsf").__minus_gt("application/x-font"),_st("gsm").__minus_gt("audio/x-gsm"),_st("gtar").__minus_gt("application/x-gtar"),_st("h").__minus_gt("text/x-chdr"),_st("h++").__minus_gt("text/x-c++hdr"),_st("hdf").__minus_gt("application/x-hdf"),_st("hh").__minus_gt("text/x-c++hdr"),_st("hin").__minus_gt("chemical/x-hin"),_st("hpp").__minus_gt("text/x-c++hdr"),_st("hqx").__minus_gt("application/mac-binhex40"),_st("hs").__minus_gt("text/x-haskell"),_st("hta").__minus_gt("application/hta"),_st("htc").__minus_gt("text/x-component"),_st("htm").__minus_gt("text/html"),_st("html").__minus_gt("text/html"),_st("hxx").__minus_gt("text/x-c++hdr"),_st("ica").__minus_gt("application/x-ica"),_st("ice").__minus_gt("x-conference/x-cooltalk"),_st("ico").__minus_gt("image/x-icon"),_st("ics").__minus_gt("text/calendar"),_st("icz").__minus_gt("text/calendar"),_st("ief").__minus_gt("image/ief"),_st("iges").__minus_gt("model/iges"),_st("igs").__minus_gt("model/iges"),_st("iii").__minus_gt("application/x-iphone"),_st("inp").__minus_gt("chemical/x-gamess-input"),_st("ins").__minus_gt("application/x-internet-signup"),_st("iso").__minus_gt("application/x-iso9660-image"),_st("isp").__minus_gt("application/x-internet-signup"),_st("ist").__minus_gt("chemical/x-isostar"),_st("istr").__minus_gt("chemical/x-isostar"),_st("jad").__minus_gt("text/vnd.sun.j2me.app-descriptor"),_st("jar").__minus_gt("application/java-archive"),_st("java").__minus_gt("text/x-java"),_st("jdx").__minus_gt("chemical/x-jcamp-dx"),_st("jmz").__minus_gt("application/x-jmol"),_st("jng").__minus_gt("image/x-jng"),_st("jnlp").__minus_gt("application/x-java-jnlp-file"),_st("jpe").__minus_gt("image/jpeg"),_st("jpeg").__minus_gt("image/jpeg"),_st("jpg").__minus_gt("image/jpeg"),_st("js").__minus_gt("application/javascript"),_st("kar").__minus_gt("audio/midi"),_st("key").__minus_gt("application/pgp-keys"),_st("kil").__minus_gt("application/x-killustrator"),_st("kin").__minus_gt("chemical/x-kinemage"),_st("kpr").__minus_gt("application/x-kpresenter"),_st("kpt").__minus_gt("application/x-kpresenter"),_st("ksp").__minus_gt("application/x-kspread"),_st("kwd").__minus_gt("application/x-kword"),_st("kwt").__minus_gt("application/x-kword"),_st("latex").__minus_gt("application/x-latex"),_st("lha").__minus_gt("application/x-lha"),_st("lhs").__minus_gt("text/x-literate-haskell"),_st("lsf").__minus_gt("video/x-la-asf"),_st("lsx").__minus_gt("video/x-la-asf"),_st("ltx").__minus_gt("text/x-tex"),_st("lzh").__minus_gt("application/x-lzh"),_st("lzx").__minus_gt("application/x-lzx"),_st("m3u").__minus_gt("audio/x-mpegurl"),_st("m4a").__minus_gt("audio/mpeg"),_st("maker").__minus_gt("application/x-maker"),_st("man").__minus_gt("application/x-troff-man"),_st("mcif").__minus_gt("chemical/x-mmcif"),_st("mcm").__minus_gt("chemical/x-macmolecule"),_st("mdb").__minus_gt("application/msaccess"),_st("me").__minus_gt("application/x-troff-me"),_st("mesh").__minus_gt("model/mesh"),_st("mid").__minus_gt("audio/midi"),_st("midi").__minus_gt("audio/midi"),_st("mif").__minus_gt("application/x-mif"),_st("mm").__minus_gt("application/x-freemind"),_st("mmd").__minus_gt("chemical/x-macromodel-input"),_st("mmf").__minus_gt("application/vnd.smaf"),_st("mml").__minus_gt("text/mathml"),_st("mmod").__minus_gt("chemical/x-macromodel-input"),_st("mng").__minus_gt("video/x-mng"),_st("moc").__minus_gt("text/x-moc"),_st("mol").__minus_gt("chemical/x-mdl-molfile"),_st("mol2").__minus_gt("chemical/x-mol2"),_st("moo").__minus_gt("chemical/x-mopac-out"),_st("mop").__minus_gt("chemical/x-mopac-input"),_st("mopcrt").__minus_gt("chemical/x-mopac-input"),_st("mov").__minus_gt("video/quicktime"),_st("movie").__minus_gt("video/x-sgi-movie"),_st("mp2").__minus_gt("audio/mpeg"),_st("mp3").__minus_gt("audio/mpeg"),_st("mp4").__minus_gt("video/mp4"),_st("mpc").__minus_gt("chemical/x-mopac-input"),_st("mpe").__minus_gt("video/mpeg"),_st("mpeg").__minus_gt("video/mpeg"),_st("mpega").__minus_gt("audio/mpeg"),_st("mpg").__minus_gt("video/mpeg"),_st("mpga").__minus_gt("audio/mpeg"),_st("ms").__minus_gt("application/x-troff-ms"),_st("msh").__minus_gt("model/mesh"),_st("msi").__minus_gt("application/x-msi"),_st("mvb").__minus_gt("chemical/x-mopac-vib"),_st("mxu").__minus_gt("video/vnd.mpegurl"),_st("nb").__minus_gt("application/mathematica"),_st("nc").__minus_gt("application/x-netcdf"),_st("nwc").__minus_gt("application/x-nwc"),_st("o").__minus_gt("application/x-object"),_st("oda").__minus_gt("application/oda"),_st("odb").__minus_gt("application/vnd.oasis.opendocument.database"),_st("odc").__minus_gt("application/vnd.oasis.opendocument.chart"),_st("odf").__minus_gt("application/vnd.oasis.opendocument.formula"),_st("odg").__minus_gt("application/vnd.oasis.opendocument.graphics"),_st("odi").__minus_gt("application/vnd.oasis.opendocument.image"),_st("odm").__minus_gt("application/vnd.oasis.opendocument.text-master"),_st("odp").__minus_gt("application/vnd.oasis.opendocument.presentation"),_st("ods").__minus_gt("application/vnd.oasis.opendocument.spreadsheet"),_st("odt").__minus_gt("application/vnd.oasis.opendocument.text"),_st("ogg").__minus_gt("application/ogg"),_st("old").__minus_gt("application/x-trash"),_st("oth").__minus_gt("application/vnd.oasis.opendocument.text-web"),_st("oza").__minus_gt("application/x-oz-application"),_st("p").__minus_gt("text/x-pascal"),_st("p7r").__minus_gt("application/x-pkcs7-certreqresp"),_st("pac").__minus_gt("application/x-ns-proxy-autoconfig"),_st("pas").__minus_gt("text/x-pascal"),_st("pat").__minus_gt("image/x-coreldrawpattern"),_st("pbm").__minus_gt("image/x-portable-bitmap"),_st("pcf").__minus_gt("application/x-font"),_st("pcf.Z").__minus_gt("application/x-font"),_st("pcx").__minus_gt("image/pcx"),_st("pdb").__minus_gt("chemical/x-pdb"),_st("pdf").__minus_gt("application/pdf"),_st("pfa").__minus_gt("application/x-font"),_st("pfb").__minus_gt("application/x-font"),_st("pgm").__minus_gt("image/x-portable-graymap"),_st("pgn").__minus_gt("application/x-chess-pgn"),_st("pgp").__minus_gt("application/pgp-signature"),_st("pk").__minus_gt("application/x-tex-pk"),_st("pl").__minus_gt("text/x-perl"),_st("pls").__minus_gt("audio/x-scpls"),_st("pm").__minus_gt("text/x-perl"),_st("png").__minus_gt("image/png"),_st("pnm").__minus_gt("image/x-portable-anymap"),_st("pot").__minus_gt("text/plain"),_st("ppm").__minus_gt("image/x-portable-pixmap"),_st("pps").__minus_gt("application/vnd.ms-powerpoint"),_st("ppt").__minus_gt("application/vnd.ms-powerpoint"),_st("prf").__minus_gt("application/pics-rules"),_st("prt").__minus_gt("chemical/x-ncbi-asn1-ascii"),_st("ps").__minus_gt("application/postscript"),_st("psd").__minus_gt("image/x-photoshop"),_st("psp").__minus_gt("text/x-psp"),_st("py").__minus_gt("text/x-python"),_st("pyc").__minus_gt("application/x-python-code"),_st("pyo").__minus_gt("application/x-python-code"),_st("qt").__minus_gt("video/quicktime"),_st("qtl").__minus_gt("application/x-quicktimeplayer"),_st("ra").__minus_gt("audio/x-realaudio"),_st("ram").__minus_gt("audio/x-pn-realaudio"),_st("rar").__minus_gt("application/rar"),_st("ras").__minus_gt("image/x-cmu-raster"),_st("rd").__minus_gt("chemical/x-mdl-rdfile"),_st("rdf").__minus_gt("application/rdf+xml"),_st("rgb").__minus_gt("image/x-rgb"),_st("rm").__minus_gt("audio/x-pn-realaudio"),_st("roff").__minus_gt("application/x-troff"),_st("ros").__minus_gt("chemical/x-rosdal"),_st("rpm").__minus_gt("application/x-redhat-package-manager"),_st("rss").__minus_gt("application/rss+xml"),_st("rtf").__minus_gt("text/rtf"),_st("rtx").__minus_gt("text/richtext"),_st("rxn").__minus_gt("chemical/x-mdl-rxnfile"),_st("sct").__minus_gt("text/scriptlet"),_st("sd").__minus_gt("chemical/x-mdl-sdfile"),_st("sd2").__minus_gt("audio/x-sd2"),_st("sda").__minus_gt("application/vnd.stardivision.draw"),_st("sdc").__minus_gt("application/vnd.stardivision.calc"),_st("sdd").__minus_gt("application/vnd.stardivision.impress"),_st("sdf").__minus_gt("chemical/x-mdl-sdfile"),_st("sdp").__minus_gt("application/vnd.stardivision.impress"),_st("sdw").__minus_gt("application/vnd.stardivision.writer"),_st("ser").__minus_gt("application/java-serialized-object"),_st("sgf").__minus_gt("application/x-go-sgf"),_st("sgl").__minus_gt("application/vnd.stardivision.writer-global"),_st("sh").__minus_gt("text/x-sh"),_st("shar").__minus_gt("application/x-shar"),_st("shtml").__minus_gt("text/html"),_st("sid").__minus_gt("audio/prs.sid"),_st("sik").__minus_gt("application/x-trash"),_st("silo").__minus_gt("model/mesh"),_st("sis").__minus_gt("application/vnd.symbian.install"),_st("sit").__minus_gt("application/x-stuffit"),_st("skd").__minus_gt("application/x-koan"),_st("skm").__minus_gt("application/x-koan"),_st("skp").__minus_gt("application/x-koan"),_st("skt").__minus_gt("application/x-koan"),_st("smf").__minus_gt("application/vnd.stardivision.math"),_st("smi").__minus_gt("application/smil"),_st("smil").__minus_gt("application/smil"),_st("snd").__minus_gt("audio/basic"),_st("spc").__minus_gt("chemical/x-galactic-spc"),_st("spl").__minus_gt("application/x-futuresplash"),_st("src").__minus_gt("application/x-wais-source"),_st("stc").__minus_gt("application/vnd.sun.xml.calc.template"),_st("std").__minus_gt("application/vnd.sun.xml.draw.template"),_st("sti").__minus_gt("application/vnd.sun.xml.impress.template"),_st("stl").__minus_gt("application/vnd.ms-pki.stl"),_st("stw").__minus_gt("application/vnd.sun.xml.writer.template"),_st("sty").__minus_gt("text/x-tex"),_st("sv4cpio").__minus_gt("application/x-sv4cpio"),_st("sv4crc").__minus_gt("application/x-sv4crc"),_st("svg").__minus_gt("image/svg+xml"),_st("svgz").__minus_gt("image/svg+xml"),_st("sw").__minus_gt("chemical/x-swissprot"),_st("swf").__minus_gt("application/x-shockwave-flash"),_st("swfl").__minus_gt("application/x-shockwave-flash"),_st("sxc").__minus_gt("application/vnd.sun.xml.calc"),_st("sxd").__minus_gt("application/vnd.sun.xml.draw"),_st("sxg").__minus_gt("application/vnd.sun.xml.writer.global"),_st("sxi").__minus_gt("application/vnd.sun.xml.impress"),_st("sxm").__minus_gt("application/vnd.sun.xml.math"),_st("sxw").__minus_gt("application/vnd.sun.xml.writer"),_st("t").__minus_gt("application/x-troff"),_st("tar").__minus_gt("application/x-tar"),_st("taz").__minus_gt("application/x-gtar"),_st("tcl").__minus_gt("text/x-tcl"),_st("tex").__minus_gt("text/x-tex"),_st("texi").__minus_gt("application/x-texinfo"),_st("texinfo").__minus_gt("application/x-texinfo"),_st("text").__minus_gt("text/plain"),_st("tgf").__minus_gt("chemical/x-mdl-tgf"),_st("tgz").__minus_gt("application/x-gtar"),_st("tif").__minus_gt("image/tiff"),_st("tiff").__minus_gt("image/tiff"),_st("tk").__minus_gt("text/x-tcl"),_st("tm").__minus_gt("text/texmacs"),_st("torrent").__minus_gt("application/x-bittorrent"),_st("tr").__minus_gt("application/x-troff"),_st("ts").__minus_gt("text/texmacs"),_st("tsp").__minus_gt("application/dsptype"),_st("tsv").__minus_gt("text/tab-separated-values"),_st("txt").__minus_gt("text/plain"),_st("udeb").__minus_gt("application/x-debian-package"),_st("uls").__minus_gt("text/iuls"),_st("ustar").__minus_gt("application/x-ustar"),_st("val").__minus_gt("chemical/x-ncbi-asn1-binary"),_st("vcd").__minus_gt("application/x-cdlink"),_st("vcf").__minus_gt("text/x-vcard"),_st("vcs").__minus_gt("text/x-vcalendar"),_st("vmd").__minus_gt("chemical/x-vmd"),_st("vms").__minus_gt("chemical/x-vamas-iso14976"),_st("vor").__minus_gt("application/vnd.stardivision.writer"),_st("vrm").__minus_gt("x-world/x-vrml"),_st("vrml").__minus_gt("x-world/x-vrml"),_st("vsd").__minus_gt("application/vnd.visio"),_st("wad").__minus_gt("application/x-doom"),_st("wav").__minus_gt("audio/x-wav"),_st("wax").__minus_gt("audio/x-ms-wax"),_st("wbmp").__minus_gt("image/vnd.wap.wbmp"),_st("wbxml").__minus_gt("application/vnd.wap.wbxml"),_st("wk").__minus_gt("application/x-123"),_st("wm").__minus_gt("video/x-ms-wm"),_st("wma").__minus_gt("audio/x-ms-wma"),_st("wmd").__minus_gt("application/x-ms-wmd"),_st("wml").__minus_gt("text/vnd.wap.wml"),_st("wmlc").__minus_gt("application/vnd.wap.wmlc"),_st("wmls").__minus_gt("text/vnd.wap.wmlscript"),_st("wmlsc").__minus_gt("application/vnd.wap.wmlscriptc"),_st("wmv").__minus_gt("video/x-ms-wmv"),_st("wmx").__minus_gt("video/x-ms-wmx"),_st("wmz").__minus_gt("application/x-ms-wmz"),_st("wp5").__minus_gt("application/wordperfect5.1"),_st("wpd").__minus_gt("application/wordperfect"),_st("wrl").__minus_gt("x-world/x-vrml"),_st("wsc").__minus_gt("text/scriptlet"),_st("wvx").__minus_gt("video/x-ms-wvx"),_st("wz").__minus_gt("application/x-wingz"),_st("xbm").__minus_gt("image/x-xbitmap"),_st("xcf").__minus_gt("application/x-xcf"),_st("xht").__minus_gt("application/xhtml+xml"),_st("xhtml").__minus_gt("application/xhtml+xml"),_st("xlb").__minus_gt("application/vnd.ms-excel"),_st("xls").__minus_gt("application/vnd.ms-excel"),_st("xlt").__minus_gt("application/vnd.ms-excel"),_st("xml").__minus_gt("application/xml"),_st("xpi").__minus_gt("application/x-xpinstall"),_st("xpm").__minus_gt("image/x-xpixmap"),_st("xsl").__minus_gt("application/xml"),_st("xtel").__minus_gt("chemical/x-xtel"),_st("xul").__minus_gt("application/vnd.mozilla.xul+xml"),_st("xwd").__minus_gt("image/x-xwindowdump"),_st("xyz").__minus_gt("chemical/x-xyz"),_st("zip").__minus_gt("application/zip"),_st("zmt").__minus_gt("chemical/x-mopac-input"),_st("~").__minus_gt("application/x-trash")]);
  920. return $1;
  921. }, function($ctx1) {$ctx1.fill(self,"defaultMimeTypes",{},smalltalk.FileServer.klass)})},
  922. args: [],
  923. source: "defaultMimeTypes\x0a\x09^ #{\x0a\x09\x09'%' -> 'application/x-trash'.\x0a\x09\x09'323' -> 'text/h323'.\x0a\x09\x09'abw' -> 'application/x-abiword'.\x0a\x09\x09'ai' -> 'application/postscript'.\x0a\x09\x09'aif' -> 'audio/x-aiff'.\x0a\x09\x09'aifc' -> 'audio/x-aiff'.\x0a\x09\x09'aiff' -> 'audio/x-aiff'.\x0a\x09\x09'alc' -> 'chemical/x-alchemy'.\x0a\x09\x09'art' -> 'image/x-jg'.\x0a\x09\x09'asc' -> 'text/plain'.\x0a\x09\x09'asf' -> 'video/x-ms-asf'.\x0a\x09\x09'asn' -> 'chemical/x-ncbi-asn1-spec'.\x0a\x09\x09'aso' -> 'chemical/x-ncbi-asn1-binary'.\x0a\x09\x09'asx' -> 'video/x-ms-asf'.\x0a\x09\x09'au' -> 'audio/basic'.\x0a\x09\x09'avi' -> 'video/x-msvideo'.\x0a\x09\x09'b' -> 'chemical/x-molconn-Z'.\x0a\x09\x09'bak' -> 'application/x-trash'.\x0a\x09\x09'bat' -> 'application/x-msdos-program'.\x0a\x09\x09'bcpio' -> 'application/x-bcpio'.\x0a\x09\x09'bib' -> 'text/x-bibtex'.\x0a\x09\x09'bin' -> 'application/octet-stream'.\x0a\x09\x09'bmp' -> 'image/x-ms-bmp'.\x0a\x09\x09'book' -> 'application/x-maker'.\x0a\x09\x09'bsd' -> 'chemical/x-crossfire'.\x0a\x09\x09'c' -> 'text/x-csrc'.\x0a\x09\x09'c++' -> 'text/x-c++src'.\x0a\x09\x09'c3d' -> 'chemical/x-chem3d'.\x0a\x09\x09'cac' -> 'chemical/x-cache'.\x0a\x09\x09'cache' -> 'chemical/x-cache'.\x0a\x09\x09'cascii' -> 'chemical/x-cactvs-binary'.\x0a\x09\x09'cat' -> 'application/vnd.ms-pki.seccat'.\x0a\x09\x09'cbin' -> 'chemical/x-cactvs-binary'.\x0a\x09\x09'cc' -> 'text/x-c++src'.\x0a\x09\x09'cdf' -> 'application/x-cdf'.\x0a\x09\x09'cdr' -> 'image/x-coreldraw'.\x0a\x09\x09'cdt' -> 'image/x-coreldrawtemplate'.\x0a\x09\x09'cdx' -> 'chemical/x-cdx'.\x0a\x09\x09'cdy' -> 'application/vnd.cinderella'.\x0a\x09\x09'cef' -> 'chemical/x-cxf'.\x0a\x09\x09'cer' -> 'chemical/x-cerius'.\x0a\x09\x09'chm' -> 'chemical/x-chemdraw'.\x0a\x09\x09'chrt' -> 'application/x-kchart'.\x0a\x09\x09'cif' -> 'chemical/x-cif'.\x0a\x09\x09'class' -> 'application/java-vm'.\x0a\x09\x09'cls' -> 'text/x-tex'.\x0a\x09\x09'cmdf' -> 'chemical/x-cmdf'.\x0a\x09\x09'cml' -> 'chemical/x-cml'.\x0a\x09\x09'cod' -> 'application/vnd.rim.cod'.\x0a\x09\x09'com' -> 'application/x-msdos-program'.\x0a\x09\x09'cpa' -> 'chemical/x-compass'.\x0a\x09\x09'cpio' -> 'application/x-cpio'.\x0a\x09\x09'cpp' -> 'text/x-c++src'.\x0a\x09\x09'cpt' -> 'image/x-corelphotopaint'.\x0a\x09\x09'crl' -> 'application/x-pkcs7-crl'.\x0a\x09\x09'crt' -> 'application/x-x509-ca-cert'.\x0a\x09\x09'csf' -> 'chemical/x-cache-csf'.\x0a\x09\x09'csh' -> 'text/x-csh'.\x0a\x09\x09'csm' -> 'chemical/x-csml'.\x0a\x09\x09'csml' -> 'chemical/x-csml'.\x0a\x09\x09'css' -> 'text/css'.\x0a\x09\x09'csv' -> 'text/comma-separated-values'.\x0a\x09\x09'ctab' -> 'chemical/x-cactvs-binary'.\x0a\x09\x09'ctx' -> 'chemical/x-ctx'.\x0a\x09\x09'cu' -> 'application/cu-seeme'.\x0a\x09\x09'cub' -> 'chemical/x-gaussian-cube'.\x0a\x09\x09'cxf' -> 'chemical/x-cxf'.\x0a\x09\x09'cxx' -> 'text/x-c++src'.\x0a\x09\x09'dat' -> 'chemical/x-mopac-input'.\x0a\x09\x09'dcr' -> 'application/x-director'.\x0a\x09\x09'deb' -> 'application/x-debian-package'.\x0a\x09\x09'dif' -> 'video/dv'.\x0a\x09\x09'diff' -> 'text/plain'.\x0a\x09\x09'dir' -> 'application/x-director'.\x0a\x09\x09'djv' -> 'image/vnd.djvu'.\x0a\x09\x09'djvu' -> 'image/vnd.djvu'.\x0a\x09\x09'dl' -> 'video/dl'.\x0a\x09\x09'dll' -> 'application/x-msdos-program'.\x0a\x09\x09'dmg' -> 'application/x-apple-diskimage'.\x0a\x09\x09'dms' -> 'application/x-dms'.\x0a\x09\x09'doc' -> 'application/msword'.\x0a\x09\x09'dot' -> 'application/msword'.\x0a\x09\x09'dv' -> 'video/dv'.\x0a\x09\x09'dvi' -> 'application/x-dvi'.\x0a\x09\x09'dx' -> 'chemical/x-jcamp-dx'.\x0a\x09\x09'dxr' -> 'application/x-director'.\x0a\x09\x09'emb' -> 'chemical/x-embl-dl-nucleotide'.\x0a\x09\x09'embl' -> 'chemical/x-embl-dl-nucleotide'.\x0a\x09\x09'ent' -> 'chemical/x-pdb'.\x0a\x09\x09'eps' -> 'application/postscript'.\x0a\x09\x09'etx' -> 'text/x-setext'.\x0a\x09\x09'exe' -> 'application/x-msdos-program'.\x0a\x09\x09'ez' -> 'application/andrew-inset'.\x0a\x09\x09'fb' -> 'application/x-maker'.\x0a\x09\x09'fbdoc' -> 'application/x-maker'.\x0a\x09\x09'fch' -> 'chemical/x-gaussian-checkpoint'.\x0a\x09\x09'fchk' -> 'chemical/x-gaussian-checkpoint'.\x0a\x09\x09'fig' -> 'application/x-xfig'.\x0a\x09\x09'flac' -> 'application/x-flac'.\x0a\x09\x09'fli' -> 'video/fli'.\x0a\x09\x09'fm' -> 'application/x-maker'.\x0a\x09\x09'frame' -> 'application/x-maker'.\x0a\x09\x09'frm' -> 'application/x-maker'.\x0a\x09\x09'gal' -> 'chemical/x-gaussian-log'.\x0a\x09\x09'gam' -> 'chemical/x-gamess-input'.\x0a\x09\x09'gamin' -> 'chemical/x-gamess-input'.\x0a\x09\x09'gau' -> 'chemical/x-gaussian-input'.\x0a\x09\x09'gcd' -> 'text/x-pcs-gcd'.\x0a\x09\x09'gcf' -> 'application/x-graphing-calculator'.\x0a\x09\x09'gcg' -> 'chemical/x-gcg8-sequence'.\x0a\x09\x09'gen' -> 'chemical/x-genbank'.\x0a\x09\x09'gf' -> 'application/x-tex-gf'.\x0a\x09\x09'gif' -> 'image/gif'.\x0a\x09\x09'gjc' -> 'chemical/x-gaussian-input'.\x0a\x09\x09'gjf' -> 'chemical/x-gaussian-input'.\x0a\x09\x09'gl' -> 'video/gl'.\x0a\x09\x09'gnumeric' -> 'application/x-gnumeric'.\x0a\x09\x09'gpt' -> 'chemical/x-mopac-graph'.\x0a\x09\x09'gsf' -> 'application/x-font'.\x0a\x09\x09'gsm' -> 'audio/x-gsm'.\x0a\x09\x09'gtar' -> 'application/x-gtar'.\x0a\x09\x09'h' -> 'text/x-chdr'.\x0a\x09\x09'h++' -> 'text/x-c++hdr'.\x0a\x09\x09'hdf' -> 'application/x-hdf'.\x0a\x09\x09'hh' -> 'text/x-c++hdr'.\x0a\x09\x09'hin' -> 'chemical/x-hin'.\x0a\x09\x09'hpp' -> 'text/x-c++hdr'.\x0a\x09\x09'hqx' -> 'application/mac-binhex40'.\x0a\x09\x09'hs' -> 'text/x-haskell'.\x0a\x09\x09'hta' -> 'application/hta'.\x0a\x09\x09'htc' -> 'text/x-component'.\x0a\x09\x09'htm' -> 'text/html'.\x0a\x09\x09'html' -> 'text/html'.\x0a\x09\x09'hxx' -> 'text/x-c++hdr'.\x0a\x09\x09'ica' -> 'application/x-ica'.\x0a\x09\x09'ice' -> 'x-conference/x-cooltalk'.\x0a\x09\x09'ico' -> 'image/x-icon'.\x0a\x09\x09'ics' -> 'text/calendar'.\x0a\x09\x09'icz' -> 'text/calendar'.\x0a\x09\x09'ief' -> 'image/ief'.\x0a\x09\x09'iges' -> 'model/iges'.\x0a\x09\x09'igs' -> 'model/iges'.\x0a\x09\x09'iii' -> 'application/x-iphone'.\x0a\x09\x09'inp' -> 'chemical/x-gamess-input'.\x0a\x09\x09'ins' -> 'application/x-internet-signup'.\x0a\x09\x09'iso' -> 'application/x-iso9660-image'.\x0a\x09\x09'isp' -> 'application/x-internet-signup'.\x0a\x09\x09'ist' -> 'chemical/x-isostar'.\x0a\x09\x09'istr' -> 'chemical/x-isostar'.\x0a\x09\x09'jad' -> 'text/vnd.sun.j2me.app-descriptor'.\x0a\x09\x09'jar' -> 'application/java-archive'.\x0a\x09\x09'java' -> 'text/x-java'.\x0a\x09\x09'jdx' -> 'chemical/x-jcamp-dx'.\x0a\x09\x09'jmz' -> 'application/x-jmol'.\x0a\x09\x09'jng' -> 'image/x-jng'.\x0a\x09\x09'jnlp' -> 'application/x-java-jnlp-file'.\x0a\x09\x09'jpe' -> 'image/jpeg'.\x0a\x09\x09'jpeg' -> 'image/jpeg'.\x0a\x09\x09'jpg' -> 'image/jpeg'.\x0a\x09\x09'js' -> 'application/javascript'.\x0a\x09\x09'kar' -> 'audio/midi'.\x0a\x09\x09'key' -> 'application/pgp-keys'.\x0a\x09\x09'kil' -> 'application/x-killustrator'.\x0a\x09\x09'kin' -> 'chemical/x-kinemage'.\x0a\x09\x09'kpr' -> 'application/x-kpresenter'.\x0a\x09\x09'kpt' -> 'application/x-kpresenter'.\x0a\x09\x09'ksp' -> 'application/x-kspread'.\x0a\x09\x09'kwd' -> 'application/x-kword'.\x0a\x09\x09'kwt' -> 'application/x-kword'.\x0a\x09\x09'latex' -> 'application/x-latex'.\x0a\x09\x09'lha' -> 'application/x-lha'.\x0a\x09\x09'lhs' -> 'text/x-literate-haskell'.\x0a\x09\x09'lsf' -> 'video/x-la-asf'.\x0a\x09\x09'lsx' -> 'video/x-la-asf'.\x0a\x09\x09'ltx' -> 'text/x-tex'.\x0a\x09\x09'lzh' -> 'application/x-lzh'.\x0a\x09\x09'lzx' -> 'application/x-lzx'.\x0a\x09\x09'm3u' -> 'audio/x-mpegurl'.\x0a\x09\x09'm4a' -> 'audio/mpeg'.\x0a\x09\x09'maker' -> 'application/x-maker'.\x0a\x09\x09'man' -> 'application/x-troff-man'.\x0a\x09\x09'mcif' -> 'chemical/x-mmcif'.\x0a\x09\x09'mcm' -> 'chemical/x-macmolecule'.\x0a\x09\x09'mdb' -> 'application/msaccess'.\x0a\x09\x09'me' -> 'application/x-troff-me'.\x0a\x09\x09'mesh' -> 'model/mesh'.\x0a\x09\x09'mid' -> 'audio/midi'.\x0a\x09\x09'midi' -> 'audio/midi'.\x0a\x09\x09'mif' -> 'application/x-mif'.\x0a\x09\x09'mm' -> 'application/x-freemind'.\x0a\x09\x09'mmd' -> 'chemical/x-macromodel-input'.\x0a\x09\x09'mmf' -> 'application/vnd.smaf'.\x0a\x09\x09'mml' -> 'text/mathml'.\x0a\x09\x09'mmod' -> 'chemical/x-macromodel-input'.\x0a\x09\x09'mng' -> 'video/x-mng'.\x0a\x09\x09'moc' -> 'text/x-moc'.\x0a\x09\x09'mol' -> 'chemical/x-mdl-molfile'.\x0a\x09\x09'mol2' -> 'chemical/x-mol2'.\x0a\x09\x09'moo' -> 'chemical/x-mopac-out'.\x0a\x09\x09'mop' -> 'chemical/x-mopac-input'.\x0a\x09\x09'mopcrt' -> 'chemical/x-mopac-input'.\x0a\x09\x09'mov' -> 'video/quicktime'.\x0a\x09\x09'movie' -> 'video/x-sgi-movie'.\x0a\x09\x09'mp2' -> 'audio/mpeg'.\x0a\x09\x09'mp3' -> 'audio/mpeg'.\x0a\x09\x09'mp4' -> 'video/mp4'.\x0a\x09\x09'mpc' -> 'chemical/x-mopac-input'.\x0a\x09\x09'mpe' -> 'video/mpeg'.\x0a\x09\x09'mpeg' -> 'video/mpeg'.\x0a\x09\x09'mpega' -> 'audio/mpeg'.\x0a\x09\x09'mpg' -> 'video/mpeg'.\x0a\x09\x09'mpga' -> 'audio/mpeg'.\x0a\x09\x09'ms' -> 'application/x-troff-ms'.\x0a\x09\x09'msh' -> 'model/mesh'.\x0a\x09\x09'msi' -> 'application/x-msi'.\x0a\x09\x09'mvb' -> 'chemical/x-mopac-vib'.\x0a\x09\x09'mxu' -> 'video/vnd.mpegurl'.\x0a\x09\x09'nb' -> 'application/mathematica'.\x0a\x09\x09'nc' -> 'application/x-netcdf'.\x0a\x09\x09'nwc' -> 'application/x-nwc'.\x0a\x09\x09'o' -> 'application/x-object'.\x0a\x09\x09'oda' -> 'application/oda'.\x0a\x09\x09'odb' -> 'application/vnd.oasis.opendocument.database'.\x0a\x09\x09'odc' -> 'application/vnd.oasis.opendocument.chart'.\x0a\x09\x09'odf' -> 'application/vnd.oasis.opendocument.formula'.\x0a\x09\x09'odg' -> 'application/vnd.oasis.opendocument.graphics'.\x0a\x09\x09'odi' -> 'application/vnd.oasis.opendocument.image'.\x0a\x09\x09'odm' -> 'application/vnd.oasis.opendocument.text-master'.\x0a\x09\x09'odp' -> 'application/vnd.oasis.opendocument.presentation'.\x0a\x09\x09'ods' -> 'application/vnd.oasis.opendocument.spreadsheet'.\x0a\x09\x09'odt' -> 'application/vnd.oasis.opendocument.text'.\x0a\x09\x09'ogg' -> 'application/ogg'.\x0a\x09\x09'old' -> 'application/x-trash'.\x0a\x09\x09'oth' -> 'application/vnd.oasis.opendocument.text-web'.\x0a\x09\x09'oza' -> 'application/x-oz-application'.\x0a\x09\x09'p' -> 'text/x-pascal'.\x0a\x09\x09'p7r' -> 'application/x-pkcs7-certreqresp'.\x0a\x09\x09'pac' -> 'application/x-ns-proxy-autoconfig'.\x0a\x09\x09'pas' -> 'text/x-pascal'.\x0a\x09\x09'pat' -> 'image/x-coreldrawpattern'.\x0a\x09\x09'pbm' -> 'image/x-portable-bitmap'.\x0a\x09\x09'pcf' -> 'application/x-font'.\x0a\x09\x09'pcf.Z' -> 'application/x-font'.\x0a\x09\x09'pcx' -> 'image/pcx'.\x0a\x09\x09'pdb' -> 'chemical/x-pdb'.\x0a\x09\x09'pdf' -> 'application/pdf'.\x0a\x09\x09'pfa' -> 'application/x-font'.\x0a\x09\x09'pfb' -> 'application/x-font'.\x0a\x09\x09'pgm' -> 'image/x-portable-graymap'.\x0a\x09\x09'pgn' -> 'application/x-chess-pgn'.\x0a\x09\x09'pgp' -> 'application/pgp-signature'.\x0a\x09\x09'pk' -> 'application/x-tex-pk'.\x0a\x09\x09'pl' -> 'text/x-perl'.\x0a\x09\x09'pls' -> 'audio/x-scpls'.\x0a\x09\x09'pm' -> 'text/x-perl'.\x0a\x09\x09'png' -> 'image/png'.\x0a\x09\x09'pnm' -> 'image/x-portable-anymap'.\x0a\x09\x09'pot' -> 'text/plain'.\x0a\x09\x09'ppm' -> 'image/x-portable-pixmap'.\x0a\x09\x09'pps' -> 'application/vnd.ms-powerpoint'.\x0a\x09\x09'ppt' -> 'application/vnd.ms-powerpoint'.\x0a\x09\x09'prf' -> 'application/pics-rules'.\x0a\x09\x09'prt' -> 'chemical/x-ncbi-asn1-ascii'.\x0a\x09\x09'ps' -> 'application/postscript'.\x0a\x09\x09'psd' -> 'image/x-photoshop'.\x0a\x09\x09'psp' -> 'text/x-psp'.\x0a\x09\x09'py' -> 'text/x-python'.\x0a\x09\x09'pyc' -> 'application/x-python-code'.\x0a\x09\x09'pyo' -> 'application/x-python-code'.\x0a\x09\x09'qt' -> 'video/quicktime'.\x0a\x09\x09'qtl' -> 'application/x-quicktimeplayer'.\x0a\x09\x09'ra' -> 'audio/x-realaudio'.\x0a\x09\x09'ram' -> 'audio/x-pn-realaudio'.\x0a\x09\x09'rar' -> 'application/rar'.\x0a\x09\x09'ras' -> 'image/x-cmu-raster'.\x0a\x09\x09'rd' -> 'chemical/x-mdl-rdfile'.\x0a\x09\x09'rdf' -> 'application/rdf+xml'.\x0a\x09\x09'rgb' -> 'image/x-rgb'.\x0a\x09\x09'rm' -> 'audio/x-pn-realaudio'.\x0a\x09\x09'roff' -> 'application/x-troff'.\x0a\x09\x09'ros' -> 'chemical/x-rosdal'.\x0a\x09\x09'rpm' -> 'application/x-redhat-package-manager'.\x0a\x09\x09'rss' -> 'application/rss+xml'.\x0a\x09\x09'rtf' -> 'text/rtf'.\x0a\x09\x09'rtx' -> 'text/richtext'.\x0a\x09\x09'rxn' -> 'chemical/x-mdl-rxnfile'.\x0a\x09\x09'sct' -> 'text/scriptlet'.\x0a\x09\x09'sd' -> 'chemical/x-mdl-sdfile'.\x0a\x09\x09'sd2' -> 'audio/x-sd2'.\x0a\x09\x09'sda' -> 'application/vnd.stardivision.draw'.\x0a\x09\x09'sdc' -> 'application/vnd.stardivision.calc'.\x0a\x09\x09'sdd' -> 'application/vnd.stardivision.impress'.\x0a\x09\x09'sdf' -> 'chemical/x-mdl-sdfile'.\x0a\x09\x09'sdp' -> 'application/vnd.stardivision.impress'.\x0a\x09\x09'sdw' -> 'application/vnd.stardivision.writer'.\x0a\x09\x09'ser' -> 'application/java-serialized-object'.\x0a\x09\x09'sgf' -> 'application/x-go-sgf'.\x0a\x09\x09'sgl' -> 'application/vnd.stardivision.writer-global'.\x0a\x09\x09'sh' -> 'text/x-sh'.\x0a\x09\x09'shar' -> 'application/x-shar'.\x0a\x09\x09'shtml' -> 'text/html'.\x0a\x09\x09'sid' -> 'audio/prs.sid'.\x0a\x09\x09'sik' -> 'application/x-trash'.\x0a\x09\x09'silo' -> 'model/mesh'.\x0a\x09\x09'sis' -> 'application/vnd.symbian.install'.\x0a\x09\x09'sit' -> 'application/x-stuffit'.\x0a\x09\x09'skd' -> 'application/x-koan'.\x0a\x09\x09'skm' -> 'application/x-koan'.\x0a\x09\x09'skp' -> 'application/x-koan'.\x0a\x09\x09'skt' -> 'application/x-koan'.\x0a\x09\x09'smf' -> 'application/vnd.stardivision.math'.\x0a\x09\x09'smi' -> 'application/smil'.\x0a\x09\x09'smil' -> 'application/smil'.\x0a\x09\x09'snd' -> 'audio/basic'.\x0a\x09\x09'spc' -> 'chemical/x-galactic-spc'.\x0a\x09\x09'spl' -> 'application/x-futuresplash'.\x0a\x09\x09'src' -> 'application/x-wais-source'.\x0a\x09\x09'stc' -> 'application/vnd.sun.xml.calc.template'.\x0a\x09\x09'std' -> 'application/vnd.sun.xml.draw.template'.\x0a\x09\x09'sti' -> 'application/vnd.sun.xml.impress.template'.\x0a\x09\x09'stl' -> 'application/vnd.ms-pki.stl'.\x0a\x09\x09'stw' -> 'application/vnd.sun.xml.writer.template'.\x0a\x09\x09'sty' -> 'text/x-tex'.\x0a\x09\x09'sv4cpio' -> 'application/x-sv4cpio'.\x0a\x09\x09'sv4crc' -> 'application/x-sv4crc'.\x0a\x09\x09'svg' -> 'image/svg+xml'.\x0a\x09\x09'svgz' -> 'image/svg+xml'.\x0a\x09\x09'sw' -> 'chemical/x-swissprot'.\x0a\x09\x09'swf' -> 'application/x-shockwave-flash'.\x0a\x09\x09'swfl' -> 'application/x-shockwave-flash'.\x0a\x09\x09'sxc' -> 'application/vnd.sun.xml.calc'.\x0a\x09\x09'sxd' -> 'application/vnd.sun.xml.draw'.\x0a\x09\x09'sxg' -> 'application/vnd.sun.xml.writer.global'.\x0a\x09\x09'sxi' -> 'application/vnd.sun.xml.impress'.\x0a\x09\x09'sxm' -> 'application/vnd.sun.xml.math'.\x0a\x09\x09'sxw' -> 'application/vnd.sun.xml.writer'.\x0a\x09\x09't' -> 'application/x-troff'.\x0a\x09\x09'tar' -> 'application/x-tar'.\x0a\x09\x09'taz' -> 'application/x-gtar'.\x0a\x09\x09'tcl' -> 'text/x-tcl'.\x0a\x09\x09'tex' -> 'text/x-tex'.\x0a\x09\x09'texi' -> 'application/x-texinfo'.\x0a\x09\x09'texinfo' -> 'application/x-texinfo'.\x0a\x09\x09'text' -> 'text/plain'.\x0a\x09\x09'tgf' -> 'chemical/x-mdl-tgf'.\x0a\x09\x09'tgz' -> 'application/x-gtar'.\x0a\x09\x09'tif' -> 'image/tiff'.\x0a\x09\x09'tiff' -> 'image/tiff'.\x0a\x09\x09'tk' -> 'text/x-tcl'.\x0a\x09\x09'tm' -> 'text/texmacs'.\x0a\x09\x09'torrent' -> 'application/x-bittorrent'.\x0a\x09\x09'tr' -> 'application/x-troff'.\x0a\x09\x09'ts' -> 'text/texmacs'.\x0a\x09\x09'tsp' -> 'application/dsptype'.\x0a\x09\x09'tsv' -> 'text/tab-separated-values'.\x0a\x09\x09'txt' -> 'text/plain'.\x0a\x09\x09'udeb' -> 'application/x-debian-package'.\x0a\x09\x09'uls' -> 'text/iuls'.\x0a\x09\x09'ustar' -> 'application/x-ustar'.\x0a\x09\x09'val' -> 'chemical/x-ncbi-asn1-binary'.\x0a\x09\x09'vcd' -> 'application/x-cdlink'.\x0a\x09\x09'vcf' -> 'text/x-vcard'.\x0a\x09\x09'vcs' -> 'text/x-vcalendar'.\x0a\x09\x09'vmd' -> 'chemical/x-vmd'.\x0a\x09\x09'vms' -> 'chemical/x-vamas-iso14976'.\x0a\x09\x09'vor' -> 'application/vnd.stardivision.writer'.\x0a\x09\x09'vrm' -> 'x-world/x-vrml'.\x0a\x09\x09'vrml' -> 'x-world/x-vrml'.\x0a\x09\x09'vsd' -> 'application/vnd.visio'.\x0a\x09\x09'wad' -> 'application/x-doom'.\x0a\x09\x09'wav' -> 'audio/x-wav'.\x0a\x09\x09'wax' -> 'audio/x-ms-wax'.\x0a\x09\x09'wbmp' -> 'image/vnd.wap.wbmp'.\x0a\x09\x09'wbxml' -> 'application/vnd.wap.wbxml'.\x0a\x09\x09'wk' -> 'application/x-123'.\x0a\x09\x09'wm' -> 'video/x-ms-wm'.\x0a\x09\x09'wma' -> 'audio/x-ms-wma'.\x0a\x09\x09'wmd' -> 'application/x-ms-wmd'.\x0a\x09\x09'wml' -> 'text/vnd.wap.wml'.\x0a\x09\x09'wmlc' -> 'application/vnd.wap.wmlc'.\x0a\x09\x09'wmls' -> 'text/vnd.wap.wmlscript'.\x0a\x09\x09'wmlsc' -> 'application/vnd.wap.wmlscriptc'.\x0a\x09\x09'wmv' -> 'video/x-ms-wmv'.\x0a\x09\x09'wmx' -> 'video/x-ms-wmx'.\x0a\x09\x09'wmz' -> 'application/x-ms-wmz'.\x0a\x09\x09'wp5' -> 'application/wordperfect5.1'.\x0a\x09\x09'wpd' -> 'application/wordperfect'.\x0a\x09\x09'wrl' -> 'x-world/x-vrml'.\x0a\x09\x09'wsc' -> 'text/scriptlet'.\x0a\x09\x09'wvx' -> 'video/x-ms-wvx'.\x0a\x09\x09'wz' -> 'application/x-wingz'.\x0a\x09\x09'xbm' -> 'image/x-xbitmap'.\x0a\x09\x09'xcf' -> 'application/x-xcf'.\x0a\x09\x09'xht' -> 'application/xhtml+xml'.\x0a\x09\x09'xhtml' -> 'application/xhtml+xml'.\x0a\x09\x09'xlb' -> 'application/vnd.ms-excel'.\x0a\x09\x09'xls' -> 'application/vnd.ms-excel'.\x0a\x09\x09'xlt' -> 'application/vnd.ms-excel'.\x0a\x09\x09'xml' -> 'application/xml'.\x0a\x09\x09'xpi' -> 'application/x-xpinstall'.\x0a\x09\x09'xpm' -> 'image/x-xpixmap'.\x0a\x09\x09'xsl' -> 'application/xml'.\x0a\x09\x09'xtel' -> 'chemical/x-xtel'.\x0a\x09\x09'xul' -> 'application/vnd.mozilla.xul+xml'.\x0a\x09\x09'xwd' -> 'image/x-xwindowdump'.\x0a\x09\x09'xyz' -> 'chemical/x-xyz'.\x0a\x09\x09'zip' -> 'application/zip'.\x0a\x09\x09'zmt' -> 'chemical/x-mopac-input'.\x0a\x09\x09'~' -> 'application/x-trash'\x0a\x09}",
  924. messageSends: ["->"],
  925. referencedClasses: []
  926. }),
  927. smalltalk.FileServer.klass);
  928. smalltalk.addMethod(
  929. smalltalk.method({
  930. selector: "defaultPort",
  931. category: 'accessing',
  932. fn: function (){
  933. var self=this;
  934. return smalltalk.withContext(function($ctx1) {
  935. var $1;
  936. $1=(4000);
  937. return $1;
  938. }, function($ctx1) {$ctx1.fill(self,"defaultPort",{},smalltalk.FileServer.klass)})},
  939. args: [],
  940. source: "defaultPort\x0a\x09^4000",
  941. messageSends: [],
  942. referencedClasses: []
  943. }),
  944. smalltalk.FileServer.klass);
  945. smalltalk.addMethod(
  946. smalltalk.method({
  947. selector: "main",
  948. category: 'initialization',
  949. fn: function (){
  950. var self=this;
  951. var fileServer,args;
  952. function $FileServer(){return smalltalk.FileServer||(typeof FileServer=="undefined"?nil:FileServer)}
  953. return smalltalk.withContext(function($ctx1) {
  954. var $1,$2;
  955. var $early={};
  956. try {
  957. args=_st(process)._argv();
  958. _st(args)._removeFrom_to_((1),(3));
  959. _st(args)._detect_ifNone_((function(each){
  960. return smalltalk.withContext(function($ctx2) {
  961. $1=_st(each).__eq("--help");
  962. if(smalltalk.assert($1)){
  963. return _st($FileServer())._printHelp();
  964. };
  965. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  966. return smalltalk.withContext(function($ctx2) {
  967. fileServer=_st($FileServer())._createServerWithArguments_(args);
  968. fileServer;
  969. $2=_st(fileServer)._start();
  970. throw $early=[$2];
  971. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  972. return self}
  973. catch(e) {if(e===$early)return e[0]; throw e}
  974. }, function($ctx1) {$ctx1.fill(self,"main",{fileServer:fileServer,args:args},smalltalk.FileServer.klass)})},
  975. args: [],
  976. source: "main\x0a\x09\x22Main entry point for Amber applications.\x0a\x09 Creates and starts a FileServer instance.\x22\x0a\x09| fileServer args |\x0a\x09args := process argv.\x0a\x09\x22Remove the first args which contain the path to the node executable and the script file.\x22\x0a\x09args removeFrom: 1 to: 3.\x0a\x0a\x09args detect: [ :each |\x0a\x09\x09(each = '--help') ifTrue: [FileServer printHelp]]\x0a\x09ifNone: [\x0a\x09\x09fileServer := FileServer createServerWithArguments: args.\x0a\x09\x09^fileServer start]",
  977. messageSends: ["argv", "removeFrom:to:", "detect:ifNone:", "ifTrue:", "printHelp", "=", "createServerWithArguments:", "start"],
  978. referencedClasses: ["FileServer"]
  979. }),
  980. smalltalk.FileServer.klass);
  981. smalltalk.addMethod(
  982. smalltalk.method({
  983. selector: "mimeTypeFor:",
  984. category: 'accessing',
  985. fn: function (aString){
  986. var self=this;
  987. return smalltalk.withContext(function($ctx1) {
  988. var $1;
  989. $1=_st(_st(self)._mimeTypes())._at_ifAbsent_(_st(aString)._replace_with_(".*[\x5c.]",""),(function(){
  990. return smalltalk.withContext(function($ctx2) {
  991. return "text/plain";
  992. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  993. return $1;
  994. }, function($ctx1) {$ctx1.fill(self,"mimeTypeFor:",{aString:aString},smalltalk.FileServer.klass)})},
  995. args: ["aString"],
  996. source: "mimeTypeFor: aString\x0a\x09^self mimeTypes at: (aString replace: '.*[\x5c.]' with: '') ifAbsent: ['text/plain']",
  997. messageSends: ["at:ifAbsent:", "replace:with:", "mimeTypes"],
  998. referencedClasses: []
  999. }),
  1000. smalltalk.FileServer.klass);
  1001. smalltalk.addMethod(
  1002. smalltalk.method({
  1003. selector: "mimeTypes",
  1004. category: 'accessing',
  1005. fn: function (){
  1006. var self=this;
  1007. return smalltalk.withContext(function($ctx1) {
  1008. var $2,$1;
  1009. $2=self["@mimeTypes"];
  1010. if(($receiver = $2) == nil || $receiver == undefined){
  1011. self["@mimeTypes"]=_st(self)._defaultMimeTypes();
  1012. $1=self["@mimeTypes"];
  1013. } else {
  1014. $1=$2;
  1015. };
  1016. return $1;
  1017. }, function($ctx1) {$ctx1.fill(self,"mimeTypes",{},smalltalk.FileServer.klass)})},
  1018. args: [],
  1019. source: "mimeTypes\x0a\x09^mimeTypes ifNil: [mimeTypes := self defaultMimeTypes]",
  1020. messageSends: ["ifNil:", "defaultMimeTypes"],
  1021. referencedClasses: []
  1022. }),
  1023. smalltalk.FileServer.klass);
  1024. smalltalk.addMethod(
  1025. smalltalk.method({
  1026. selector: "printHelp",
  1027. category: 'accessing',
  1028. fn: function (){
  1029. var self=this;
  1030. return smalltalk.withContext(function($ctx1) {
  1031. _st(console)._log_("Available commandline options are:");
  1032. _st(console)._log_("--help");
  1033. _st(_st(self)._commandLineSwitches())._do_((function(each){
  1034. return smalltalk.withContext(function($ctx2) {
  1035. return _st(console)._log_(_st(each).__comma(" <parameter>"));
  1036. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1037. return self}, function($ctx1) {$ctx1.fill(self,"printHelp",{},smalltalk.FileServer.klass)})},
  1038. args: [],
  1039. source: "printHelp\x0a\x09console log: 'Available commandline options are:'.\x0a\x09console log: '--help'.\x0a\x09self commandLineSwitches do: [ :each |\x0a\x09\x09console log: each, ' <parameter>']",
  1040. messageSends: ["log:", "do:", ",", "commandLineSwitches"],
  1041. referencedClasses: []
  1042. }),
  1043. smalltalk.FileServer.klass);
  1044. smalltalk.addMethod(
  1045. smalltalk.method({
  1046. selector: "selectorForCommandLineSwitch:",
  1047. category: 'accessing',
  1048. fn: function (aSwitch){
  1049. var self=this;
  1050. return smalltalk.withContext(function($ctx1) {
  1051. var $1;
  1052. $1=_st(_st(_st(aSwitch)._replace_with_("^--",""))._replace_with_("-[a-z]",(function(each){
  1053. return smalltalk.withContext(function($ctx2) {
  1054. return _st(_st(each)._second())._asUppercase();
  1055. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}))).__comma(":");
  1056. return $1;
  1057. }, function($ctx1) {$ctx1.fill(self,"selectorForCommandLineSwitch:",{aSwitch:aSwitch},smalltalk.FileServer.klass)})},
  1058. args: ["aSwitch"],
  1059. source: "selectorForCommandLineSwitch: aSwitch\x0a\x09\x22Remove the trailing '--', add ':' at the end\x0a\x09 and replace all occurences of a lowercase letter preceded by a '-' with\x0a\x09 the Uppercase letter.\x0a\x09 Example: --fallback-page becomes fallbackPage:\x22\x0a\x09^((aSwitch replace: '^--' with: '')\x0a\x09\x09replace: '-[a-z]' with: [ :each | each second asUppercase ]), ':'",
  1060. messageSends: [",", "replace:with:", "asUppercase", "second"],
  1061. referencedClasses: []
  1062. }),
  1063. smalltalk.FileServer.klass);
  1064. smalltalk.addClass('Repl', smalltalk.Object, ['readline', 'interface', 'util'], 'AmberCli');
  1065. smalltalk.Repl.comment="I am a class representing a REPL (Read Evaluate Print Loop) and provide a command line interface to Amber Smalltalk.\x0aOn the prompt you can type Amber statements which will be evaluated after pressing <Enter>.\x0aThe evaluation is comparable with executing a 'DoIt' in a workspace.\x0a\x0aMy runtime requirement is a functional Node.js executable with working Readline support."
  1066. smalltalk.addMethod(
  1067. smalltalk.method({
  1068. selector: "close",
  1069. category: 'actions',
  1070. fn: function (){
  1071. var self=this;
  1072. return smalltalk.withContext(function($ctx1) {
  1073. _st(_st(process)._stdin())._destroy();
  1074. return self}, function($ctx1) {$ctx1.fill(self,"close",{},smalltalk.Repl)})},
  1075. args: [],
  1076. source: "close\x0a\x09process stdin destroy",
  1077. messageSends: ["destroy", "stdin"],
  1078. referencedClasses: []
  1079. }),
  1080. smalltalk.Repl);
  1081. smalltalk.addMethod(
  1082. smalltalk.method({
  1083. selector: "createInterface",
  1084. category: 'actions',
  1085. fn: function (){
  1086. var self=this;
  1087. return smalltalk.withContext(function($ctx1) {
  1088. self["@interface"]=_st(self["@readline"])._createInterface_stdout_(_st(process)._stdin(),_st(process)._stdout());
  1089. _st(self["@interface"])._on_do_("line",(function(buffer){
  1090. return smalltalk.withContext(function($ctx2) {
  1091. return _st(self)._eval_(buffer);
  1092. }, function($ctx2) {$ctx2.fillBlock({buffer:buffer},$ctx1)})}));
  1093. _st(self["@interface"])._on_do_("close",(function(){
  1094. return smalltalk.withContext(function($ctx2) {
  1095. return _st(self)._close();
  1096. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1097. _st(self)._setPrompt();
  1098. _st(self["@interface"])._prompt();
  1099. return self}, function($ctx1) {$ctx1.fill(self,"createInterface",{},smalltalk.Repl)})},
  1100. args: [],
  1101. source: "createInterface\x0a\x09\x22No completion for now\x22\x0a\x09interface := readline createInterface: process stdin stdout: process stdout.\x0a\x09interface on: 'line' do: [:buffer | self eval: buffer].\x0a\x09interface on: 'close' do: [self close].\x0a\x09self setPrompt.\x0a\x09interface prompt",
  1102. messageSends: ["createInterface:stdout:", "stdin", "stdout", "on:do:", "eval:", "close", "setPrompt", "prompt"],
  1103. referencedClasses: []
  1104. }),
  1105. smalltalk.Repl);
  1106. smalltalk.addMethod(
  1107. smalltalk.method({
  1108. selector: "eval:",
  1109. category: 'actions',
  1110. fn: function (buffer){
  1111. var self=this;
  1112. var result;
  1113. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  1114. function $Transcript(){return smalltalk.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
  1115. function $ErrorHandler(){return smalltalk.ErrorHandler||(typeof ErrorHandler=="undefined"?nil:ErrorHandler)}
  1116. return smalltalk.withContext(function($ctx1) {
  1117. var $1,$2;
  1118. $1=_st(buffer)._isEmpty();
  1119. if(! smalltalk.assert($1)){
  1120. _st(self)._try_catch_((function(){
  1121. return smalltalk.withContext(function($ctx2) {
  1122. result=_st(_st($Compiler())._new())._evaluateExpression_(buffer);
  1123. result;
  1124. return _st($Transcript())._show_(result);
  1125. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),(function(e){
  1126. return smalltalk.withContext(function($ctx2) {
  1127. $2=_st(e)._isSmalltalkError();
  1128. if(smalltalk.assert($2)){
  1129. return _st(_st($ErrorHandler())._new())._handleError_(e);
  1130. } else {
  1131. return _st(_st(process)._stdout())._write_(_st(e)._jsStack());
  1132. };
  1133. }, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1)})}));
  1134. };
  1135. _st(self["@interface"])._prompt();
  1136. return self}, function($ctx1) {$ctx1.fill(self,"eval:",{buffer:buffer,result:result},smalltalk.Repl)})},
  1137. args: ["buffer"],
  1138. source: "eval: buffer\x0a\x09| result |\x0a\x09buffer isEmpty ifFalse: [\x0a\x09\x09self try: [\x0a\x09\x09\x09result := Compiler new evaluateExpression: buffer.\x0a\x09\x09\x09Transcript show: result]\x0a\x09\x09catch: [:e |\x0a\x09\x09\x09e isSmalltalkError\x0a\x09\x09\x09 ifTrue: [ErrorHandler new handleError: e]\x0a\x09\x09\x09 ifFalse: [process stdout write: e jsStack]]].\x0a\x09interface prompt",
  1139. messageSends: ["ifFalse:", "try:catch:", "evaluateExpression:", "new", "show:", "ifTrue:ifFalse:", "handleError:", "write:", "jsStack", "stdout", "isSmalltalkError", "isEmpty", "prompt"],
  1140. referencedClasses: ["Compiler", "Transcript", "ErrorHandler"]
  1141. }),
  1142. smalltalk.Repl);
  1143. smalltalk.addMethod(
  1144. smalltalk.method({
  1145. selector: "initialize",
  1146. category: 'initialization',
  1147. fn: function (){
  1148. var self=this;
  1149. return smalltalk.withContext(function($ctx1) {
  1150. smalltalk.Object.fn.prototype._initialize.apply(_st(self), []);
  1151. self["@readline"]=_st(require)._value_("readline");
  1152. self["@util"]=_st(require)._value_("util");
  1153. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.Repl)})},
  1154. args: [],
  1155. source: "initialize\x0a\x09super initialize.\x0a\x09readline := require value: 'readline'.\x0a\x09util := require value: 'util'",
  1156. messageSends: ["initialize", "value:"],
  1157. referencedClasses: []
  1158. }),
  1159. smalltalk.Repl);
  1160. smalltalk.addMethod(
  1161. smalltalk.method({
  1162. selector: "prompt",
  1163. category: 'accessing',
  1164. fn: function (){
  1165. var self=this;
  1166. return smalltalk.withContext(function($ctx1) {
  1167. return "amber >> ";
  1168. }, function($ctx1) {$ctx1.fill(self,"prompt",{},smalltalk.Repl)})},
  1169. args: [],
  1170. source: "prompt\x0a\x09^'amber >> '",
  1171. messageSends: [],
  1172. referencedClasses: []
  1173. }),
  1174. smalltalk.Repl);
  1175. smalltalk.addMethod(
  1176. smalltalk.method({
  1177. selector: "setPrompt",
  1178. category: 'actions',
  1179. fn: function (){
  1180. var self=this;
  1181. return smalltalk.withContext(function($ctx1) {
  1182. _st(self["@interface"])._setPrompt_(_st(self)._prompt());
  1183. return self}, function($ctx1) {$ctx1.fill(self,"setPrompt",{},smalltalk.Repl)})},
  1184. args: [],
  1185. source: "setPrompt\x0a\x09interface setPrompt: self prompt",
  1186. messageSends: ["setPrompt:", "prompt"],
  1187. referencedClasses: []
  1188. }),
  1189. smalltalk.Repl);
  1190. smalltalk.addMethod(
  1191. smalltalk.method({
  1192. selector: "main",
  1193. category: 'not yet classified',
  1194. fn: function (){
  1195. var self=this;
  1196. return smalltalk.withContext(function($ctx1) {
  1197. _st(_st(self)._new())._createInterface();
  1198. return self}, function($ctx1) {$ctx1.fill(self,"main",{},smalltalk.Repl.klass)})},
  1199. args: [],
  1200. source: "main\x0a\x09self new createInterface",
  1201. messageSends: ["createInterface", "new"],
  1202. referencedClasses: []
  1203. }),
  1204. smalltalk.Repl.klass);