1
0

AmberCli.js 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  1. define("amber_cli/AmberCli", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_core/Kernel-Objects"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('AmberCli');
  3. smalltalk.packages["AmberCli"].transport = {"type":"amd","amdNamespace":"amber_cli"};
  4. smalltalk.addClass('AmberCli', smalltalk.Object, [], 'AmberCli');
  5. 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.";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "commandLineSwitches",
  9. category: 'commandline',
  10. fn: function (){
  11. var self=this;
  12. var switches;
  13. return smalltalk.withContext(function($ctx1) {
  14. var $1;
  15. switches=_st(_st(self._class())._methodsInProtocol_("commands"))._collect_((function(each){
  16. return smalltalk.withContext(function($ctx2) {
  17. return _st(each)._selector();
  18. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  19. switches=_st(switches)._select_((function(each){
  20. return smalltalk.withContext(function($ctx2) {
  21. return _st(each)._match_("^[^:]*:$");
  22. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  23. switches=_st(switches)._collect_((function(each){
  24. return smalltalk.withContext(function($ctx2) {
  25. return _st(_st(_st(each)._allButLast())._replace_with_("([A-Z])","-$1"))._asLowercase();
  26. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  27. $1=switches;
  28. return $1;
  29. }, function($ctx1) {$ctx1.fill(self,"commandLineSwitches",{switches:switches},smalltalk.AmberCli.klass)})},
  30. args: [],
  31. 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",
  32. messageSends: ["collect:", "selector", "methodsInProtocol:", "class", "select:", "match:", "asLowercase", "replace:with:", "allButLast"],
  33. referencedClasses: []
  34. }),
  35. smalltalk.AmberCli.klass);
  36. smalltalk.addMethod(
  37. smalltalk.method({
  38. selector: "handleArguments:",
  39. category: 'commandline',
  40. fn: function (args){
  41. var self=this;
  42. var selector;
  43. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  44. return smalltalk.withContext(function($ctx1) {
  45. selector=self._selectorForCommandLineSwitch_(_st(args)._first());
  46. _st(args)._remove_(_st(args)._first());
  47. self._perform_withArguments_(selector,_st($Array())._with_(args));
  48. return self}, function($ctx1) {$ctx1.fill(self,"handleArguments:",{args:args,selector:selector},smalltalk.AmberCli.klass)})},
  49. args: ["args"],
  50. 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)",
  51. messageSends: ["selectorForCommandLineSwitch:", "first", "remove:", "perform:withArguments:", "with:"],
  52. referencedClasses: ["Array"]
  53. }),
  54. smalltalk.AmberCli.klass);
  55. smalltalk.addMethod(
  56. smalltalk.method({
  57. selector: "help:",
  58. category: 'commands',
  59. fn: function (args){
  60. var self=this;
  61. return smalltalk.withContext(function($ctx1) {
  62. _st(console)._log_("Available Commands:");
  63. _st(self._commandLineSwitches())._do_((function(each){
  64. return smalltalk.withContext(function($ctx2) {
  65. return _st(console)._log_(each);
  66. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  67. return self}, function($ctx1) {$ctx1.fill(self,"help:",{args:args},smalltalk.AmberCli.klass)})},
  68. args: ["args"],
  69. source: "help: args\x0a\x09console log: 'Available Commands:'.\x0a\x09self commandLineSwitches do: [ :each | console log: each ]",
  70. messageSends: ["log:", "do:", "commandLineSwitches"],
  71. referencedClasses: []
  72. }),
  73. smalltalk.AmberCli.klass);
  74. smalltalk.addMethod(
  75. smalltalk.method({
  76. selector: "main",
  77. category: 'startup',
  78. fn: function (){
  79. var self=this;
  80. var args,nodeMinorVersion;
  81. return smalltalk.withContext(function($ctx1) {
  82. var $1,$2,$3;
  83. nodeMinorVersion=_st(_st(_st(_st(process)._version())._tokenize_("."))._second())._asNumber();
  84. $1=_st(nodeMinorVersion).__lt((8));
  85. if(smalltalk.assert($1)){
  86. _st(console)._log_("You are currently using Node.js ".__comma(_st(process)._version()));
  87. _st(console)._log_("Required is at least Node.js v0.8.x or greater.");
  88. return (-1);
  89. };
  90. args=_st(process)._argv();
  91. _st(args)._removeFrom_to_((1),(2));
  92. $2=_st(args)._isEmpty();
  93. if(smalltalk.assert($2)){
  94. self._help_(nil);
  95. } else {
  96. $3=self._handleArguments_(args);
  97. return $3;
  98. };
  99. return self}, function($ctx1) {$ctx1.fill(self,"main",{args:args,nodeMinorVersion:nodeMinorVersion},smalltalk.AmberCli.klass)})},
  100. args: [],
  101. source: "main\x0a\x09\x22Main entry point for Amber applications.\x0a\x09Parses commandline arguments and starts the according subprogram.\x22\x0a\x09| args nodeMinorVersion |\x0a\x0a\x09nodeMinorVersion := ((process version) tokenize: '.') second asNumber.\x0a\x09nodeMinorVersion < 8 ifTrue: [\x0a\x09\x09console log: 'You are currently using Node.js ', (process version).\x0a\x09\x09console log: 'Required is at least Node.js v0.8.x or greater.'.\x0a\x09\x09^ -1.\x0a\x09].\x0a\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: 2.\x0a\x09\x0a\x09(args isEmpty)\x0a\x09\x09ifTrue: [self help: nil]\x0a\x09\x09ifFalse: [^self handleArguments: args]",
  102. messageSends: ["asNumber", "second", "tokenize:", "version", "ifTrue:", "log:", ",", "<", "argv", "removeFrom:to:", "ifTrue:ifFalse:", "help:", "handleArguments:", "isEmpty"],
  103. referencedClasses: []
  104. }),
  105. smalltalk.AmberCli.klass);
  106. smalltalk.addMethod(
  107. smalltalk.method({
  108. selector: "repl:",
  109. category: 'commands',
  110. fn: function (args){
  111. var self=this;
  112. function $Repl(){return smalltalk.Repl||(typeof Repl=="undefined"?nil:Repl)}
  113. return smalltalk.withContext(function($ctx1) {
  114. var $1;
  115. $1=_st(_st($Repl())._new())._createInterface();
  116. return $1;
  117. }, function($ctx1) {$ctx1.fill(self,"repl:",{args:args},smalltalk.AmberCli.klass)})},
  118. args: ["args"],
  119. source: "repl: args\x0a\x09^Repl new createInterface",
  120. messageSends: ["createInterface", "new"],
  121. referencedClasses: ["Repl"]
  122. }),
  123. smalltalk.AmberCli.klass);
  124. smalltalk.addMethod(
  125. smalltalk.method({
  126. selector: "selectorForCommandLineSwitch:",
  127. category: 'commandline',
  128. fn: function (aSwitch){
  129. var self=this;
  130. var command,selector;
  131. return smalltalk.withContext(function($ctx1) {
  132. var $1,$2;
  133. $1=_st(self._commandLineSwitches())._includes_(aSwitch);
  134. if(smalltalk.assert($1)){
  135. selector=_st(_st(aSwitch)._replace_with_("-[a-z]",(function(each){
  136. return smalltalk.withContext(function($ctx2) {
  137. return _st(_st(each)._second())._asUppercase();
  138. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}))).__comma(":");
  139. selector;
  140. } else {
  141. selector="help:";
  142. selector;
  143. };
  144. $2=selector;
  145. return $2;
  146. }, function($ctx1) {$ctx1.fill(self,"selectorForCommandLineSwitch:",{aSwitch:aSwitch,command:command,selector:selector},smalltalk.AmberCli.klass)})},
  147. args: ["aSwitch"],
  148. 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",
  149. messageSends: ["ifTrue:ifFalse:", ",", "replace:with:", "asUppercase", "second", "includes:", "commandLineSwitches"],
  150. referencedClasses: []
  151. }),
  152. smalltalk.AmberCli.klass);
  153. smalltalk.addMethod(
  154. smalltalk.method({
  155. selector: "serve:",
  156. category: 'commands',
  157. fn: function (args){
  158. var self=this;
  159. function $FileServer(){return smalltalk.FileServer||(typeof FileServer=="undefined"?nil:FileServer)}
  160. return smalltalk.withContext(function($ctx1) {
  161. var $1;
  162. $1=_st(_st($FileServer())._createServerWithArguments_(args))._start();
  163. return $1;
  164. }, function($ctx1) {$ctx1.fill(self,"serve:",{args:args},smalltalk.AmberCli.klass)})},
  165. args: ["args"],
  166. source: "serve: args\x0a\x09^(FileServer createServerWithArguments: args) start",
  167. messageSends: ["start", "createServerWithArguments:"],
  168. referencedClasses: ["FileServer"]
  169. }),
  170. smalltalk.AmberCli.klass);
  171. smalltalk.addClass('FileServer', smalltalk.Object, ['path', 'http', 'fs', 'url', 'host', 'port', 'basePath', 'util', 'username', 'password', 'fallbackPage'], 'AmberCli');
  172. 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.";
  173. smalltalk.addMethod(
  174. smalltalk.method({
  175. selector: "base64Decode:",
  176. category: 'private',
  177. fn: function (aString){
  178. var self=this;
  179. return smalltalk.withContext(function($ctx1) {
  180. return (new Buffer(aString, 'base64').toString());
  181. return self}, function($ctx1) {$ctx1.fill(self,"base64Decode:",{aString:aString},smalltalk.FileServer)})},
  182. args: ["aString"],
  183. source: "base64Decode: aString\x0a\x09<return (new Buffer(aString, 'base64').toString())>",
  184. messageSends: [],
  185. referencedClasses: []
  186. }),
  187. smalltalk.FileServer);
  188. smalltalk.addMethod(
  189. smalltalk.method({
  190. selector: "basePath",
  191. category: 'accessing',
  192. fn: function (){
  193. var self=this;
  194. return smalltalk.withContext(function($ctx1) {
  195. var $2,$1;
  196. $2=self["@basePath"];
  197. if(($receiver = $2) == nil || $receiver == undefined){
  198. $1="./";
  199. } else {
  200. $1=$2;
  201. };
  202. return $1;
  203. }, function($ctx1) {$ctx1.fill(self,"basePath",{},smalltalk.FileServer)})},
  204. args: [],
  205. source: "basePath\x0a\x09^basePath ifNil: ['./']",
  206. messageSends: ["ifNil:"],
  207. referencedClasses: []
  208. }),
  209. smalltalk.FileServer);
  210. smalltalk.addMethod(
  211. smalltalk.method({
  212. selector: "basePath:",
  213. category: 'accessing',
  214. fn: function (aString){
  215. var self=this;
  216. return smalltalk.withContext(function($ctx1) {
  217. self["@basePath"]=aString;
  218. return self}, function($ctx1) {$ctx1.fill(self,"basePath:",{aString:aString},smalltalk.FileServer)})},
  219. args: ["aString"],
  220. source: "basePath: aString\x0a\x09basePath := aString",
  221. messageSends: [],
  222. referencedClasses: []
  223. }),
  224. smalltalk.FileServer);
  225. smalltalk.addMethod(
  226. smalltalk.method({
  227. selector: "checkDirectoryLayout",
  228. category: 'initialization',
  229. fn: function (){
  230. var self=this;
  231. return smalltalk.withContext(function($ctx1) {
  232. var $1,$2,$3;
  233. $1=_st(self["@fs"])._existsSync_(_st(self._basePath()).__comma("index.html"));
  234. if(! smalltalk.assert($1)){
  235. _st(console)._warn_("Warning: project directory does not contain index.html");
  236. };
  237. $2=_st(self["@fs"])._existsSync_(_st(self._basePath()).__comma("st"));
  238. if(! smalltalk.assert($2)){
  239. _st(console)._warn_("Warning: project directory is missing an \x22st\x22 directory");
  240. };
  241. $3=_st(self["@fs"])._existsSync_(_st(self._basePath()).__comma("js"));
  242. if(! smalltalk.assert($3)){
  243. _st(console)._warn_("Warning: project directory is missing a \x22js\x22 directory");
  244. };
  245. return self}, function($ctx1) {$ctx1.fill(self,"checkDirectoryLayout",{},smalltalk.FileServer)})},
  246. args: [],
  247. 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'].",
  248. messageSends: ["ifFalse:", "warn:", "existsSync:", ",", "basePath"],
  249. referencedClasses: []
  250. }),
  251. smalltalk.FileServer);
  252. smalltalk.addMethod(
  253. smalltalk.method({
  254. selector: "fallbackPage",
  255. category: 'accessing',
  256. fn: function (){
  257. var self=this;
  258. return smalltalk.withContext(function($ctx1) {
  259. var $1;
  260. $1=self["@fallbackPage"];
  261. return $1;
  262. }, function($ctx1) {$ctx1.fill(self,"fallbackPage",{},smalltalk.FileServer)})},
  263. args: [],
  264. source: "fallbackPage\x0a\x09^fallbackPage",
  265. messageSends: [],
  266. referencedClasses: []
  267. }),
  268. smalltalk.FileServer);
  269. smalltalk.addMethod(
  270. smalltalk.method({
  271. selector: "fallbackPage:",
  272. category: 'accessing',
  273. fn: function (aString){
  274. var self=this;
  275. return smalltalk.withContext(function($ctx1) {
  276. self["@fallbackPage"]=aString;
  277. return self}, function($ctx1) {$ctx1.fill(self,"fallbackPage:",{aString:aString},smalltalk.FileServer)})},
  278. args: ["aString"],
  279. source: "fallbackPage: aString\x0a\x09fallbackPage := aString",
  280. messageSends: [],
  281. referencedClasses: []
  282. }),
  283. smalltalk.FileServer);
  284. smalltalk.addMethod(
  285. smalltalk.method({
  286. selector: "handleGETRequest:respondTo:",
  287. category: 'request handling',
  288. fn: function (aRequest,aResponse){
  289. var self=this;
  290. var uri,filename;
  291. return smalltalk.withContext(function($ctx1) {
  292. var $1;
  293. uri=_st(_st(self["@url"])._parse_(_st(aRequest)._url()))._pathname();
  294. filename=_st(self["@path"])._join_with_(self._basePath(),uri);
  295. _st(self["@fs"])._exists_do_(filename,(function(aBoolean){
  296. return smalltalk.withContext(function($ctx2) {
  297. $1=aBoolean;
  298. if(smalltalk.assert($1)){
  299. return self._respondFileNamed_to_(filename,aResponse);
  300. } else {
  301. return self._respondNotFoundTo_(aResponse);
  302. };
  303. }, function($ctx2) {$ctx2.fillBlock({aBoolean:aBoolean},$ctx1)})}));
  304. return self}, function($ctx1) {$ctx1.fill(self,"handleGETRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse,uri:uri,filename:filename},smalltalk.FileServer)})},
  305. args: ["aRequest", "aResponse"],
  306. 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]]",
  307. messageSends: ["pathname", "parse:", "url", "join:with:", "basePath", "exists:do:", "ifFalse:ifTrue:", "respondNotFoundTo:", "respondFileNamed:to:"],
  308. referencedClasses: []
  309. }),
  310. smalltalk.FileServer);
  311. smalltalk.addMethod(
  312. smalltalk.method({
  313. selector: "handleOPTIONSRequest:respondTo:",
  314. category: 'request handling',
  315. fn: function (aRequest,aResponse){
  316. var self=this;
  317. return smalltalk.withContext(function($ctx1) {
  318. _st(aResponse)._writeHead_options_((200),smalltalk.HashedCollection._from_(["Access-Control-Allow-Origin".__minus_gt("*"),"Access-Control-Allow-Methods".__minus_gt("GET, PUT, POST, DELETE, OPTIONS"),"Access-Control-Allow-Headers".__minus_gt("Content-Type, Accept"),"Content-Length".__minus_gt((0)),"Access-Control-Max-Age".__minus_gt((10))]));
  319. _st(aResponse)._end();
  320. return self}, function($ctx1) {$ctx1.fill(self,"handleOPTIONSRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse},smalltalk.FileServer)})},
  321. args: ["aRequest", "aResponse"],
  322. 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",
  323. messageSends: ["writeHead:options:", "->", "end"],
  324. referencedClasses: []
  325. }),
  326. smalltalk.FileServer);
  327. smalltalk.addMethod(
  328. smalltalk.method({
  329. selector: "handlePUTRequest:respondTo:",
  330. category: 'request handling',
  331. fn: function (aRequest,aResponse){
  332. var self=this;
  333. var file,stream;
  334. return smalltalk.withContext(function($ctx1) {
  335. var $1,$2;
  336. $1=self._isAuthenticated_(aRequest);
  337. if(! smalltalk.assert($1)){
  338. self._respondAuthenticationRequiredTo_(aResponse);
  339. return nil;
  340. };
  341. file=".".__comma(_st(aRequest)._url());
  342. stream=_st(self["@fs"])._createWriteStream_(file);
  343. _st(stream)._on_do_("error",(function(error){
  344. return smalltalk.withContext(function($ctx2) {
  345. _st(console)._warn_("Error creating WriteStream for file ".__comma(file));
  346. _st(console)._warn_(" Did you forget to create the necessary js/ or st/ directory in your project?");
  347. _st(console)._warn_(" The exact error is: ".__comma(error));
  348. return self._respondNotCreatedTo_(aResponse);
  349. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1)})}));
  350. _st(stream)._on_do_("close",(function(){
  351. return smalltalk.withContext(function($ctx2) {
  352. return self._respondCreatedTo_(aResponse);
  353. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  354. _st(aRequest)._setEncoding_("utf8");
  355. _st(aRequest)._on_do_("data",(function(data){
  356. return smalltalk.withContext(function($ctx2) {
  357. return _st(stream)._write_(data);
  358. }, function($ctx2) {$ctx2.fillBlock({data:data},$ctx1)})}));
  359. _st(aRequest)._on_do_("end",(function(){
  360. return smalltalk.withContext(function($ctx2) {
  361. $2=_st(stream)._writable();
  362. if(smalltalk.assert($2)){
  363. return _st(stream)._end();
  364. };
  365. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  366. return self}, function($ctx1) {$ctx1.fill(self,"handlePUTRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse,file:file,stream:stream},smalltalk.FileServer)})},
  367. args: ["aRequest", "aResponse"],
  368. 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]]",
  369. messageSends: ["ifFalse:", "respondAuthenticationRequiredTo:", "isAuthenticated:", ",", "url", "createWriteStream:", "on:do:", "warn:", "respondNotCreatedTo:", "respondCreatedTo:", "setEncoding:", "write:", "ifTrue:", "end", "writable"],
  370. referencedClasses: []
  371. }),
  372. smalltalk.FileServer);
  373. smalltalk.addMethod(
  374. smalltalk.method({
  375. selector: "handleRequest:respondTo:",
  376. category: 'request handling',
  377. fn: function (aRequest,aResponse){
  378. var self=this;
  379. return smalltalk.withContext(function($ctx1) {
  380. var $1,$2,$3;
  381. $1=_st(_st(aRequest)._method()).__eq("PUT");
  382. if(smalltalk.assert($1)){
  383. self._handlePUTRequest_respondTo_(aRequest,aResponse);
  384. };
  385. $2=_st(_st(aRequest)._method()).__eq("GET");
  386. if(smalltalk.assert($2)){
  387. self._handleGETRequest_respondTo_(aRequest,aResponse);
  388. };
  389. $3=_st(_st(aRequest)._method()).__eq("OPTIONS");
  390. if(smalltalk.assert($3)){
  391. self._handleOPTIONSRequest_respondTo_(aRequest,aResponse);
  392. };
  393. return self}, function($ctx1) {$ctx1.fill(self,"handleRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse},smalltalk.FileServer)})},
  394. args: ["aRequest", "aResponse"],
  395. 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]",
  396. messageSends: ["ifTrue:", "handlePUTRequest:respondTo:", "=", "method", "handleGETRequest:respondTo:", "handleOPTIONSRequest:respondTo:"],
  397. referencedClasses: []
  398. }),
  399. smalltalk.FileServer);
  400. smalltalk.addMethod(
  401. smalltalk.method({
  402. selector: "host",
  403. category: 'accessing',
  404. fn: function (){
  405. var self=this;
  406. return smalltalk.withContext(function($ctx1) {
  407. var $1;
  408. $1=self["@host"];
  409. return $1;
  410. }, function($ctx1) {$ctx1.fill(self,"host",{},smalltalk.FileServer)})},
  411. args: [],
  412. source: "host\x0a\x09^host",
  413. messageSends: [],
  414. referencedClasses: []
  415. }),
  416. smalltalk.FileServer);
  417. smalltalk.addMethod(
  418. smalltalk.method({
  419. selector: "host:",
  420. category: 'accessing',
  421. fn: function (hostname){
  422. var self=this;
  423. return smalltalk.withContext(function($ctx1) {
  424. self["@host"]=hostname;
  425. return self}, function($ctx1) {$ctx1.fill(self,"host:",{hostname:hostname},smalltalk.FileServer)})},
  426. args: ["hostname"],
  427. source: "host: hostname\x0a\x09host := hostname",
  428. messageSends: [],
  429. referencedClasses: []
  430. }),
  431. smalltalk.FileServer);
  432. smalltalk.addMethod(
  433. smalltalk.method({
  434. selector: "initialize",
  435. category: 'initialization',
  436. fn: function (){
  437. var self=this;
  438. return smalltalk.withContext(function($ctx1) {
  439. smalltalk.FileServer.superclass.fn.prototype._initialize.apply(_st(self), []);
  440. self["@path"]=self._require_("path");
  441. self["@http"]=self._require_("http");
  442. self["@fs"]=self._require_("fs");
  443. self["@util"]=self._require_("util");
  444. self["@url"]=self._require_("url");
  445. self["@host"]=_st(self._class())._defaultHost();
  446. self["@port"]=_st(self._class())._defaultPort();
  447. self["@username"]=nil;
  448. self["@password"]=nil;
  449. self["@fallbackPage"]=nil;
  450. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.FileServer)})},
  451. args: [],
  452. 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.",
  453. messageSends: ["initialize", "require:", "defaultHost", "class", "defaultPort"],
  454. referencedClasses: []
  455. }),
  456. smalltalk.FileServer);
  457. smalltalk.addMethod(
  458. smalltalk.method({
  459. selector: "isAuthenticated:",
  460. category: 'private',
  461. fn: function (aRequest){
  462. var self=this;
  463. var header,token,auth,parts;
  464. return smalltalk.withContext(function($ctx1) {
  465. var $1,$2,$3,$4,$5;
  466. $1=_st(_st(self["@username"])._isNil())._and_((function(){
  467. return smalltalk.withContext(function($ctx2) {
  468. return _st(self["@password"])._isNil();
  469. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  470. if(smalltalk.assert($1)){
  471. return true;
  472. };
  473. $2=_st(_st(aRequest)._headers())._at_("authorization");
  474. if(($receiver = $2) == nil || $receiver == undefined){
  475. header="";
  476. } else {
  477. header=$2;
  478. };
  479. $3=_st(header)._isEmpty();
  480. if(smalltalk.assert($3)){
  481. return false;
  482. } else {
  483. $4=_st(header)._tokenize_(" ");
  484. if(($receiver = $4) == nil || $receiver == undefined){
  485. token="";
  486. } else {
  487. token=$4;
  488. };
  489. token;
  490. auth=self._base64Decode_(_st(token)._at_((2)));
  491. auth;
  492. parts=_st(auth)._tokenize_(":");
  493. parts;
  494. $5=_st(_st(self["@username"]).__eq(_st(parts)._at_((1))))._and_((function(){
  495. return smalltalk.withContext(function($ctx2) {
  496. return _st(self["@password"]).__eq(_st(parts)._at_((2)));
  497. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  498. if(smalltalk.assert($5)){
  499. return true;
  500. } else {
  501. return false;
  502. };
  503. };
  504. return self}, function($ctx1) {$ctx1.fill(self,"isAuthenticated:",{aRequest:aRequest,header:header,token:token,auth:auth,parts:parts},smalltalk.FileServer)})},
  505. args: ["aRequest"],
  506. 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].",
  507. messageSends: ["ifTrue:", "and:", "isNil", "ifNil:", "at:", "headers", "ifTrue:ifFalse:", "tokenize:", "base64Decode:", "=", "isEmpty"],
  508. referencedClasses: []
  509. }),
  510. smalltalk.FileServer);
  511. smalltalk.addMethod(
  512. smalltalk.method({
  513. selector: "password:",
  514. category: 'accessing',
  515. fn: function (aPassword){
  516. var self=this;
  517. return smalltalk.withContext(function($ctx1) {
  518. self["@password"]=aPassword;
  519. return self}, function($ctx1) {$ctx1.fill(self,"password:",{aPassword:aPassword},smalltalk.FileServer)})},
  520. args: ["aPassword"],
  521. source: "password: aPassword\x0a\x09password := aPassword.",
  522. messageSends: [],
  523. referencedClasses: []
  524. }),
  525. smalltalk.FileServer);
  526. smalltalk.addMethod(
  527. smalltalk.method({
  528. selector: "port",
  529. category: 'accessing',
  530. fn: function (){
  531. var self=this;
  532. return smalltalk.withContext(function($ctx1) {
  533. var $1;
  534. $1=self["@port"];
  535. return $1;
  536. }, function($ctx1) {$ctx1.fill(self,"port",{},smalltalk.FileServer)})},
  537. args: [],
  538. source: "port\x0a\x09^port",
  539. messageSends: [],
  540. referencedClasses: []
  541. }),
  542. smalltalk.FileServer);
  543. smalltalk.addMethod(
  544. smalltalk.method({
  545. selector: "port:",
  546. category: 'accessing',
  547. fn: function (aNumber){
  548. var self=this;
  549. return smalltalk.withContext(function($ctx1) {
  550. self["@port"]=aNumber;
  551. return self}, function($ctx1) {$ctx1.fill(self,"port:",{aNumber:aNumber},smalltalk.FileServer)})},
  552. args: ["aNumber"],
  553. source: "port: aNumber\x0a\x09port := aNumber",
  554. messageSends: [],
  555. referencedClasses: []
  556. }),
  557. smalltalk.FileServer);
  558. smalltalk.addMethod(
  559. smalltalk.method({
  560. selector: "require:",
  561. category: 'private',
  562. fn: function (aModuleString){
  563. var self=this;
  564. return smalltalk.withContext(function($ctx1) {
  565. var $1;
  566. $1=_st(require)._value_(aModuleString);
  567. return $1;
  568. }, function($ctx1) {$ctx1.fill(self,"require:",{aModuleString:aModuleString},smalltalk.FileServer)})},
  569. args: ["aModuleString"],
  570. source: "require: aModuleString\x0a\x09\x22call to the require function\x22\x0a\x09^require value: aModuleString",
  571. messageSends: ["value:"],
  572. referencedClasses: []
  573. }),
  574. smalltalk.FileServer);
  575. smalltalk.addMethod(
  576. smalltalk.method({
  577. selector: "respondAuthenticationRequiredTo:",
  578. category: 'request handling',
  579. fn: function (aResponse){
  580. var self=this;
  581. return smalltalk.withContext(function($ctx1) {
  582. var $1,$2;
  583. $1=aResponse;
  584. _st($1)._writeHead_options_((401),smalltalk.HashedCollection._from_(["WWW-Authenticate".__minus_gt("Basic realm=\x22Secured Developer Area\x22")]));
  585. _st($1)._write_("<html><body>Authentication needed</body></html>");
  586. $2=_st($1)._end();
  587. return self}, function($ctx1) {$ctx1.fill(self,"respondAuthenticationRequiredTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  588. args: ["aResponse"],
  589. 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.",
  590. messageSends: ["writeHead:options:", "->", "write:", "end"],
  591. referencedClasses: []
  592. }),
  593. smalltalk.FileServer);
  594. smalltalk.addMethod(
  595. smalltalk.method({
  596. selector: "respondCreatedTo:",
  597. category: 'request handling',
  598. fn: function (aResponse){
  599. var self=this;
  600. return smalltalk.withContext(function($ctx1) {
  601. var $1,$2;
  602. $1=aResponse;
  603. _st($1)._writeHead_options_((201),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain"),"Access-Control-Allow-Origin".__minus_gt("*")]));
  604. $2=_st($1)._end();
  605. return self}, function($ctx1) {$ctx1.fill(self,"respondCreatedTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  606. args: ["aResponse"],
  607. source: "respondCreatedTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 201 options: #{'Content-Type' -> 'text/plain'. 'Access-Control-Allow-Origin' -> '*'};\x0a\x09\x09end.",
  608. messageSends: ["writeHead:options:", "->", "end"],
  609. referencedClasses: []
  610. }),
  611. smalltalk.FileServer);
  612. smalltalk.addMethod(
  613. smalltalk.method({
  614. selector: "respondFileNamed:to:",
  615. category: 'request handling',
  616. fn: function (aFilename,aResponse){
  617. var self=this;
  618. var type,filename;
  619. return smalltalk.withContext(function($ctx1) {
  620. var $1,$2,$3,$4,$5;
  621. filename=aFilename;
  622. $1=_st(_st(self["@fs"])._statSync_(aFilename))._isDirectory();
  623. if(smalltalk.assert($1)){
  624. filename=_st(filename).__comma("index.html");
  625. filename;
  626. };
  627. _st(self["@fs"])._readFile_do_(filename,(function(ex,file){
  628. return smalltalk.withContext(function($ctx2) {
  629. $2=_st(ex)._notNil();
  630. if(smalltalk.assert($2)){
  631. _st(console)._log_(_st(filename).__comma(" does not exist"));
  632. return self._respondInternalErrorTo_(aResponse);
  633. } else {
  634. type=_st(self._class())._mimeTypeFor_(filename);
  635. type;
  636. $3=_st(type).__eq("application/javascript");
  637. if(smalltalk.assert($3)){
  638. type=_st(type).__comma(";charset=utf-8");
  639. type;
  640. };
  641. $4=aResponse;
  642. _st($4)._writeHead_options_((200),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt(type)]));
  643. _st($4)._write_encoding_(file,"binary");
  644. $5=_st($4)._end();
  645. return $5;
  646. };
  647. }, function($ctx2) {$ctx2.fillBlock({ex:ex,file:file},$ctx1)})}));
  648. return self}, function($ctx1) {$ctx1.fill(self,"respondFileNamed:to:",{aFilename:aFilename,aResponse:aResponse,type:type,filename:filename},smalltalk.FileServer)})},
  649. args: ["aFilename", "aResponse"],
  650. 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]]",
  651. messageSends: ["ifTrue:", ",", "isDirectory", "statSync:", "readFile:do:", "ifTrue:ifFalse:", "log:", "respondInternalErrorTo:", "mimeTypeFor:", "class", "=", "writeHead:options:", "->", "write:encoding:", "end", "notNil"],
  652. referencedClasses: []
  653. }),
  654. smalltalk.FileServer);
  655. smalltalk.addMethod(
  656. smalltalk.method({
  657. selector: "respondInternalErrorTo:",
  658. category: 'request handling',
  659. fn: function (aResponse){
  660. var self=this;
  661. return smalltalk.withContext(function($ctx1) {
  662. var $1,$2;
  663. $1=aResponse;
  664. _st($1)._writeHead_options_((500),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain")]));
  665. _st($1)._write_("500 Internal server error");
  666. $2=_st($1)._end();
  667. return self}, function($ctx1) {$ctx1.fill(self,"respondInternalErrorTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  668. args: ["aResponse"],
  669. source: "respondInternalErrorTo: aResponse\x0a\x09aResponse \x0a\x09\x09writeHead: 500 options: #{'Content-Type' -> 'text/plain'};\x0a\x09\x09write: '500 Internal server error';\x0a\x09\x09end",
  670. messageSends: ["writeHead:options:", "->", "write:", "end"],
  671. referencedClasses: []
  672. }),
  673. smalltalk.FileServer);
  674. smalltalk.addMethod(
  675. smalltalk.method({
  676. selector: "respondNotCreatedTo:",
  677. category: 'request handling',
  678. fn: function (aResponse){
  679. var self=this;
  680. return smalltalk.withContext(function($ctx1) {
  681. var $1,$2;
  682. $1=aResponse;
  683. _st($1)._writeHead_options_((400),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain")]));
  684. _st($1)._write_("File could not be created. Did you forget to create the st/js directories on the server?");
  685. $2=_st($1)._end();
  686. return self}, function($ctx1) {$ctx1.fill(self,"respondNotCreatedTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  687. args: ["aResponse"],
  688. 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.",
  689. messageSends: ["writeHead:options:", "->", "write:", "end"],
  690. referencedClasses: []
  691. }),
  692. smalltalk.FileServer);
  693. smalltalk.addMethod(
  694. smalltalk.method({
  695. selector: "respondNotFoundTo:",
  696. category: 'request handling',
  697. fn: function (aResponse){
  698. var self=this;
  699. return smalltalk.withContext(function($ctx1) {
  700. var $1,$2,$3,$4;
  701. $1=_st(self._fallbackPage())._isNil();
  702. if(! smalltalk.assert($1)){
  703. $2=self._respondFileNamed_to_(self._fallbackPage(),aResponse);
  704. return $2;
  705. };
  706. $3=aResponse;
  707. _st($3)._writeHead_options_((404),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain")]));
  708. _st($3)._write_("404 Not found");
  709. $4=_st($3)._end();
  710. return self}, function($ctx1) {$ctx1.fill(self,"respondNotFoundTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  711. args: ["aResponse"],
  712. 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",
  713. messageSends: ["ifFalse:", "respondFileNamed:to:", "fallbackPage", "isNil", "writeHead:options:", "->", "write:", "end"],
  714. referencedClasses: []
  715. }),
  716. smalltalk.FileServer);
  717. smalltalk.addMethod(
  718. smalltalk.method({
  719. selector: "respondOKTo:",
  720. category: 'request handling',
  721. fn: function (aResponse){
  722. var self=this;
  723. return smalltalk.withContext(function($ctx1) {
  724. var $1,$2;
  725. $1=aResponse;
  726. _st($1)._writeHead_options_((200),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain"),"Access-Control-Allow-Origin".__minus_gt("*")]));
  727. $2=_st($1)._end();
  728. return self}, function($ctx1) {$ctx1.fill(self,"respondOKTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  729. args: ["aResponse"],
  730. source: "respondOKTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 200 options: #{'Content-Type' -> 'text/plain'. 'Access-Control-Allow-Origin' -> '*'};\x0a\x09\x09end.",
  731. messageSends: ["writeHead:options:", "->", "end"],
  732. referencedClasses: []
  733. }),
  734. smalltalk.FileServer);
  735. smalltalk.addMethod(
  736. smalltalk.method({
  737. selector: "start",
  738. category: 'starting',
  739. fn: function (){
  740. var self=this;
  741. return smalltalk.withContext(function($ctx1) {
  742. var $1,$2;
  743. self._checkDirectoryLayout();
  744. $1=_st(self["@http"])._createServer_((function(request,response){
  745. return smalltalk.withContext(function($ctx2) {
  746. return self._handleRequest_respondTo_(request,response);
  747. }, function($ctx2) {$ctx2.fillBlock({request:request,response:response},$ctx1)})}));
  748. _st($1)._on_do_("error",(function(error){
  749. return smalltalk.withContext(function($ctx2) {
  750. return _st(console)._log_("Error starting server: ".__comma(error));
  751. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1)})}));
  752. _st($1)._on_do_("listening",(function(){
  753. return smalltalk.withContext(function($ctx2) {
  754. return _st(console)._log_(_st(_st("Starting file server on http://".__comma(self._host())).__comma(":")).__comma(_st(self._port())._asString()));
  755. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  756. $2=_st($1)._listen_host_(self._port(),self._host());
  757. return self}, function($ctx1) {$ctx1.fill(self,"start",{},smalltalk.FileServer)})},
  758. args: [],
  759. 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 http://', self host, ':', self port asString];\x0a\x09 listen: self port host: self host.",
  760. messageSends: ["checkDirectoryLayout", "on:do:", "log:", ",", "createServer:", "handleRequest:respondTo:", "asString", "port", "host", "listen:host:"],
  761. referencedClasses: []
  762. }),
  763. smalltalk.FileServer);
  764. smalltalk.addMethod(
  765. smalltalk.method({
  766. selector: "startOn:",
  767. category: 'starting',
  768. fn: function (aPort){
  769. var self=this;
  770. return smalltalk.withContext(function($ctx1) {
  771. self._port_(aPort);
  772. self._start();
  773. return self}, function($ctx1) {$ctx1.fill(self,"startOn:",{aPort:aPort},smalltalk.FileServer)})},
  774. args: ["aPort"],
  775. source: "startOn: aPort\x0a\x09self port: aPort.\x0a\x09self start",
  776. messageSends: ["port:", "start"],
  777. referencedClasses: []
  778. }),
  779. smalltalk.FileServer);
  780. smalltalk.addMethod(
  781. smalltalk.method({
  782. selector: "username:",
  783. category: 'accessing',
  784. fn: function (aUsername){
  785. var self=this;
  786. return smalltalk.withContext(function($ctx1) {
  787. self["@username"]=aUsername;
  788. return self}, function($ctx1) {$ctx1.fill(self,"username:",{aUsername:aUsername},smalltalk.FileServer)})},
  789. args: ["aUsername"],
  790. source: "username: aUsername\x0a\x09username := aUsername.",
  791. messageSends: [],
  792. referencedClasses: []
  793. }),
  794. smalltalk.FileServer);
  795. smalltalk.addMethod(
  796. smalltalk.method({
  797. selector: "writeData:toFileNamed:",
  798. category: 'private',
  799. fn: function (data,aFilename){
  800. var self=this;
  801. return smalltalk.withContext(function($ctx1) {
  802. _st(console)._log_(aFilename);
  803. return self}, function($ctx1) {$ctx1.fill(self,"writeData:toFileNamed:",{data:data,aFilename:aFilename},smalltalk.FileServer)})},
  804. args: ["data", "aFilename"],
  805. source: "writeData: data toFileNamed: aFilename\x0a\x09console log: aFilename",
  806. messageSends: ["log:"],
  807. referencedClasses: []
  808. }),
  809. smalltalk.FileServer);
  810. smalltalk.FileServer.klass.iVarNames = ['mimeTypes'];
  811. smalltalk.addMethod(
  812. smalltalk.method({
  813. selector: "commandLineSwitches",
  814. category: 'accessing',
  815. fn: function (){
  816. var self=this;
  817. var switches;
  818. return smalltalk.withContext(function($ctx1) {
  819. var $1;
  820. switches=_st(self._methodsInProtocol_("accessing"))._collect_((function(each){
  821. return smalltalk.withContext(function($ctx2) {
  822. return _st(each)._selector();
  823. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  824. switches=_st(switches)._select_((function(each){
  825. return smalltalk.withContext(function($ctx2) {
  826. return _st(each)._match_("^[^:]*:$");
  827. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  828. switches=_st(switches)._collect_((function(each){
  829. return smalltalk.withContext(function($ctx2) {
  830. return _st(_st(_st(_st(each)._allButLast())._replace_with_("([A-Z])","-$1"))._asLowercase())._replace_with_("^([a-z])","--$1");
  831. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  832. $1=switches;
  833. return $1;
  834. }, function($ctx1) {$ctx1.fill(self,"commandLineSwitches",{switches:switches},smalltalk.FileServer.klass)})},
  835. args: [],
  836. 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",
  837. messageSends: ["collect:", "selector", "methodsInProtocol:", "select:", "match:", "replace:with:", "asLowercase", "allButLast"],
  838. referencedClasses: []
  839. }),
  840. smalltalk.FileServer.klass);
  841. smalltalk.addMethod(
  842. smalltalk.method({
  843. selector: "createServerWithArguments:",
  844. category: 'initialization',
  845. fn: function (options){
  846. var self=this;
  847. var server,popFront,front,optionName,optionValue,switches;
  848. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  849. return smalltalk.withContext(function($ctx1) {
  850. var $1,$2,$3,$4,$5;
  851. var $early={};
  852. try {
  853. switches=self._commandLineSwitches();
  854. server=self._new();
  855. _st(options)._ifEmpty_((function(){
  856. return smalltalk.withContext(function($ctx2) {
  857. $1=server;
  858. throw $early=[$1];
  859. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  860. $2=_st(_st(options)._size())._even();
  861. if(! smalltalk.assert($2)){
  862. _st(console)._log_("Using default parameters.");
  863. _st(console)._log_("Wrong commandline options or not enough arguments for: ".__comma(options));
  864. _st(console)._log_("Use any of the following ones: ".__comma(switches));
  865. $3=server;
  866. return $3;
  867. };
  868. popFront=(function(args){
  869. return smalltalk.withContext(function($ctx2) {
  870. front=_st(args)._first();
  871. front;
  872. _st(args)._remove_(front);
  873. return front;
  874. }, function($ctx2) {$ctx2.fillBlock({args:args},$ctx1)})});
  875. _st((function(){
  876. return smalltalk.withContext(function($ctx2) {
  877. return _st(options)._notEmpty();
  878. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  879. return smalltalk.withContext(function($ctx2) {
  880. optionName=_st(popFront)._value_(options);
  881. optionName;
  882. optionValue=_st(popFront)._value_(options);
  883. optionValue;
  884. $4=_st(switches)._includes_(optionName);
  885. if(smalltalk.assert($4)){
  886. optionName=self._selectorForCommandLineSwitch_(optionName);
  887. optionName;
  888. return _st(server)._perform_withArguments_(optionName,_st($Array())._with_(optionValue));
  889. } else {
  890. _st(console)._log_(_st(optionName).__comma(" is not a valid commandline option"));
  891. return _st(console)._log_("Use any of the following ones: ".__comma(switches));
  892. };
  893. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  894. $5=server;
  895. return $5;
  896. }
  897. catch(e) {if(e===$early)return e[0]; throw e}
  898. }, function($ctx1) {$ctx1.fill(self,"createServerWithArguments:",{options:options,server:server,popFront:popFront,front:front,optionName:optionName,optionValue:optionValue,switches:switches},smalltalk.FileServer.klass)})},
  899. args: ["options"],
  900. 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.",
  901. messageSends: ["commandLineSwitches", "new", "ifEmpty:", "ifFalse:", "log:", ",", "even", "size", "first", "remove:", "whileTrue:", "value:", "ifTrue:ifFalse:", "selectorForCommandLineSwitch:", "perform:withArguments:", "with:", "includes:", "notEmpty"],
  902. referencedClasses: ["Array"]
  903. }),
  904. smalltalk.FileServer.klass);
  905. smalltalk.addMethod(
  906. smalltalk.method({
  907. selector: "defaultHost",
  908. category: 'accessing',
  909. fn: function (){
  910. var self=this;
  911. return smalltalk.withContext(function($ctx1) {
  912. return "127.0.0.1";
  913. }, function($ctx1) {$ctx1.fill(self,"defaultHost",{},smalltalk.FileServer.klass)})},
  914. args: [],
  915. source: "defaultHost\x0a\x09^'127.0.0.1'",
  916. messageSends: [],
  917. referencedClasses: []
  918. }),
  919. smalltalk.FileServer.klass);
  920. smalltalk.addMethod(
  921. smalltalk.method({
  922. selector: "defaultMimeTypes",
  923. category: 'accessing',
  924. fn: function (){
  925. var self=this;
  926. return smalltalk.withContext(function($ctx1) {
  927. var $1;
  928. $1=smalltalk.HashedCollection._from_(["%".__minus_gt("application/x-trash"),"323".__minus_gt("text/h323"),"abw".__minus_gt("application/x-abiword"),"ai".__minus_gt("application/postscript"),"aif".__minus_gt("audio/x-aiff"),"aifc".__minus_gt("audio/x-aiff"),"aiff".__minus_gt("audio/x-aiff"),"alc".__minus_gt("chemical/x-alchemy"),"art".__minus_gt("image/x-jg"),"asc".__minus_gt("text/plain"),"asf".__minus_gt("video/x-ms-asf"),"asn".__minus_gt("chemical/x-ncbi-asn1-spec"),"aso".__minus_gt("chemical/x-ncbi-asn1-binary"),"asx".__minus_gt("video/x-ms-asf"),"au".__minus_gt("audio/basic"),"avi".__minus_gt("video/x-msvideo"),"b".__minus_gt("chemical/x-molconn-Z"),"bak".__minus_gt("application/x-trash"),"bat".__minus_gt("application/x-msdos-program"),"bcpio".__minus_gt("application/x-bcpio"),"bib".__minus_gt("text/x-bibtex"),"bin".__minus_gt("application/octet-stream"),"bmp".__minus_gt("image/x-ms-bmp"),"book".__minus_gt("application/x-maker"),"bsd".__minus_gt("chemical/x-crossfire"),"c".__minus_gt("text/x-csrc"),"c++".__minus_gt("text/x-c++src"),"c3d".__minus_gt("chemical/x-chem3d"),"cac".__minus_gt("chemical/x-cache"),"cache".__minus_gt("chemical/x-cache"),"cascii".__minus_gt("chemical/x-cactvs-binary"),"cat".__minus_gt("application/vnd.ms-pki.seccat"),"cbin".__minus_gt("chemical/x-cactvs-binary"),"cc".__minus_gt("text/x-c++src"),"cdf".__minus_gt("application/x-cdf"),"cdr".__minus_gt("image/x-coreldraw"),"cdt".__minus_gt("image/x-coreldrawtemplate"),"cdx".__minus_gt("chemical/x-cdx"),"cdy".__minus_gt("application/vnd.cinderella"),"cef".__minus_gt("chemical/x-cxf"),"cer".__minus_gt("chemical/x-cerius"),"chm".__minus_gt("chemical/x-chemdraw"),"chrt".__minus_gt("application/x-kchart"),"cif".__minus_gt("chemical/x-cif"),"class".__minus_gt("application/java-vm"),"cls".__minus_gt("text/x-tex"),"cmdf".__minus_gt("chemical/x-cmdf"),"cml".__minus_gt("chemical/x-cml"),"cod".__minus_gt("application/vnd.rim.cod"),"com".__minus_gt("application/x-msdos-program"),"cpa".__minus_gt("chemical/x-compass"),"cpio".__minus_gt("application/x-cpio"),"cpp".__minus_gt("text/x-c++src"),"cpt".__minus_gt("image/x-corelphotopaint"),"crl".__minus_gt("application/x-pkcs7-crl"),"crt".__minus_gt("application/x-x509-ca-cert"),"csf".__minus_gt("chemical/x-cache-csf"),"csh".__minus_gt("text/x-csh"),"csm".__minus_gt("chemical/x-csml"),"csml".__minus_gt("chemical/x-csml"),"css".__minus_gt("text/css"),"csv".__minus_gt("text/comma-separated-values"),"ctab".__minus_gt("chemical/x-cactvs-binary"),"ctx".__minus_gt("chemical/x-ctx"),"cu".__minus_gt("application/cu-seeme"),"cub".__minus_gt("chemical/x-gaussian-cube"),"cxf".__minus_gt("chemical/x-cxf"),"cxx".__minus_gt("text/x-c++src"),"dat".__minus_gt("chemical/x-mopac-input"),"dcr".__minus_gt("application/x-director"),"deb".__minus_gt("application/x-debian-package"),"dif".__minus_gt("video/dv"),"diff".__minus_gt("text/plain"),"dir".__minus_gt("application/x-director"),"djv".__minus_gt("image/vnd.djvu"),"djvu".__minus_gt("image/vnd.djvu"),"dl".__minus_gt("video/dl"),"dll".__minus_gt("application/x-msdos-program"),"dmg".__minus_gt("application/x-apple-diskimage"),"dms".__minus_gt("application/x-dms"),"doc".__minus_gt("application/msword"),"dot".__minus_gt("application/msword"),"dv".__minus_gt("video/dv"),"dvi".__minus_gt("application/x-dvi"),"dx".__minus_gt("chemical/x-jcamp-dx"),"dxr".__minus_gt("application/x-director"),"emb".__minus_gt("chemical/x-embl-dl-nucleotide"),"embl".__minus_gt("chemical/x-embl-dl-nucleotide"),"ent".__minus_gt("chemical/x-pdb"),"eps".__minus_gt("application/postscript"),"etx".__minus_gt("text/x-setext"),"exe".__minus_gt("application/x-msdos-program"),"ez".__minus_gt("application/andrew-inset"),"fb".__minus_gt("application/x-maker"),"fbdoc".__minus_gt("application/x-maker"),"fch".__minus_gt("chemical/x-gaussian-checkpoint"),"fchk".__minus_gt("chemical/x-gaussian-checkpoint"),"fig".__minus_gt("application/x-xfig"),"flac".__minus_gt("application/x-flac"),"fli".__minus_gt("video/fli"),"fm".__minus_gt("application/x-maker"),"frame".__minus_gt("application/x-maker"),"frm".__minus_gt("application/x-maker"),"gal".__minus_gt("chemical/x-gaussian-log"),"gam".__minus_gt("chemical/x-gamess-input"),"gamin".__minus_gt("chemical/x-gamess-input"),"gau".__minus_gt("chemical/x-gaussian-input"),"gcd".__minus_gt("text/x-pcs-gcd"),"gcf".__minus_gt("application/x-graphing-calculator"),"gcg".__minus_gt("chemical/x-gcg8-sequence"),"gen".__minus_gt("chemical/x-genbank"),"gf".__minus_gt("application/x-tex-gf"),"gif".__minus_gt("image/gif"),"gjc".__minus_gt("chemical/x-gaussian-input"),"gjf".__minus_gt("chemical/x-gaussian-input"),"gl".__minus_gt("video/gl"),"gnumeric".__minus_gt("application/x-gnumeric"),"gpt".__minus_gt("chemical/x-mopac-graph"),"gsf".__minus_gt("application/x-font"),"gsm".__minus_gt("audio/x-gsm"),"gtar".__minus_gt("application/x-gtar"),"h".__minus_gt("text/x-chdr"),"h++".__minus_gt("text/x-c++hdr"),"hdf".__minus_gt("application/x-hdf"),"hh".__minus_gt("text/x-c++hdr"),"hin".__minus_gt("chemical/x-hin"),"hpp".__minus_gt("text/x-c++hdr"),"hqx".__minus_gt("application/mac-binhex40"),"hs".__minus_gt("text/x-haskell"),"hta".__minus_gt("application/hta"),"htc".__minus_gt("text/x-component"),"htm".__minus_gt("text/html"),"html".__minus_gt("text/html"),"hxx".__minus_gt("text/x-c++hdr"),"ica".__minus_gt("application/x-ica"),"ice".__minus_gt("x-conference/x-cooltalk"),"ico".__minus_gt("image/x-icon"),"ics".__minus_gt("text/calendar"),"icz".__minus_gt("text/calendar"),"ief".__minus_gt("image/ief"),"iges".__minus_gt("model/iges"),"igs".__minus_gt("model/iges"),"iii".__minus_gt("application/x-iphone"),"inp".__minus_gt("chemical/x-gamess-input"),"ins".__minus_gt("application/x-internet-signup"),"iso".__minus_gt("application/x-iso9660-image"),"isp".__minus_gt("application/x-internet-signup"),"ist".__minus_gt("chemical/x-isostar"),"istr".__minus_gt("chemical/x-isostar"),"jad".__minus_gt("text/vnd.sun.j2me.app-descriptor"),"jar".__minus_gt("application/java-archive"),"java".__minus_gt("text/x-java"),"jdx".__minus_gt("chemical/x-jcamp-dx"),"jmz".__minus_gt("application/x-jmol"),"jng".__minus_gt("image/x-jng"),"jnlp".__minus_gt("application/x-java-jnlp-file"),"jpe".__minus_gt("image/jpeg"),"jpeg".__minus_gt("image/jpeg"),"jpg".__minus_gt("image/jpeg"),"js".__minus_gt("application/javascript"),"kar".__minus_gt("audio/midi"),"key".__minus_gt("application/pgp-keys"),"kil".__minus_gt("application/x-killustrator"),"kin".__minus_gt("chemical/x-kinemage"),"kpr".__minus_gt("application/x-kpresenter"),"kpt".__minus_gt("application/x-kpresenter"),"ksp".__minus_gt("application/x-kspread"),"kwd".__minus_gt("application/x-kword"),"kwt".__minus_gt("application/x-kword"),"latex".__minus_gt("application/x-latex"),"lha".__minus_gt("application/x-lha"),"lhs".__minus_gt("text/x-literate-haskell"),"lsf".__minus_gt("video/x-la-asf"),"lsx".__minus_gt("video/x-la-asf"),"ltx".__minus_gt("text/x-tex"),"lzh".__minus_gt("application/x-lzh"),"lzx".__minus_gt("application/x-lzx"),"m3u".__minus_gt("audio/x-mpegurl"),"m4a".__minus_gt("audio/mpeg"),"maker".__minus_gt("application/x-maker"),"man".__minus_gt("application/x-troff-man"),"mcif".__minus_gt("chemical/x-mmcif"),"mcm".__minus_gt("chemical/x-macmolecule"),"mdb".__minus_gt("application/msaccess"),"me".__minus_gt("application/x-troff-me"),"mesh".__minus_gt("model/mesh"),"mid".__minus_gt("audio/midi"),"midi".__minus_gt("audio/midi"),"mif".__minus_gt("application/x-mif"),"mm".__minus_gt("application/x-freemind"),"mmd".__minus_gt("chemical/x-macromodel-input"),"mmf".__minus_gt("application/vnd.smaf"),"mml".__minus_gt("text/mathml"),"mmod".__minus_gt("chemical/x-macromodel-input"),"mng".__minus_gt("video/x-mng"),"moc".__minus_gt("text/x-moc"),"mol".__minus_gt("chemical/x-mdl-molfile"),"mol2".__minus_gt("chemical/x-mol2"),"moo".__minus_gt("chemical/x-mopac-out"),"mop".__minus_gt("chemical/x-mopac-input"),"mopcrt".__minus_gt("chemical/x-mopac-input"),"mov".__minus_gt("video/quicktime"),"movie".__minus_gt("video/x-sgi-movie"),"mp2".__minus_gt("audio/mpeg"),"mp3".__minus_gt("audio/mpeg"),"mp4".__minus_gt("video/mp4"),"mpc".__minus_gt("chemical/x-mopac-input"),"mpe".__minus_gt("video/mpeg"),"mpeg".__minus_gt("video/mpeg"),"mpega".__minus_gt("audio/mpeg"),"mpg".__minus_gt("video/mpeg"),"mpga".__minus_gt("audio/mpeg"),"ms".__minus_gt("application/x-troff-ms"),"msh".__minus_gt("model/mesh"),"msi".__minus_gt("application/x-msi"),"mvb".__minus_gt("chemical/x-mopac-vib"),"mxu".__minus_gt("video/vnd.mpegurl"),"nb".__minus_gt("application/mathematica"),"nc".__minus_gt("application/x-netcdf"),"nwc".__minus_gt("application/x-nwc"),"o".__minus_gt("application/x-object"),"oda".__minus_gt("application/oda"),"odb".__minus_gt("application/vnd.oasis.opendocument.database"),"odc".__minus_gt("application/vnd.oasis.opendocument.chart"),"odf".__minus_gt("application/vnd.oasis.opendocument.formula"),"odg".__minus_gt("application/vnd.oasis.opendocument.graphics"),"odi".__minus_gt("application/vnd.oasis.opendocument.image"),"odm".__minus_gt("application/vnd.oasis.opendocument.text-master"),"odp".__minus_gt("application/vnd.oasis.opendocument.presentation"),"ods".__minus_gt("application/vnd.oasis.opendocument.spreadsheet"),"odt".__minus_gt("application/vnd.oasis.opendocument.text"),"ogg".__minus_gt("application/ogg"),"old".__minus_gt("application/x-trash"),"oth".__minus_gt("application/vnd.oasis.opendocument.text-web"),"oza".__minus_gt("application/x-oz-application"),"p".__minus_gt("text/x-pascal"),"p7r".__minus_gt("application/x-pkcs7-certreqresp"),"pac".__minus_gt("application/x-ns-proxy-autoconfig"),"pas".__minus_gt("text/x-pascal"),"pat".__minus_gt("image/x-coreldrawpattern"),"pbm".__minus_gt("image/x-portable-bitmap"),"pcf".__minus_gt("application/x-font"),"pcf.Z".__minus_gt("application/x-font"),"pcx".__minus_gt("image/pcx"),"pdb".__minus_gt("chemical/x-pdb"),"pdf".__minus_gt("application/pdf"),"pfa".__minus_gt("application/x-font"),"pfb".__minus_gt("application/x-font"),"pgm".__minus_gt("image/x-portable-graymap"),"pgn".__minus_gt("application/x-chess-pgn"),"pgp".__minus_gt("application/pgp-signature"),"pk".__minus_gt("application/x-tex-pk"),"pl".__minus_gt("text/x-perl"),"pls".__minus_gt("audio/x-scpls"),"pm".__minus_gt("text/x-perl"),"png".__minus_gt("image/png"),"pnm".__minus_gt("image/x-portable-anymap"),"pot".__minus_gt("text/plain"),"ppm".__minus_gt("image/x-portable-pixmap"),"pps".__minus_gt("application/vnd.ms-powerpoint"),"ppt".__minus_gt("application/vnd.ms-powerpoint"),"prf".__minus_gt("application/pics-rules"),"prt".__minus_gt("chemical/x-ncbi-asn1-ascii"),"ps".__minus_gt("application/postscript"),"psd".__minus_gt("image/x-photoshop"),"psp".__minus_gt("text/x-psp"),"py".__minus_gt("text/x-python"),"pyc".__minus_gt("application/x-python-code"),"pyo".__minus_gt("application/x-python-code"),"qt".__minus_gt("video/quicktime"),"qtl".__minus_gt("application/x-quicktimeplayer"),"ra".__minus_gt("audio/x-realaudio"),"ram".__minus_gt("audio/x-pn-realaudio"),"rar".__minus_gt("application/rar"),"ras".__minus_gt("image/x-cmu-raster"),"rd".__minus_gt("chemical/x-mdl-rdfile"),"rdf".__minus_gt("application/rdf+xml"),"rgb".__minus_gt("image/x-rgb"),"rm".__minus_gt("audio/x-pn-realaudio"),"roff".__minus_gt("application/x-troff"),"ros".__minus_gt("chemical/x-rosdal"),"rpm".__minus_gt("application/x-redhat-package-manager"),"rss".__minus_gt("application/rss+xml"),"rtf".__minus_gt("text/rtf"),"rtx".__minus_gt("text/richtext"),"rxn".__minus_gt("chemical/x-mdl-rxnfile"),"sct".__minus_gt("text/scriptlet"),"sd".__minus_gt("chemical/x-mdl-sdfile"),"sd2".__minus_gt("audio/x-sd2"),"sda".__minus_gt("application/vnd.stardivision.draw"),"sdc".__minus_gt("application/vnd.stardivision.calc"),"sdd".__minus_gt("application/vnd.stardivision.impress"),"sdf".__minus_gt("chemical/x-mdl-sdfile"),"sdp".__minus_gt("application/vnd.stardivision.impress"),"sdw".__minus_gt("application/vnd.stardivision.writer"),"ser".__minus_gt("application/java-serialized-object"),"sgf".__minus_gt("application/x-go-sgf"),"sgl".__minus_gt("application/vnd.stardivision.writer-global"),"sh".__minus_gt("text/x-sh"),"shar".__minus_gt("application/x-shar"),"shtml".__minus_gt("text/html"),"sid".__minus_gt("audio/prs.sid"),"sik".__minus_gt("application/x-trash"),"silo".__minus_gt("model/mesh"),"sis".__minus_gt("application/vnd.symbian.install"),"sit".__minus_gt("application/x-stuffit"),"skd".__minus_gt("application/x-koan"),"skm".__minus_gt("application/x-koan"),"skp".__minus_gt("application/x-koan"),"skt".__minus_gt("application/x-koan"),"smf".__minus_gt("application/vnd.stardivision.math"),"smi".__minus_gt("application/smil"),"smil".__minus_gt("application/smil"),"snd".__minus_gt("audio/basic"),"spc".__minus_gt("chemical/x-galactic-spc"),"spl".__minus_gt("application/x-futuresplash"),"src".__minus_gt("application/x-wais-source"),"stc".__minus_gt("application/vnd.sun.xml.calc.template"),"std".__minus_gt("application/vnd.sun.xml.draw.template"),"sti".__minus_gt("application/vnd.sun.xml.impress.template"),"stl".__minus_gt("application/vnd.ms-pki.stl"),"stw".__minus_gt("application/vnd.sun.xml.writer.template"),"sty".__minus_gt("text/x-tex"),"sv4cpio".__minus_gt("application/x-sv4cpio"),"sv4crc".__minus_gt("application/x-sv4crc"),"svg".__minus_gt("image/svg+xml"),"svgz".__minus_gt("image/svg+xml"),"sw".__minus_gt("chemical/x-swissprot"),"swf".__minus_gt("application/x-shockwave-flash"),"swfl".__minus_gt("application/x-shockwave-flash"),"sxc".__minus_gt("application/vnd.sun.xml.calc"),"sxd".__minus_gt("application/vnd.sun.xml.draw"),"sxg".__minus_gt("application/vnd.sun.xml.writer.global"),"sxi".__minus_gt("application/vnd.sun.xml.impress"),"sxm".__minus_gt("application/vnd.sun.xml.math"),"sxw".__minus_gt("application/vnd.sun.xml.writer"),"t".__minus_gt("application/x-troff"),"tar".__minus_gt("application/x-tar"),"taz".__minus_gt("application/x-gtar"),"tcl".__minus_gt("text/x-tcl"),"tex".__minus_gt("text/x-tex"),"texi".__minus_gt("application/x-texinfo"),"texinfo".__minus_gt("application/x-texinfo"),"text".__minus_gt("text/plain"),"tgf".__minus_gt("chemical/x-mdl-tgf"),"tgz".__minus_gt("application/x-gtar"),"tif".__minus_gt("image/tiff"),"tiff".__minus_gt("image/tiff"),"tk".__minus_gt("text/x-tcl"),"tm".__minus_gt("text/texmacs"),"torrent".__minus_gt("application/x-bittorrent"),"tr".__minus_gt("application/x-troff"),"ts".__minus_gt("text/texmacs"),"tsp".__minus_gt("application/dsptype"),"tsv".__minus_gt("text/tab-separated-values"),"txt".__minus_gt("text/plain"),"udeb".__minus_gt("application/x-debian-package"),"uls".__minus_gt("text/iuls"),"ustar".__minus_gt("application/x-ustar"),"val".__minus_gt("chemical/x-ncbi-asn1-binary"),"vcd".__minus_gt("application/x-cdlink"),"vcf".__minus_gt("text/x-vcard"),"vcs".__minus_gt("text/x-vcalendar"),"vmd".__minus_gt("chemical/x-vmd"),"vms".__minus_gt("chemical/x-vamas-iso14976"),"vor".__minus_gt("application/vnd.stardivision.writer"),"vrm".__minus_gt("x-world/x-vrml"),"vrml".__minus_gt("x-world/x-vrml"),"vsd".__minus_gt("application/vnd.visio"),"wad".__minus_gt("application/x-doom"),"wav".__minus_gt("audio/x-wav"),"wax".__minus_gt("audio/x-ms-wax"),"wbmp".__minus_gt("image/vnd.wap.wbmp"),"wbxml".__minus_gt("application/vnd.wap.wbxml"),"wk".__minus_gt("application/x-123"),"wm".__minus_gt("video/x-ms-wm"),"wma".__minus_gt("audio/x-ms-wma"),"wmd".__minus_gt("application/x-ms-wmd"),"wml".__minus_gt("text/vnd.wap.wml"),"wmlc".__minus_gt("application/vnd.wap.wmlc"),"wmls".__minus_gt("text/vnd.wap.wmlscript"),"wmlsc".__minus_gt("application/vnd.wap.wmlscriptc"),"wmv".__minus_gt("video/x-ms-wmv"),"wmx".__minus_gt("video/x-ms-wmx"),"wmz".__minus_gt("application/x-ms-wmz"),"wp5".__minus_gt("application/wordperfect5.1"),"wpd".__minus_gt("application/wordperfect"),"wrl".__minus_gt("x-world/x-vrml"),"wsc".__minus_gt("text/scriptlet"),"wvx".__minus_gt("video/x-ms-wvx"),"wz".__minus_gt("application/x-wingz"),"xbm".__minus_gt("image/x-xbitmap"),"xcf".__minus_gt("application/x-xcf"),"xht".__minus_gt("application/xhtml+xml"),"xhtml".__minus_gt("application/xhtml+xml"),"xlb".__minus_gt("application/vnd.ms-excel"),"xls".__minus_gt("application/vnd.ms-excel"),"xlt".__minus_gt("application/vnd.ms-excel"),"xml".__minus_gt("application/xml"),"xpi".__minus_gt("application/x-xpinstall"),"xpm".__minus_gt("image/x-xpixmap"),"xsl".__minus_gt("application/xml"),"xtel".__minus_gt("chemical/x-xtel"),"xul".__minus_gt("application/vnd.mozilla.xul+xml"),"xwd".__minus_gt("image/x-xwindowdump"),"xyz".__minus_gt("chemical/x-xyz"),"zip".__minus_gt("application/zip"),"zmt".__minus_gt("chemical/x-mopac-input"),"~".__minus_gt("application/x-trash")]);
  929. return $1;
  930. }, function($ctx1) {$ctx1.fill(self,"defaultMimeTypes",{},smalltalk.FileServer.klass)})},
  931. args: [],
  932. 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}",
  933. messageSends: ["->"],
  934. referencedClasses: []
  935. }),
  936. smalltalk.FileServer.klass);
  937. smalltalk.addMethod(
  938. smalltalk.method({
  939. selector: "defaultPort",
  940. category: 'accessing',
  941. fn: function (){
  942. var self=this;
  943. return smalltalk.withContext(function($ctx1) {
  944. return (4000);
  945. }, function($ctx1) {$ctx1.fill(self,"defaultPort",{},smalltalk.FileServer.klass)})},
  946. args: [],
  947. source: "defaultPort\x0a\x09^4000",
  948. messageSends: [],
  949. referencedClasses: []
  950. }),
  951. smalltalk.FileServer.klass);
  952. smalltalk.addMethod(
  953. smalltalk.method({
  954. selector: "main",
  955. category: 'initialization',
  956. fn: function (){
  957. var self=this;
  958. var fileServer,args;
  959. function $FileServer(){return smalltalk.FileServer||(typeof FileServer=="undefined"?nil:FileServer)}
  960. return smalltalk.withContext(function($ctx1) {
  961. var $1,$2;
  962. var $early={};
  963. try {
  964. args=_st(process)._argv();
  965. _st(args)._removeFrom_to_((1),(3));
  966. _st(args)._detect_ifNone_((function(each){
  967. return smalltalk.withContext(function($ctx2) {
  968. $1=_st(each).__eq("--help");
  969. if(smalltalk.assert($1)){
  970. return _st($FileServer())._printHelp();
  971. };
  972. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  973. return smalltalk.withContext(function($ctx2) {
  974. fileServer=_st($FileServer())._createServerWithArguments_(args);
  975. fileServer;
  976. $2=_st(fileServer)._start();
  977. throw $early=[$2];
  978. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  979. return self}
  980. catch(e) {if(e===$early)return e[0]; throw e}
  981. }, function($ctx1) {$ctx1.fill(self,"main",{fileServer:fileServer,args:args},smalltalk.FileServer.klass)})},
  982. args: [],
  983. 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]",
  984. messageSends: ["argv", "removeFrom:to:", "detect:ifNone:", "ifTrue:", "printHelp", "=", "createServerWithArguments:", "start"],
  985. referencedClasses: ["FileServer"]
  986. }),
  987. smalltalk.FileServer.klass);
  988. smalltalk.addMethod(
  989. smalltalk.method({
  990. selector: "mimeTypeFor:",
  991. category: 'accessing',
  992. fn: function (aString){
  993. var self=this;
  994. return smalltalk.withContext(function($ctx1) {
  995. var $1;
  996. $1=_st(self._mimeTypes())._at_ifAbsent_(_st(aString)._replace_with_(".*[\x5c.]",""),(function(){
  997. return smalltalk.withContext(function($ctx2) {
  998. return "text/plain";
  999. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1000. return $1;
  1001. }, function($ctx1) {$ctx1.fill(self,"mimeTypeFor:",{aString:aString},smalltalk.FileServer.klass)})},
  1002. args: ["aString"],
  1003. source: "mimeTypeFor: aString\x0a\x09^self mimeTypes at: (aString replace: '.*[\x5c.]' with: '') ifAbsent: ['text/plain']",
  1004. messageSends: ["at:ifAbsent:", "replace:with:", "mimeTypes"],
  1005. referencedClasses: []
  1006. }),
  1007. smalltalk.FileServer.klass);
  1008. smalltalk.addMethod(
  1009. smalltalk.method({
  1010. selector: "mimeTypes",
  1011. category: 'accessing',
  1012. fn: function (){
  1013. var self=this;
  1014. return smalltalk.withContext(function($ctx1) {
  1015. var $2,$1;
  1016. $2=self["@mimeTypes"];
  1017. if(($receiver = $2) == nil || $receiver == undefined){
  1018. self["@mimeTypes"]=self._defaultMimeTypes();
  1019. $1=self["@mimeTypes"];
  1020. } else {
  1021. $1=$2;
  1022. };
  1023. return $1;
  1024. }, function($ctx1) {$ctx1.fill(self,"mimeTypes",{},smalltalk.FileServer.klass)})},
  1025. args: [],
  1026. source: "mimeTypes\x0a\x09^mimeTypes ifNil: [mimeTypes := self defaultMimeTypes]",
  1027. messageSends: ["ifNil:", "defaultMimeTypes"],
  1028. referencedClasses: []
  1029. }),
  1030. smalltalk.FileServer.klass);
  1031. smalltalk.addMethod(
  1032. smalltalk.method({
  1033. selector: "printHelp",
  1034. category: 'accessing',
  1035. fn: function (){
  1036. var self=this;
  1037. return smalltalk.withContext(function($ctx1) {
  1038. _st(console)._log_("Available commandline options are:");
  1039. _st(console)._log_("--help");
  1040. _st(self._commandLineSwitches())._do_((function(each){
  1041. return smalltalk.withContext(function($ctx2) {
  1042. return _st(console)._log_(_st(each).__comma(" <parameter>"));
  1043. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1044. return self}, function($ctx1) {$ctx1.fill(self,"printHelp",{},smalltalk.FileServer.klass)})},
  1045. args: [],
  1046. source: "printHelp\x0a\x09console log: 'Available commandline options are:'.\x0a\x09console log: '--help'.\x0a\x09self commandLineSwitches do: [ :each |\x0a\x09\x09console log: each, ' <parameter>']",
  1047. messageSends: ["log:", "do:", ",", "commandLineSwitches"],
  1048. referencedClasses: []
  1049. }),
  1050. smalltalk.FileServer.klass);
  1051. smalltalk.addMethod(
  1052. smalltalk.method({
  1053. selector: "selectorForCommandLineSwitch:",
  1054. category: 'accessing',
  1055. fn: function (aSwitch){
  1056. var self=this;
  1057. return smalltalk.withContext(function($ctx1) {
  1058. var $1;
  1059. $1=_st(_st(_st(aSwitch)._replace_with_("^--",""))._replace_with_("-[a-z]",(function(each){
  1060. return smalltalk.withContext(function($ctx2) {
  1061. return _st(_st(each)._second())._asUppercase();
  1062. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}))).__comma(":");
  1063. return $1;
  1064. }, function($ctx1) {$ctx1.fill(self,"selectorForCommandLineSwitch:",{aSwitch:aSwitch},smalltalk.FileServer.klass)})},
  1065. args: ["aSwitch"],
  1066. 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 ]), ':'",
  1067. messageSends: [",", "replace:with:", "asUppercase", "second"],
  1068. referencedClasses: []
  1069. }),
  1070. smalltalk.FileServer.klass);
  1071. smalltalk.addClass('Repl', smalltalk.Object, ['readline', 'interface', 'util', 'session', 'resultCount', 'commands'], 'AmberCli');
  1072. 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.";
  1073. smalltalk.addMethod(
  1074. smalltalk.method({
  1075. selector: "addVariableNamed:to:",
  1076. category: 'private',
  1077. fn: function (aString,anObject){
  1078. var self=this;
  1079. var newClass,newObject;
  1080. return smalltalk.withContext(function($ctx1) {
  1081. var $1;
  1082. newClass=self._subclass_withVariable_(_st(anObject)._class(),aString);
  1083. self._encapsulateVariable_withValue_in_(aString,anObject,newClass);
  1084. newObject=_st(newClass)._new();
  1085. self._setPreviousVariablesFor_from_(newObject,anObject);
  1086. $1=newObject;
  1087. return $1;
  1088. }, function($ctx1) {$ctx1.fill(self,"addVariableNamed:to:",{aString:aString,anObject:anObject,newClass:newClass,newObject:newObject},smalltalk.Repl)})},
  1089. args: ["aString", "anObject"],
  1090. source: "addVariableNamed: aString to: anObject\x0a\x09| newClass newObject |\x0a\x09newClass := self subclass: anObject class withVariable: aString.\x0a\x09self encapsulateVariable: aString withValue: anObject in: newClass.\x0a\x09newObject := newClass new.\x0a\x09self setPreviousVariablesFor: newObject from: anObject.\x0a\x09^ newObject",
  1091. messageSends: ["subclass:withVariable:", "class", "encapsulateVariable:withValue:in:", "new", "setPreviousVariablesFor:from:"],
  1092. referencedClasses: []
  1093. }),
  1094. smalltalk.Repl);
  1095. smalltalk.addMethod(
  1096. smalltalk.method({
  1097. selector: "assignNewVariable:do:",
  1098. category: 'private',
  1099. fn: function (buffer,aBlock){
  1100. var self=this;
  1101. return smalltalk.withContext(function($ctx1) {
  1102. var $2,$3,$5,$7,$6,$4,$1;
  1103. $1=self._parseAssignment_do_(buffer,(function(name,expr){
  1104. var varName,value;
  1105. return smalltalk.withContext(function($ctx2) {
  1106. $2=name;
  1107. if(($receiver = $2) == nil || $receiver == undefined){
  1108. varName=self._nextResultName();
  1109. } else {
  1110. varName=$2;
  1111. };
  1112. varName;
  1113. self["@session"]=self._addVariableNamed_to_(varName,self["@session"]);
  1114. self["@session"];
  1115. $3=self;
  1116. $5=_st(varName).__comma(" := ");
  1117. $7=expr;
  1118. if(($receiver = $7) == nil || $receiver == undefined){
  1119. $6=buffer;
  1120. } else {
  1121. $6=$7;
  1122. };
  1123. $4=_st($5).__comma($6);
  1124. value=_st($3)._eval_on_($4,self["@session"]);
  1125. value;
  1126. return _st(aBlock)._value_value_(varName,value);
  1127. }, function($ctx2) {$ctx2.fillBlock({name:name,expr:expr,varName:varName,value:value},$ctx1)})}));
  1128. return $1;
  1129. }, function($ctx1) {$ctx1.fill(self,"assignNewVariable:do:",{buffer:buffer,aBlock:aBlock},smalltalk.Repl)})},
  1130. args: ["buffer", "aBlock"],
  1131. source: "assignNewVariable: buffer do: aBlock\x0a\x09\x22Assigns a new variable and calls the given block with the variable's name and value\x0a\x09 if buffer contains an assignment expression. If it doesn't the block is called with nil for\x0a\x09 both arguments.\x22\x0a\x09^ self parseAssignment: buffer do: [ :name :expr || varName value |\x0a\x09\x09varName := name ifNil: [self nextResultName].\x0a\x09\x09session := self addVariableNamed: varName to: session.\x0a\x09\x09value := self eval: varName, ' := ', (expr ifNil: [buffer]) on: session.\x0a\x09\x09aBlock value: varName value: value]",
  1132. messageSends: ["parseAssignment:do:", "ifNil:", "nextResultName", "addVariableNamed:to:", "eval:on:", ",", "value:value:"],
  1133. referencedClasses: []
  1134. }),
  1135. smalltalk.Repl);
  1136. smalltalk.addMethod(
  1137. smalltalk.method({
  1138. selector: "clearScreen",
  1139. category: 'private',
  1140. fn: function (){
  1141. var self=this;
  1142. var esc,cls;
  1143. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  1144. return smalltalk.withContext(function($ctx1) {
  1145. esc=_st($String())._fromCharCode_((27));
  1146. cls=_st(_st(_st(esc).__comma("[2J")).__comma(esc)).__comma("[0;0f");
  1147. _st(_st(process)._stdout())._write_(cls);
  1148. _st(self["@interface"])._prompt();
  1149. return self}, function($ctx1) {$ctx1.fill(self,"clearScreen",{esc:esc,cls:cls},smalltalk.Repl)})},
  1150. args: [],
  1151. source: "clearScreen\x0a\x09| esc cls |\x0a\x09esc := String fromCharCode: 27.\x0a\x09cls := esc, '[2J', esc, '[0;0f'.\x0a\x09process stdout write: cls.\x0a\x09interface prompt",
  1152. messageSends: ["fromCharCode:", ",", "write:", "stdout", "prompt"],
  1153. referencedClasses: ["String"]
  1154. }),
  1155. smalltalk.Repl);
  1156. smalltalk.addMethod(
  1157. smalltalk.method({
  1158. selector: "close",
  1159. category: 'actions',
  1160. fn: function (){
  1161. var self=this;
  1162. return smalltalk.withContext(function($ctx1) {
  1163. _st(_st(process)._stdin())._destroy();
  1164. return self}, function($ctx1) {$ctx1.fill(self,"close",{},smalltalk.Repl)})},
  1165. args: [],
  1166. source: "close\x0a\x09process stdin destroy",
  1167. messageSends: ["destroy", "stdin"],
  1168. referencedClasses: []
  1169. }),
  1170. smalltalk.Repl);
  1171. smalltalk.addMethod(
  1172. smalltalk.method({
  1173. selector: "commands",
  1174. category: 'accessing',
  1175. fn: function (){
  1176. var self=this;
  1177. return smalltalk.withContext(function($ctx1) {
  1178. var $1;
  1179. $1=self["@commands"];
  1180. return $1;
  1181. }, function($ctx1) {$ctx1.fill(self,"commands",{},smalltalk.Repl)})},
  1182. args: [],
  1183. source: "commands\x0a\x09^ commands",
  1184. messageSends: [],
  1185. referencedClasses: []
  1186. }),
  1187. smalltalk.Repl);
  1188. smalltalk.addMethod(
  1189. smalltalk.method({
  1190. selector: "createInterface",
  1191. category: 'actions',
  1192. fn: function (){
  1193. var self=this;
  1194. return smalltalk.withContext(function($ctx1) {
  1195. var $1,$2;
  1196. self["@interface"]=_st(self["@readline"])._createInterface_stdout_(_st(process)._stdin(),_st(process)._stdout());
  1197. _st(self["@interface"])._on_do_("line",(function(buffer){
  1198. return smalltalk.withContext(function($ctx2) {
  1199. return self._processLine_(buffer);
  1200. }, function($ctx2) {$ctx2.fillBlock({buffer:buffer},$ctx1)})}));
  1201. _st(self["@interface"])._on_do_("close",(function(){
  1202. return smalltalk.withContext(function($ctx2) {
  1203. return self._close();
  1204. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1205. $1=self;
  1206. _st($1)._printWelcome();
  1207. _st($1)._setupHotkeys();
  1208. $2=_st($1)._setPrompt();
  1209. _st(self["@interface"])._prompt();
  1210. return self}, function($ctx1) {$ctx1.fill(self,"createInterface",{},smalltalk.Repl)})},
  1211. args: [],
  1212. source: "createInterface\x0a\x09interface := readline createInterface: process stdin stdout: process stdout.\x0a\x09interface on: 'line' do: [:buffer | self processLine: buffer].\x0a\x09interface on: 'close' do: [self close].\x0a\x09self printWelcome; setupHotkeys; setPrompt.\x0a\x09interface prompt",
  1213. messageSends: ["createInterface:stdout:", "stdin", "stdout", "on:do:", "processLine:", "close", "printWelcome", "setupHotkeys", "setPrompt", "prompt"],
  1214. referencedClasses: []
  1215. }),
  1216. smalltalk.Repl);
  1217. smalltalk.addMethod(
  1218. smalltalk.method({
  1219. selector: "encapsulateVariable:withValue:in:",
  1220. category: 'private',
  1221. fn: function (aString,anObject,aClass){
  1222. var self=this;
  1223. var compiler;
  1224. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  1225. return smalltalk.withContext(function($ctx1) {
  1226. compiler=_st($Compiler())._new();
  1227. _st(compiler)._install_forClass_category_(_st(_st(_st(aString).__comma(": anObject ^ ")).__comma(aString)).__comma(" := anObject"),aClass,"session");
  1228. _st(compiler)._install_forClass_category_(_st(_st(aString).__comma(" ^ ")).__comma(aString),aClass,"session");
  1229. return self}, function($ctx1) {$ctx1.fill(self,"encapsulateVariable:withValue:in:",{aString:aString,anObject:anObject,aClass:aClass,compiler:compiler},smalltalk.Repl)})},
  1230. args: ["aString", "anObject", "aClass"],
  1231. source: "encapsulateVariable: aString withValue: anObject in: aClass\x0a\x09\x22Add getter and setter for given variable to session.\x22\x0a\x09| compiler |\x0a\x09compiler := Compiler new.\x0a\x09compiler install: aString, ': anObject ^ ', aString, ' := anObject' forClass: aClass category: 'session'.\x0a\x09compiler install: aString, ' ^ ', aString forClass: aClass category: 'session'.",
  1232. messageSends: ["new", "install:forClass:category:", ","],
  1233. referencedClasses: ["Compiler"]
  1234. }),
  1235. smalltalk.Repl);
  1236. smalltalk.addMethod(
  1237. smalltalk.method({
  1238. selector: "eval:",
  1239. category: 'actions',
  1240. fn: function (buffer){
  1241. var self=this;
  1242. function $DoIt(){return smalltalk.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  1243. return smalltalk.withContext(function($ctx1) {
  1244. var $1;
  1245. $1=self._eval_on_(buffer,_st($DoIt())._new());
  1246. return $1;
  1247. }, function($ctx1) {$ctx1.fill(self,"eval:",{buffer:buffer},smalltalk.Repl)})},
  1248. args: ["buffer"],
  1249. source: "eval: buffer\x0a\x09^ self eval: buffer on: DoIt new.",
  1250. messageSends: ["eval:on:", "new"],
  1251. referencedClasses: ["DoIt"]
  1252. }),
  1253. smalltalk.Repl);
  1254. smalltalk.addMethod(
  1255. smalltalk.method({
  1256. selector: "eval:on:",
  1257. category: 'actions',
  1258. fn: function (buffer,anObject){
  1259. var self=this;
  1260. var result;
  1261. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  1262. function $ErrorHandler(){return smalltalk.ErrorHandler||(typeof ErrorHandler=="undefined"?nil:ErrorHandler)}
  1263. return smalltalk.withContext(function($ctx1) {
  1264. var $1,$2,$3;
  1265. $1=_st(buffer)._isEmpty();
  1266. if(! smalltalk.assert($1)){
  1267. self._try_catch_((function(){
  1268. return smalltalk.withContext(function($ctx2) {
  1269. result=_st(_st($Compiler())._new())._evaluateExpression_on_(buffer,anObject);
  1270. return result;
  1271. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),(function(e){
  1272. return smalltalk.withContext(function($ctx2) {
  1273. $2=_st(e)._isSmalltalkError();
  1274. if(smalltalk.assert($2)){
  1275. return _st(_st($ErrorHandler())._new())._handleError_(e);
  1276. } else {
  1277. return _st(_st(process)._stdout())._write_(_st(e)._jsStack());
  1278. };
  1279. }, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1)})}));
  1280. };
  1281. $3=result;
  1282. return $3;
  1283. }, function($ctx1) {$ctx1.fill(self,"eval:on:",{buffer:buffer,anObject:anObject,result:result},smalltalk.Repl)})},
  1284. args: ["buffer", "anObject"],
  1285. source: "eval: buffer on: anObject\x0a\x09| result |\x0a\x09buffer isEmpty ifFalse: [\x0a\x09\x09self try: [\x0a\x09\x09\x09result := Compiler new evaluateExpression: buffer on: anObject]\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\x09^ result",
  1286. messageSends: ["ifFalse:", "try:catch:", "evaluateExpression:on:", "new", "ifTrue:ifFalse:", "handleError:", "write:", "jsStack", "stdout", "isSmalltalkError", "isEmpty"],
  1287. referencedClasses: ["Compiler", "ErrorHandler"]
  1288. }),
  1289. smalltalk.Repl);
  1290. smalltalk.addMethod(
  1291. smalltalk.method({
  1292. selector: "executeCommand:",
  1293. category: 'private',
  1294. fn: function (aString){
  1295. var self=this;
  1296. return smalltalk.withContext(function($ctx1) {
  1297. var $1;
  1298. var $early={};
  1299. try {
  1300. _st(self._commands())._keysAndValuesDo_((function(names,cmd){
  1301. return smalltalk.withContext(function($ctx2) {
  1302. $1=_st(names)._includes_(aString);
  1303. if(smalltalk.assert($1)){
  1304. _st(cmd)._value();
  1305. throw $early=[true];
  1306. };
  1307. }, function($ctx2) {$ctx2.fillBlock({names:names,cmd:cmd},$ctx1)})}));
  1308. return false;
  1309. }
  1310. catch(e) {if(e===$early)return e[0]; throw e}
  1311. }, function($ctx1) {$ctx1.fill(self,"executeCommand:",{aString:aString},smalltalk.Repl)})},
  1312. args: ["aString"],
  1313. source: "executeCommand: aString\x0a\x09\x22Tries to process the given string as a command. Returns true if it was a command, false if not.\x22\x0a\x09self commands keysAndValuesDo: [:names :cmd |\x0a\x09\x09(names includes: aString) ifTrue: [\x0a\x09\x09\x09cmd value.\x0a\x09\x09\x09^ true]].\x0a\x09^ false",
  1314. messageSends: ["keysAndValuesDo:", "ifTrue:", "value", "includes:", "commands"],
  1315. referencedClasses: []
  1316. }),
  1317. smalltalk.Repl);
  1318. smalltalk.addMethod(
  1319. smalltalk.method({
  1320. selector: "initialize",
  1321. category: 'initialization',
  1322. fn: function (){
  1323. var self=this;
  1324. function $DoIt(){return smalltalk.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  1325. return smalltalk.withContext(function($ctx1) {
  1326. smalltalk.Repl.superclass.fn.prototype._initialize.apply(_st(self), []);
  1327. self["@session"]=_st($DoIt())._new();
  1328. self["@readline"]=_st(require)._value_("readline");
  1329. self["@util"]=_st(require)._value_("util");
  1330. self._setupCommands();
  1331. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.Repl)})},
  1332. args: [],
  1333. source: "initialize\x0a\x09super initialize.\x0a\x09session := DoIt new.\x0a\x09readline := require value: 'readline'.\x0a\x09util := require value: 'util'.\x0a\x09self setupCommands",
  1334. messageSends: ["initialize", "new", "value:", "setupCommands"],
  1335. referencedClasses: ["DoIt"]
  1336. }),
  1337. smalltalk.Repl);
  1338. smalltalk.addMethod(
  1339. smalltalk.method({
  1340. selector: "instanceVariableNamesFor:",
  1341. category: 'private',
  1342. fn: function (aClass){
  1343. var self=this;
  1344. return smalltalk.withContext(function($ctx1) {
  1345. var $2,$1;
  1346. $2=_st(aClass)._superclass();
  1347. if(($receiver = $2) == nil || $receiver == undefined){
  1348. $1=_st(aClass)._instanceVariableNames();
  1349. } else {
  1350. $1=_st(_st(aClass)._instanceVariableNames())._copyWithAll_(self._instanceVariableNamesFor_(_st(aClass)._superclass()));
  1351. };
  1352. return $1;
  1353. }, function($ctx1) {$ctx1.fill(self,"instanceVariableNamesFor:",{aClass:aClass},smalltalk.Repl)})},
  1354. args: ["aClass"],
  1355. source: "instanceVariableNamesFor: aClass\x0a\x09\x22Yields all instance variable names for the given class, including inherited ones.\x22\x0a\x09^ aClass superclass\x0a\x09\x09ifNotNil: [\x0a\x09\x09\x09aClass instanceVariableNames copyWithAll: (self instanceVariableNamesFor: aClass superclass)]\x0a\x09\x09ifNil: [\x0a\x09\x09\x09aClass instanceVariableNames]",
  1356. messageSends: ["ifNotNil:ifNil:", "copyWithAll:", "instanceVariableNamesFor:", "superclass", "instanceVariableNames"],
  1357. referencedClasses: []
  1358. }),
  1359. smalltalk.Repl);
  1360. smalltalk.addMethod(
  1361. smalltalk.method({
  1362. selector: "isIdentifier:",
  1363. category: 'private',
  1364. fn: function (aString){
  1365. var self=this;
  1366. return smalltalk.withContext(function($ctx1) {
  1367. var $1;
  1368. $1=_st(aString)._match_("^[a-z_]\x5cw+$"._asRegexp());
  1369. return $1;
  1370. }, function($ctx1) {$ctx1.fill(self,"isIdentifier:",{aString:aString},smalltalk.Repl)})},
  1371. args: ["aString"],
  1372. source: "isIdentifier: aString\x0a\x09^ aString match: '^[a-z_]\x5cw+$' asRegexp",
  1373. messageSends: ["match:", "asRegexp"],
  1374. referencedClasses: []
  1375. }),
  1376. smalltalk.Repl);
  1377. smalltalk.addMethod(
  1378. smalltalk.method({
  1379. selector: "isVariableDefined:",
  1380. category: 'private',
  1381. fn: function (aString){
  1382. var self=this;
  1383. return smalltalk.withContext(function($ctx1) {
  1384. var $1;
  1385. $1=_st(self._instanceVariableNamesFor_(_st(self["@session"])._class()))._includes_(aString);
  1386. return $1;
  1387. }, function($ctx1) {$ctx1.fill(self,"isVariableDefined:",{aString:aString},smalltalk.Repl)})},
  1388. args: ["aString"],
  1389. source: "isVariableDefined: aString\x0a\x09^ (self instanceVariableNamesFor: session class) includes: aString",
  1390. messageSends: ["includes:", "instanceVariableNamesFor:", "class"],
  1391. referencedClasses: []
  1392. }),
  1393. smalltalk.Repl);
  1394. smalltalk.addMethod(
  1395. smalltalk.method({
  1396. selector: "nextResultName",
  1397. category: 'private',
  1398. fn: function (){
  1399. var self=this;
  1400. return smalltalk.withContext(function($ctx1) {
  1401. var $1,$2;
  1402. $1=self["@resultCount"];
  1403. if(($receiver = $1) == nil || $receiver == undefined){
  1404. self["@resultCount"]=(1);
  1405. } else {
  1406. self["@resultCount"]=_st(self["@resultCount"]).__plus((1));
  1407. };
  1408. $2="res".__comma(_st(self["@resultCount"])._asString());
  1409. return $2;
  1410. }, function($ctx1) {$ctx1.fill(self,"nextResultName",{},smalltalk.Repl)})},
  1411. args: [],
  1412. source: "nextResultName\x0a\x09resultCount := resultCount\x0a \x09ifNotNil: [resultCount + 1]\x0a \x09ifNil: [1].\x0a ^ 'res', resultCount asString",
  1413. messageSends: ["ifNotNil:ifNil:", "+", ",", "asString"],
  1414. referencedClasses: []
  1415. }),
  1416. smalltalk.Repl);
  1417. smalltalk.addMethod(
  1418. smalltalk.method({
  1419. selector: "onKeyPress:",
  1420. category: 'private',
  1421. fn: function (key){
  1422. var self=this;
  1423. return smalltalk.withContext(function($ctx1) {
  1424. var $1;
  1425. $1=_st(_st(key)._ctrl())._and_((function(){
  1426. return smalltalk.withContext(function($ctx2) {
  1427. return _st(_st(key)._name()).__eq("l");
  1428. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1429. if(smalltalk.assert($1)){
  1430. self._clearScreen();
  1431. };
  1432. return self}, function($ctx1) {$ctx1.fill(self,"onKeyPress:",{key:key},smalltalk.Repl)})},
  1433. args: ["key"],
  1434. source: "onKeyPress: key\x0a\x09(key ctrl and: [key name = 'l'])\x0a\x09\x09ifTrue: [self clearScreen]",
  1435. messageSends: ["ifTrue:", "clearScreen", "and:", "=", "name", "ctrl"],
  1436. referencedClasses: []
  1437. }),
  1438. smalltalk.Repl);
  1439. smalltalk.addMethod(
  1440. smalltalk.method({
  1441. selector: "parseAssignment:do:",
  1442. category: 'private',
  1443. fn: function (aString,aBlock){
  1444. var self=this;
  1445. var assignment;
  1446. return smalltalk.withContext(function($ctx1) {
  1447. var $2,$1;
  1448. assignment=_st(_st(aString)._tokenize_(":="))._collect_((function(s){
  1449. return smalltalk.withContext(function($ctx2) {
  1450. return _st(s)._trimBoth();
  1451. }, function($ctx2) {$ctx2.fillBlock({s:s},$ctx1)})}));
  1452. $2=_st(_st(_st(assignment)._size()).__eq((2)))._and_((function(){
  1453. return smalltalk.withContext(function($ctx2) {
  1454. return self._isIdentifier_(_st(assignment)._first());
  1455. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1456. if(smalltalk.assert($2)){
  1457. $1=_st(aBlock)._value_value_(_st(assignment)._first(),_st(assignment)._last());
  1458. } else {
  1459. $1=_st(aBlock)._value_value_(nil,nil);
  1460. };
  1461. return $1;
  1462. }, function($ctx1) {$ctx1.fill(self,"parseAssignment:do:",{aString:aString,aBlock:aBlock,assignment:assignment},smalltalk.Repl)})},
  1463. args: ["aString", "aBlock"],
  1464. source: "parseAssignment: aString do: aBlock\x0a\x09\x22Assigns a new variable if the given string is an assignment expression. Calls the given block with name and value.\x0a\x09 If the string is not one no variable will be assigned and the block will be called with nil for both arguments.\x22\x0a\x09| assignment |\x0a\x09assignment := (aString tokenize: ':=') collect: [:s | s trimBoth].\x0a\x09^ (assignment size = 2 and: [self isIdentifier: assignment first])\x0a\x09\x09ifTrue: [aBlock value: assignment first value: assignment last]\x0a\x09\x09ifFalse: [aBlock value: nil value: nil]",
  1465. messageSends: ["collect:", "trimBoth", "tokenize:", "ifTrue:ifFalse:", "value:value:", "first", "last", "and:", "isIdentifier:", "=", "size"],
  1466. referencedClasses: []
  1467. }),
  1468. smalltalk.Repl);
  1469. smalltalk.addMethod(
  1470. smalltalk.method({
  1471. selector: "presentResultNamed:withValue:",
  1472. category: 'private',
  1473. fn: function (varName,value){
  1474. var self=this;
  1475. function $Transcript(){return smalltalk.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
  1476. return smalltalk.withContext(function($ctx1) {
  1477. var $1,$2;
  1478. $1=$Transcript();
  1479. _st($1)._show_(_st(_st(_st(_st(varName).__comma(": ")).__comma(_st(_st(value)._class())._name())).__comma(" = ")).__comma(_st(value)._asString()));
  1480. $2=_st($1)._cr();
  1481. _st(self["@interface"])._prompt();
  1482. return self}, function($ctx1) {$ctx1.fill(self,"presentResultNamed:withValue:",{varName:varName,value:value},smalltalk.Repl)})},
  1483. args: ["varName", "value"],
  1484. source: "presentResultNamed: varName withValue: value\x0a\x09Transcript show: varName, ': ', value class name, ' = ', value asString; cr.\x0a\x09interface prompt",
  1485. messageSends: ["show:", ",", "asString", "name", "class", "cr", "prompt"],
  1486. referencedClasses: ["Transcript"]
  1487. }),
  1488. smalltalk.Repl);
  1489. smalltalk.addMethod(
  1490. smalltalk.method({
  1491. selector: "printWelcome",
  1492. category: 'private',
  1493. fn: function (){
  1494. var self=this;
  1495. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1496. function $Transcript(){return smalltalk.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
  1497. return smalltalk.withContext(function($ctx1) {
  1498. var $1,$2;
  1499. _st($Transcript())._show_(_st(_st(_st("Welcome to Amber version ".__comma(_st(_st($Smalltalk())._current())._version())).__comma(" (NodeJS ")).__comma(_st(_st(process)._versions())._node())).__comma(")."));
  1500. $1=$Transcript();
  1501. _st($1)._show_("Type :q to exit.");
  1502. $2=_st($1)._cr();
  1503. return self}, function($ctx1) {$ctx1.fill(self,"printWelcome",{},smalltalk.Repl)})},
  1504. args: [],
  1505. source: "printWelcome\x0a\x09Transcript show: 'Welcome to Amber version ', Smalltalk current version, ' (NodeJS ', process versions node, ').'.\x0a\x09Transcript show: 'Type :q to exit.'; cr.",
  1506. messageSends: ["show:", ",", "node", "versions", "version", "current", "cr"],
  1507. referencedClasses: ["Smalltalk", "Transcript"]
  1508. }),
  1509. smalltalk.Repl);
  1510. smalltalk.addMethod(
  1511. smalltalk.method({
  1512. selector: "processLine:",
  1513. category: 'private',
  1514. fn: function (buffer){
  1515. var self=this;
  1516. var show;
  1517. return smalltalk.withContext(function($ctx1) {
  1518. var $1,$2;
  1519. show=(function(varName,value){
  1520. return smalltalk.withContext(function($ctx2) {
  1521. return self._presentResultNamed_withValue_(varName,value);
  1522. }, function($ctx2) {$ctx2.fillBlock({varName:varName,value:value},$ctx1)})});
  1523. $1=self._executeCommand_(buffer);
  1524. if(! smalltalk.assert($1)){
  1525. $2=self._isVariableDefined_(buffer);
  1526. if(smalltalk.assert($2)){
  1527. _st(show)._value_value_(buffer,_st(self["@session"])._perform_(buffer));
  1528. } else {
  1529. self._assignNewVariable_do_(buffer,show);
  1530. };
  1531. };
  1532. return self}, function($ctx1) {$ctx1.fill(self,"processLine:",{buffer:buffer,show:show},smalltalk.Repl)})},
  1533. args: ["buffer"],
  1534. source: "processLine: buffer\x0a\x09\x22Processes lines entered through the readline interface.\x22\x0a\x09| show |\x0a\x09show := [:varName :value | self presentResultNamed: varName withValue: value].\x0a\x09(self executeCommand: buffer) ifFalse: [\x0a\x09\x09(self isVariableDefined: buffer)\x0a\x09\x09\x09ifTrue: [show value: buffer value: (session perform: buffer)]\x0a\x09\x09\x09ifFalse: [self assignNewVariable: buffer do: show]]",
  1535. messageSends: ["presentResultNamed:withValue:", "ifFalse:", "ifTrue:ifFalse:", "value:value:", "perform:", "assignNewVariable:do:", "isVariableDefined:", "executeCommand:"],
  1536. referencedClasses: []
  1537. }),
  1538. smalltalk.Repl);
  1539. smalltalk.addMethod(
  1540. smalltalk.method({
  1541. selector: "prompt",
  1542. category: 'accessing',
  1543. fn: function (){
  1544. var self=this;
  1545. return smalltalk.withContext(function($ctx1) {
  1546. return "amber >> ";
  1547. }, function($ctx1) {$ctx1.fill(self,"prompt",{},smalltalk.Repl)})},
  1548. args: [],
  1549. source: "prompt\x0a\x09^'amber >> '",
  1550. messageSends: [],
  1551. referencedClasses: []
  1552. }),
  1553. smalltalk.Repl);
  1554. smalltalk.addMethod(
  1555. smalltalk.method({
  1556. selector: "setPreviousVariablesFor:from:",
  1557. category: 'private',
  1558. fn: function (newObject,oldObject){
  1559. var self=this;
  1560. return smalltalk.withContext(function($ctx1) {
  1561. _st(self._instanceVariableNamesFor_(_st(oldObject)._class()))._do_((function(each){
  1562. return smalltalk.withContext(function($ctx2) {
  1563. return _st(newObject)._perform_withArguments_(_st(each).__comma(":"),[_st(oldObject)._perform_(each)]);
  1564. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1565. return self}, function($ctx1) {$ctx1.fill(self,"setPreviousVariablesFor:from:",{newObject:newObject,oldObject:oldObject},smalltalk.Repl)})},
  1566. args: ["newObject", "oldObject"],
  1567. source: "setPreviousVariablesFor: newObject from: oldObject\x0a\x09(self instanceVariableNamesFor: oldObject class) do: [:each |\x0a\x09\x09newObject perform: each, ':' withArguments: {oldObject perform: each}].",
  1568. messageSends: ["do:", "perform:withArguments:", ",", "perform:", "instanceVariableNamesFor:", "class"],
  1569. referencedClasses: []
  1570. }),
  1571. smalltalk.Repl);
  1572. smalltalk.addMethod(
  1573. smalltalk.method({
  1574. selector: "setPrompt",
  1575. category: 'actions',
  1576. fn: function (){
  1577. var self=this;
  1578. return smalltalk.withContext(function($ctx1) {
  1579. _st(self["@interface"])._setPrompt_(self._prompt());
  1580. return self}, function($ctx1) {$ctx1.fill(self,"setPrompt",{},smalltalk.Repl)})},
  1581. args: [],
  1582. source: "setPrompt\x0a\x09interface setPrompt: self prompt",
  1583. messageSends: ["setPrompt:", "prompt"],
  1584. referencedClasses: []
  1585. }),
  1586. smalltalk.Repl);
  1587. smalltalk.addMethod(
  1588. smalltalk.method({
  1589. selector: "setupCommands",
  1590. category: 'initialization',
  1591. fn: function (){
  1592. var self=this;
  1593. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  1594. return smalltalk.withContext(function($ctx1) {
  1595. self["@commands"]=_st($Dictionary())._from_([_st([":q"]).__minus_gt((function(){
  1596. return smalltalk.withContext(function($ctx2) {
  1597. return _st(process)._exit();
  1598. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})),_st([""]).__minus_gt((function(){
  1599. return smalltalk.withContext(function($ctx2) {
  1600. return _st(self["@interface"])._prompt();
  1601. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))]);
  1602. return self}, function($ctx1) {$ctx1.fill(self,"setupCommands",{},smalltalk.Repl)})},
  1603. args: [],
  1604. source: "setupCommands\x0a\x09commands := Dictionary from: {\x0a\x09\x09{':q'} -> [process exit].\x0a\x09\x09{''} -> [interface prompt]}",
  1605. messageSends: ["from:", "->", "exit", "prompt"],
  1606. referencedClasses: ["Dictionary"]
  1607. }),
  1608. smalltalk.Repl);
  1609. smalltalk.addMethod(
  1610. smalltalk.method({
  1611. selector: "setupHotkeys",
  1612. category: 'initialization',
  1613. fn: function (){
  1614. var self=this;
  1615. return smalltalk.withContext(function($ctx1) {
  1616. var $1;
  1617. _st(_st(process)._stdin())._on_do_("keypress",(function(s,key){
  1618. return smalltalk.withContext(function($ctx2) {
  1619. $1=key;
  1620. if(($receiver = $1) == nil || $receiver == undefined){
  1621. return $1;
  1622. } else {
  1623. return self._onKeyPress_(key);
  1624. };
  1625. }, function($ctx2) {$ctx2.fillBlock({s:s,key:key},$ctx1)})}));
  1626. return self}, function($ctx1) {$ctx1.fill(self,"setupHotkeys",{},smalltalk.Repl)})},
  1627. args: [],
  1628. source: "setupHotkeys\x0a\x09process stdin on: 'keypress' do: [:s :key | key ifNotNil: [self onKeyPress: key]].",
  1629. messageSends: ["on:do:", "ifNotNil:", "onKeyPress:", "stdin"],
  1630. referencedClasses: []
  1631. }),
  1632. smalltalk.Repl);
  1633. smalltalk.addMethod(
  1634. smalltalk.method({
  1635. selector: "subclass:withVariable:",
  1636. category: 'private',
  1637. fn: function (aClass,varName){
  1638. var self=this;
  1639. function $ClassBuilder(){return smalltalk.ClassBuilder||(typeof ClassBuilder=="undefined"?nil:ClassBuilder)}
  1640. return smalltalk.withContext(function($ctx1) {
  1641. var $1;
  1642. $1=_st(_st($ClassBuilder())._new())._addSubclassOf_named_instanceVariableNames_package_(aClass,_st(self._subclassNameFor_(aClass))._asSymbol(),[varName],"Compiler-Core");
  1643. return $1;
  1644. }, function($ctx1) {$ctx1.fill(self,"subclass:withVariable:",{aClass:aClass,varName:varName},smalltalk.Repl)})},
  1645. args: ["aClass", "varName"],
  1646. source: "subclass: aClass withVariable: varName\x0a\x09\x22Create subclass with new variable.\x22\x0a\x09^ ClassBuilder new\x0a\x09\x09addSubclassOf: aClass\x0a\x09\x09named: (self subclassNameFor: aClass) asSymbol\x0a\x09\x09instanceVariableNames: {varName}\x0a\x09\x09package: 'Compiler-Core'",
  1647. messageSends: ["addSubclassOf:named:instanceVariableNames:package:", "asSymbol", "subclassNameFor:", "new"],
  1648. referencedClasses: ["ClassBuilder"]
  1649. }),
  1650. smalltalk.Repl);
  1651. smalltalk.addMethod(
  1652. smalltalk.method({
  1653. selector: "subclassNameFor:",
  1654. category: 'private',
  1655. fn: function (aClass){
  1656. var self=this;
  1657. return smalltalk.withContext(function($ctx1) {
  1658. var $2,$1;
  1659. $2=_st(_st(aClass)._name())._matchesOf_("\x5cd+$");
  1660. if(($receiver = $2) == nil || $receiver == undefined){
  1661. $1=_st(_st(aClass)._name()).__comma("2");
  1662. } else {
  1663. var counter;
  1664. counter=_st(_st(_st(_st(_st(aClass)._name())._matchesOf_("\x5cd+$"))._first())._asNumber()).__plus((1));
  1665. counter;
  1666. $1=_st(_st(aClass)._name())._replaceRegexp_with_("\x5cd+$"._asRegexp(),_st(counter)._asString());
  1667. };
  1668. return $1;
  1669. }, function($ctx1) {$ctx1.fill(self,"subclassNameFor:",{aClass:aClass},smalltalk.Repl)})},
  1670. args: ["aClass"],
  1671. source: "subclassNameFor: aClass\x0a\x09^ (aClass name matchesOf: '\x5cd+$')\x0a\x09\x09ifNotNil: [ | counter |\x0a\x09\x09\x09counter := (aClass name matchesOf: '\x5cd+$') first asNumber + 1.\x0a\x09\x09\x09aClass name replaceRegexp: '\x5cd+$' asRegexp with: counter asString]\x0a\x09\x09ifNil: [\x0a\x09\x09\x09aClass name, '2'].",
  1672. messageSends: ["ifNotNil:ifNil:", "+", "asNumber", "first", "matchesOf:", "name", "replaceRegexp:with:", "asRegexp", "asString", ","],
  1673. referencedClasses: []
  1674. }),
  1675. smalltalk.Repl);
  1676. smalltalk.addMethod(
  1677. smalltalk.method({
  1678. selector: "main",
  1679. category: 'initialization',
  1680. fn: function (){
  1681. var self=this;
  1682. return smalltalk.withContext(function($ctx1) {
  1683. _st(self._new())._createInterface();
  1684. return self}, function($ctx1) {$ctx1.fill(self,"main",{},smalltalk.Repl.klass)})},
  1685. args: [],
  1686. source: "main\x0a\x09self new createInterface",
  1687. messageSends: ["createInterface", "new"],
  1688. referencedClasses: []
  1689. }),
  1690. smalltalk.Repl.klass);
  1691. });