2
0

AmberCli.js 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  1. smalltalk.addPackage('AmberCli');
  2. smalltalk.addClass('AmberCli', smalltalk.Object, [], 'AmberCli');
  3. smalltalk.AmberCli.comment="I am the Amber CLI (CommandLine Interface) tool which runs on Node.js.\x0a\x0aMy responsibility is to start different Amber programs like the FileServer or the Repl.\x0aWhich program to start is determined by the first commandline parameters passed to the AmberCli executable.\x0aUse `help` to get a list of all available options.\x0aAny further commandline parameters are passed to the specific program.\x0a\x0a## Commands\x0a\x0aNew commands can be added by creating a class side method in the `commands` protocol which takes one parameter.\x0aThis parameter is an array of all commandline options + values passed on to the program.\x0aAny `camelCaseCommand` is transformed into a commandline parameter of the form `camel-case-command` and vice versa.";
  4. smalltalk.addMethod(
  5. smalltalk.method({
  6. selector: "commandLineSwitches",
  7. category: 'commandline',
  8. fn: function (){
  9. var self=this;
  10. var switches;
  11. return smalltalk.withContext(function($ctx1) {
  12. var $1;
  13. switches=_st(_st(self._class())._methodsInProtocol_("commands"))._collect_((function(each){
  14. return smalltalk.withContext(function($ctx2) {
  15. return _st(each)._selector();
  16. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  17. switches=_st(switches)._select_((function(each){
  18. return smalltalk.withContext(function($ctx2) {
  19. return _st(each)._match_("^[^:]*:$");
  20. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  21. switches=_st(switches)._collect_((function(each){
  22. return smalltalk.withContext(function($ctx2) {
  23. return _st(_st(_st(each)._allButLast())._replace_with_("([A-Z])","-$1"))._asLowercase();
  24. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  25. $1=switches;
  26. return $1;
  27. }, function($ctx1) {$ctx1.fill(self,"commandLineSwitches",{switches:switches},smalltalk.AmberCli.klass)})},
  28. args: [],
  29. source: "commandLineSwitches\x0a\x09\x22Collect all methodnames from the 'commands' protocol of the class\x0a\x09 and select the ones with only one parameter.\x0a\x09 Then remove the ':' at the end of the name.\x0a\x09 Additionally all uppercase letters are made lowercase and preceded by a '-'.\x0a\x09 Example: fallbackPage: becomes --fallback-page.\x0a\x09 Return the Array containing the commandline switches.\x22\x0a\x09| switches |\x0a\x09switches := ((self class methodsInProtocol: 'commands') collect: [ :each | each selector]).\x0a\x09switches := switches select: [ :each | each match: '^[^:]*:$'].\x0a\x09switches :=switches collect: [ :each |\x0a\x09\x09(each allButLast replace: '([A-Z])' with: '-$1') asLowercase].\x0a\x09^switches",
  30. messageSends: ["collect:", "selector", "methodsInProtocol:", "class", "select:", "match:", "asLowercase", "replace:with:", "allButLast"],
  31. referencedClasses: []
  32. }),
  33. smalltalk.AmberCli.klass);
  34. smalltalk.addMethod(
  35. smalltalk.method({
  36. selector: "handleArguments:",
  37. category: 'commandline',
  38. fn: function (args){
  39. var self=this;
  40. var selector;
  41. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  42. return smalltalk.withContext(function($ctx1) {
  43. selector=self._selectorForCommandLineSwitch_(_st(args)._first());
  44. _st(args)._remove_(_st(args)._first());
  45. self._perform_withArguments_(selector,_st($Array())._with_(args));
  46. return self}, function($ctx1) {$ctx1.fill(self,"handleArguments:",{args:args,selector:selector},smalltalk.AmberCli.klass)})},
  47. args: ["args"],
  48. source: "handleArguments: args\x0a\x09| selector |\x0a\x0a\x09selector := self selectorForCommandLineSwitch: (args first).\x0a\x09args remove: args first.\x0a\x09self perform: selector withArguments: (Array with: args)",
  49. messageSends: ["selectorForCommandLineSwitch:", "first", "remove:", "perform:withArguments:", "with:"],
  50. referencedClasses: ["Array"]
  51. }),
  52. smalltalk.AmberCli.klass);
  53. smalltalk.addMethod(
  54. smalltalk.method({
  55. selector: "help:",
  56. category: 'commands',
  57. fn: function (args){
  58. var self=this;
  59. return smalltalk.withContext(function($ctx1) {
  60. _st(console)._log_("Available Commands:");
  61. _st(self._commandLineSwitches())._do_((function(each){
  62. return smalltalk.withContext(function($ctx2) {
  63. return _st(console)._log_(each);
  64. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  65. return self}, function($ctx1) {$ctx1.fill(self,"help:",{args:args},smalltalk.AmberCli.klass)})},
  66. args: ["args"],
  67. source: "help: args\x0a\x09console log: 'Available Commands:'.\x0a\x09self commandLineSwitches do: [ :each | console log: each ]",
  68. messageSends: ["log:", "do:", "commandLineSwitches"],
  69. referencedClasses: []
  70. }),
  71. smalltalk.AmberCli.klass);
  72. smalltalk.addMethod(
  73. smalltalk.method({
  74. selector: "main",
  75. category: 'startup',
  76. fn: function (){
  77. var self=this;
  78. var args,nodeMinorVersion;
  79. return smalltalk.withContext(function($ctx1) {
  80. var $1,$2,$3;
  81. nodeMinorVersion=_st(_st(_st(_st(process)._version())._tokenize_("."))._second())._asNumber();
  82. $1=_st(nodeMinorVersion).__lt((8));
  83. if(smalltalk.assert($1)){
  84. _st(console)._log_("You are currently using Node.js ".__comma(_st(process)._version()));
  85. _st(console)._log_("Required is at least Node.js v0.8.x or greater.");
  86. return (-1);
  87. };
  88. args=_st(process)._argv();
  89. _st(args)._removeFrom_to_((1),(3));
  90. $2=_st(args)._isEmpty();
  91. if(smalltalk.assert($2)){
  92. self._help_(nil);
  93. } else {
  94. $3=self._handleArguments_(args);
  95. return $3;
  96. };
  97. return self}, function($ctx1) {$ctx1.fill(self,"main",{args:args,nodeMinorVersion:nodeMinorVersion},smalltalk.AmberCli.klass)})},
  98. args: [],
  99. 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: 3.\x0a\x09\x0a\x09(args isEmpty)\x0a\x09\x09ifTrue: [self help: nil]\x0a\x09\x09ifFalse: [^self handleArguments: args]",
  100. messageSends: ["asNumber", "second", "tokenize:", "version", "ifTrue:", "log:", ",", "<", "argv", "removeFrom:to:", "ifTrue:ifFalse:", "help:", "handleArguments:", "isEmpty"],
  101. referencedClasses: []
  102. }),
  103. smalltalk.AmberCli.klass);
  104. smalltalk.addMethod(
  105. smalltalk.method({
  106. selector: "repl:",
  107. category: 'commands',
  108. fn: function (args){
  109. var self=this;
  110. function $Repl(){return smalltalk.Repl||(typeof Repl=="undefined"?nil:Repl)}
  111. return smalltalk.withContext(function($ctx1) {
  112. var $1;
  113. $1=_st(_st($Repl())._new())._createInterface();
  114. return $1;
  115. }, function($ctx1) {$ctx1.fill(self,"repl:",{args:args},smalltalk.AmberCli.klass)})},
  116. args: ["args"],
  117. source: "repl: args\x0a\x09^Repl new createInterface",
  118. messageSends: ["createInterface", "new"],
  119. referencedClasses: ["Repl"]
  120. }),
  121. smalltalk.AmberCli.klass);
  122. smalltalk.addMethod(
  123. smalltalk.method({
  124. selector: "selectorForCommandLineSwitch:",
  125. category: 'commandline',
  126. fn: function (aSwitch){
  127. var self=this;
  128. var command,selector;
  129. return smalltalk.withContext(function($ctx1) {
  130. var $1,$2;
  131. $1=_st(self._commandLineSwitches())._includes_(aSwitch);
  132. if(smalltalk.assert($1)){
  133. selector=_st(_st(aSwitch)._replace_with_("-[a-z]",(function(each){
  134. return smalltalk.withContext(function($ctx2) {
  135. return _st(_st(each)._second())._asUppercase();
  136. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}))).__comma(":");
  137. selector;
  138. } else {
  139. selector="help:";
  140. selector;
  141. };
  142. $2=selector;
  143. return $2;
  144. }, function($ctx1) {$ctx1.fill(self,"selectorForCommandLineSwitch:",{aSwitch:aSwitch,command:command,selector:selector},smalltalk.AmberCli.klass)})},
  145. args: ["aSwitch"],
  146. 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",
  147. messageSends: ["ifTrue:ifFalse:", ",", "replace:with:", "asUppercase", "second", "includes:", "commandLineSwitches"],
  148. referencedClasses: []
  149. }),
  150. smalltalk.AmberCli.klass);
  151. smalltalk.addMethod(
  152. smalltalk.method({
  153. selector: "serve:",
  154. category: 'commands',
  155. fn: function (args){
  156. var self=this;
  157. function $FileServer(){return smalltalk.FileServer||(typeof FileServer=="undefined"?nil:FileServer)}
  158. return smalltalk.withContext(function($ctx1) {
  159. var $1;
  160. $1=_st(_st($FileServer())._createServerWithArguments_(args))._start();
  161. return $1;
  162. }, function($ctx1) {$ctx1.fill(self,"serve:",{args:args},smalltalk.AmberCli.klass)})},
  163. args: ["args"],
  164. source: "serve: args\x0a\x09^(FileServer createServerWithArguments: args) start",
  165. messageSends: ["start", "createServerWithArguments:"],
  166. referencedClasses: ["FileServer"]
  167. }),
  168. smalltalk.AmberCli.klass);
  169. smalltalk.addClass('FileServer', smalltalk.Object, ['path', 'http', 'fs', 'url', 'host', 'port', 'basePath', 'util', 'username', 'password', 'fallbackPage'], 'AmberCli');
  170. 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.";
  171. smalltalk.addMethod(
  172. smalltalk.method({
  173. selector: "base64Decode:",
  174. category: 'private',
  175. fn: function (aString){
  176. var self=this;
  177. return smalltalk.withContext(function($ctx1) {
  178. return (new Buffer(aString, 'base64').toString());
  179. return self}, function($ctx1) {$ctx1.fill(self,"base64Decode:",{aString:aString},smalltalk.FileServer)})},
  180. args: ["aString"],
  181. source: "base64Decode: aString\x0a\x09<return (new Buffer(aString, 'base64').toString())>",
  182. messageSends: [],
  183. referencedClasses: []
  184. }),
  185. smalltalk.FileServer);
  186. smalltalk.addMethod(
  187. smalltalk.method({
  188. selector: "basePath",
  189. category: 'accessing',
  190. fn: function (){
  191. var self=this;
  192. return smalltalk.withContext(function($ctx1) {
  193. var $2,$1;
  194. $2=self["@basePath"];
  195. if(($receiver = $2) == nil || $receiver == undefined){
  196. $1="./";
  197. } else {
  198. $1=$2;
  199. };
  200. return $1;
  201. }, function($ctx1) {$ctx1.fill(self,"basePath",{},smalltalk.FileServer)})},
  202. args: [],
  203. source: "basePath\x0a\x09^basePath ifNil: ['./']",
  204. messageSends: ["ifNil:"],
  205. referencedClasses: []
  206. }),
  207. smalltalk.FileServer);
  208. smalltalk.addMethod(
  209. smalltalk.method({
  210. selector: "basePath:",
  211. category: 'accessing',
  212. fn: function (aString){
  213. var self=this;
  214. return smalltalk.withContext(function($ctx1) {
  215. self["@basePath"]=aString;
  216. return self}, function($ctx1) {$ctx1.fill(self,"basePath:",{aString:aString},smalltalk.FileServer)})},
  217. args: ["aString"],
  218. source: "basePath: aString\x0a\x09basePath := aString",
  219. messageSends: [],
  220. referencedClasses: []
  221. }),
  222. smalltalk.FileServer);
  223. smalltalk.addMethod(
  224. smalltalk.method({
  225. selector: "checkDirectoryLayout",
  226. category: 'initialization',
  227. fn: function (){
  228. var self=this;
  229. return smalltalk.withContext(function($ctx1) {
  230. var $1,$2,$3;
  231. $1=_st(self["@fs"])._existsSync_(_st(self._basePath()).__comma("index.html"));
  232. if(! smalltalk.assert($1)){
  233. _st(console)._warn_("Warning: project directory does not contain index.html");
  234. };
  235. $2=_st(self["@fs"])._existsSync_(_st(self._basePath()).__comma("st"));
  236. if(! smalltalk.assert($2)){
  237. _st(console)._warn_("Warning: project directory is missing an \x22st\x22 directory");
  238. };
  239. $3=_st(self["@fs"])._existsSync_(_st(self._basePath()).__comma("js"));
  240. if(! smalltalk.assert($3)){
  241. _st(console)._warn_("Warning: project directory is missing a \x22js\x22 directory");
  242. };
  243. return self}, function($ctx1) {$ctx1.fill(self,"checkDirectoryLayout",{},smalltalk.FileServer)})},
  244. args: [],
  245. 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'].",
  246. messageSends: ["ifFalse:", "warn:", "existsSync:", ",", "basePath"],
  247. referencedClasses: []
  248. }),
  249. smalltalk.FileServer);
  250. smalltalk.addMethod(
  251. smalltalk.method({
  252. selector: "fallbackPage",
  253. category: 'accessing',
  254. fn: function (){
  255. var self=this;
  256. return smalltalk.withContext(function($ctx1) {
  257. var $1;
  258. $1=self["@fallbackPage"];
  259. return $1;
  260. }, function($ctx1) {$ctx1.fill(self,"fallbackPage",{},smalltalk.FileServer)})},
  261. args: [],
  262. source: "fallbackPage\x0a\x09^fallbackPage",
  263. messageSends: [],
  264. referencedClasses: []
  265. }),
  266. smalltalk.FileServer);
  267. smalltalk.addMethod(
  268. smalltalk.method({
  269. selector: "fallbackPage:",
  270. category: 'accessing',
  271. fn: function (aString){
  272. var self=this;
  273. return smalltalk.withContext(function($ctx1) {
  274. self["@fallbackPage"]=aString;
  275. return self}, function($ctx1) {$ctx1.fill(self,"fallbackPage:",{aString:aString},smalltalk.FileServer)})},
  276. args: ["aString"],
  277. source: "fallbackPage: aString\x0a\x09fallbackPage := aString",
  278. messageSends: [],
  279. referencedClasses: []
  280. }),
  281. smalltalk.FileServer);
  282. smalltalk.addMethod(
  283. smalltalk.method({
  284. selector: "handleGETRequest:respondTo:",
  285. category: 'request handling',
  286. fn: function (aRequest,aResponse){
  287. var self=this;
  288. var uri,filename;
  289. return smalltalk.withContext(function($ctx1) {
  290. var $1;
  291. uri=_st(_st(self["@url"])._parse_(_st(aRequest)._url()))._pathname();
  292. filename=_st(self["@path"])._join_with_(self._basePath(),uri);
  293. _st(self["@fs"])._exists_do_(filename,(function(aBoolean){
  294. return smalltalk.withContext(function($ctx2) {
  295. $1=aBoolean;
  296. if(smalltalk.assert($1)){
  297. return self._respondFileNamed_to_(filename,aResponse);
  298. } else {
  299. return self._respondNotFoundTo_(aResponse);
  300. };
  301. }, function($ctx2) {$ctx2.fillBlock({aBoolean:aBoolean},$ctx1)})}));
  302. return self}, function($ctx1) {$ctx1.fill(self,"handleGETRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse,uri:uri,filename:filename},smalltalk.FileServer)})},
  303. args: ["aRequest", "aResponse"],
  304. 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]]",
  305. messageSends: ["pathname", "parse:", "url", "join:with:", "basePath", "exists:do:", "ifFalse:ifTrue:", "respondNotFoundTo:", "respondFileNamed:to:"],
  306. referencedClasses: []
  307. }),
  308. smalltalk.FileServer);
  309. smalltalk.addMethod(
  310. smalltalk.method({
  311. selector: "handleOPTIONSRequest:respondTo:",
  312. category: 'request handling',
  313. fn: function (aRequest,aResponse){
  314. var self=this;
  315. return smalltalk.withContext(function($ctx1) {
  316. _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))]));
  317. _st(aResponse)._end();
  318. return self}, function($ctx1) {$ctx1.fill(self,"handleOPTIONSRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse},smalltalk.FileServer)})},
  319. args: ["aRequest", "aResponse"],
  320. 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",
  321. messageSends: ["writeHead:options:", "->", "end"],
  322. referencedClasses: []
  323. }),
  324. smalltalk.FileServer);
  325. smalltalk.addMethod(
  326. smalltalk.method({
  327. selector: "handlePUTRequest:respondTo:",
  328. category: 'request handling',
  329. fn: function (aRequest,aResponse){
  330. var self=this;
  331. var file,stream;
  332. return smalltalk.withContext(function($ctx1) {
  333. var $1,$2;
  334. $1=self._isAuthenticated_(aRequest);
  335. if(! smalltalk.assert($1)){
  336. self._respondAuthenticationRequiredTo_(aResponse);
  337. return nil;
  338. };
  339. file=".".__comma(_st(aRequest)._url());
  340. stream=_st(self["@fs"])._createWriteStream_(file);
  341. _st(stream)._on_do_("error",(function(error){
  342. return smalltalk.withContext(function($ctx2) {
  343. _st(console)._warn_("Error creating WriteStream for file ".__comma(file));
  344. _st(console)._warn_(" Did you forget to create the necessary js/ or st/ directory in your project?");
  345. _st(console)._warn_(" The exact error is: ".__comma(error));
  346. return self._respondNotCreatedTo_(aResponse);
  347. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1)})}));
  348. _st(stream)._on_do_("close",(function(){
  349. return smalltalk.withContext(function($ctx2) {
  350. return self._respondCreatedTo_(aResponse);
  351. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  352. _st(aRequest)._setEncoding_("utf8");
  353. _st(aRequest)._on_do_("data",(function(data){
  354. return smalltalk.withContext(function($ctx2) {
  355. return _st(stream)._write_(data);
  356. }, function($ctx2) {$ctx2.fillBlock({data:data},$ctx1)})}));
  357. _st(aRequest)._on_do_("end",(function(){
  358. return smalltalk.withContext(function($ctx2) {
  359. $2=_st(stream)._writable();
  360. if(smalltalk.assert($2)){
  361. return _st(stream)._end();
  362. };
  363. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  364. return self}, function($ctx1) {$ctx1.fill(self,"handlePUTRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse,file:file,stream:stream},smalltalk.FileServer)})},
  365. args: ["aRequest", "aResponse"],
  366. 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]]",
  367. messageSends: ["ifFalse:", "respondAuthenticationRequiredTo:", "isAuthenticated:", ",", "url", "createWriteStream:", "on:do:", "warn:", "respondNotCreatedTo:", "respondCreatedTo:", "setEncoding:", "write:", "ifTrue:", "end", "writable"],
  368. referencedClasses: []
  369. }),
  370. smalltalk.FileServer);
  371. smalltalk.addMethod(
  372. smalltalk.method({
  373. selector: "handleRequest:respondTo:",
  374. category: 'request handling',
  375. fn: function (aRequest,aResponse){
  376. var self=this;
  377. return smalltalk.withContext(function($ctx1) {
  378. var $1,$2,$3;
  379. $1=_st(_st(aRequest)._method()).__eq("PUT");
  380. if(smalltalk.assert($1)){
  381. self._handlePUTRequest_respondTo_(aRequest,aResponse);
  382. };
  383. $2=_st(_st(aRequest)._method()).__eq("GET");
  384. if(smalltalk.assert($2)){
  385. self._handleGETRequest_respondTo_(aRequest,aResponse);
  386. };
  387. $3=_st(_st(aRequest)._method()).__eq("OPTIONS");
  388. if(smalltalk.assert($3)){
  389. self._handleOPTIONSRequest_respondTo_(aRequest,aResponse);
  390. };
  391. return self}, function($ctx1) {$ctx1.fill(self,"handleRequest:respondTo:",{aRequest:aRequest,aResponse:aResponse},smalltalk.FileServer)})},
  392. args: ["aRequest", "aResponse"],
  393. 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]",
  394. messageSends: ["ifTrue:", "handlePUTRequest:respondTo:", "=", "method", "handleGETRequest:respondTo:", "handleOPTIONSRequest:respondTo:"],
  395. referencedClasses: []
  396. }),
  397. smalltalk.FileServer);
  398. smalltalk.addMethod(
  399. smalltalk.method({
  400. selector: "host",
  401. category: 'accessing',
  402. fn: function (){
  403. var self=this;
  404. return smalltalk.withContext(function($ctx1) {
  405. var $1;
  406. $1=self["@host"];
  407. return $1;
  408. }, function($ctx1) {$ctx1.fill(self,"host",{},smalltalk.FileServer)})},
  409. args: [],
  410. source: "host\x0a\x09^host",
  411. messageSends: [],
  412. referencedClasses: []
  413. }),
  414. smalltalk.FileServer);
  415. smalltalk.addMethod(
  416. smalltalk.method({
  417. selector: "host:",
  418. category: 'accessing',
  419. fn: function (hostname){
  420. var self=this;
  421. return smalltalk.withContext(function($ctx1) {
  422. self["@host"]=hostname;
  423. return self}, function($ctx1) {$ctx1.fill(self,"host:",{hostname:hostname},smalltalk.FileServer)})},
  424. args: ["hostname"],
  425. source: "host: hostname\x0a\x09host := hostname",
  426. messageSends: [],
  427. referencedClasses: []
  428. }),
  429. smalltalk.FileServer);
  430. smalltalk.addMethod(
  431. smalltalk.method({
  432. selector: "initialize",
  433. category: 'initialization',
  434. fn: function (){
  435. var self=this;
  436. return smalltalk.withContext(function($ctx1) {
  437. smalltalk.Object.fn.prototype._initialize.apply(_st(self), []);
  438. self["@path"]=self._require_("path");
  439. self["@http"]=self._require_("http");
  440. self["@fs"]=self._require_("fs");
  441. self["@util"]=self._require_("util");
  442. self["@url"]=self._require_("url");
  443. self["@host"]=_st(self._class())._defaultHost();
  444. self["@port"]=_st(self._class())._defaultPort();
  445. self["@username"]=nil;
  446. self["@password"]=nil;
  447. self["@fallbackPage"]=nil;
  448. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.FileServer)})},
  449. args: [],
  450. 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.",
  451. messageSends: ["initialize", "require:", "defaultHost", "class", "defaultPort"],
  452. referencedClasses: []
  453. }),
  454. smalltalk.FileServer);
  455. smalltalk.addMethod(
  456. smalltalk.method({
  457. selector: "isAuthenticated:",
  458. category: 'private',
  459. fn: function (aRequest){
  460. var self=this;
  461. var header,token,auth,parts;
  462. return smalltalk.withContext(function($ctx1) {
  463. var $1,$2,$3,$4,$5;
  464. $1=_st(_st(self["@username"])._isNil())._and_((function(){
  465. return smalltalk.withContext(function($ctx2) {
  466. return _st(self["@password"])._isNil();
  467. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  468. if(smalltalk.assert($1)){
  469. return true;
  470. };
  471. $2=_st(_st(aRequest)._headers())._at_("authorization");
  472. if(($receiver = $2) == nil || $receiver == undefined){
  473. header="";
  474. } else {
  475. header=$2;
  476. };
  477. $3=_st(header)._isEmpty();
  478. if(smalltalk.assert($3)){
  479. return false;
  480. } else {
  481. $4=_st(header)._tokenize_(" ");
  482. if(($receiver = $4) == nil || $receiver == undefined){
  483. token="";
  484. } else {
  485. token=$4;
  486. };
  487. token;
  488. auth=self._base64Decode_(_st(token)._at_((2)));
  489. auth;
  490. parts=_st(auth)._tokenize_(":");
  491. parts;
  492. $5=_st(_st(self["@username"]).__eq(_st(parts)._at_((1))))._and_((function(){
  493. return smalltalk.withContext(function($ctx2) {
  494. return _st(self["@password"]).__eq(_st(parts)._at_((2)));
  495. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  496. if(smalltalk.assert($5)){
  497. return true;
  498. } else {
  499. return false;
  500. };
  501. };
  502. return self}, function($ctx1) {$ctx1.fill(self,"isAuthenticated:",{aRequest:aRequest,header:header,token:token,auth:auth,parts:parts},smalltalk.FileServer)})},
  503. args: ["aRequest"],
  504. 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].",
  505. messageSends: ["ifTrue:", "and:", "isNil", "ifNil:", "at:", "headers", "ifTrue:ifFalse:", "tokenize:", "base64Decode:", "=", "isEmpty"],
  506. referencedClasses: []
  507. }),
  508. smalltalk.FileServer);
  509. smalltalk.addMethod(
  510. smalltalk.method({
  511. selector: "password:",
  512. category: 'accessing',
  513. fn: function (aPassword){
  514. var self=this;
  515. return smalltalk.withContext(function($ctx1) {
  516. self["@password"]=aPassword;
  517. return self}, function($ctx1) {$ctx1.fill(self,"password:",{aPassword:aPassword},smalltalk.FileServer)})},
  518. args: ["aPassword"],
  519. source: "password: aPassword\x0a\x09password := aPassword.",
  520. messageSends: [],
  521. referencedClasses: []
  522. }),
  523. smalltalk.FileServer);
  524. smalltalk.addMethod(
  525. smalltalk.method({
  526. selector: "port",
  527. category: 'accessing',
  528. fn: function (){
  529. var self=this;
  530. return smalltalk.withContext(function($ctx1) {
  531. var $1;
  532. $1=self["@port"];
  533. return $1;
  534. }, function($ctx1) {$ctx1.fill(self,"port",{},smalltalk.FileServer)})},
  535. args: [],
  536. source: "port\x0a\x09^port",
  537. messageSends: [],
  538. referencedClasses: []
  539. }),
  540. smalltalk.FileServer);
  541. smalltalk.addMethod(
  542. smalltalk.method({
  543. selector: "port:",
  544. category: 'accessing',
  545. fn: function (aNumber){
  546. var self=this;
  547. return smalltalk.withContext(function($ctx1) {
  548. self["@port"]=aNumber;
  549. return self}, function($ctx1) {$ctx1.fill(self,"port:",{aNumber:aNumber},smalltalk.FileServer)})},
  550. args: ["aNumber"],
  551. source: "port: aNumber\x0a\x09port := aNumber",
  552. messageSends: [],
  553. referencedClasses: []
  554. }),
  555. smalltalk.FileServer);
  556. smalltalk.addMethod(
  557. smalltalk.method({
  558. selector: "require:",
  559. category: 'private',
  560. fn: function (aModuleString){
  561. var self=this;
  562. return smalltalk.withContext(function($ctx1) {
  563. var $1;
  564. $1=_st(require)._value_(aModuleString);
  565. return $1;
  566. }, function($ctx1) {$ctx1.fill(self,"require:",{aModuleString:aModuleString},smalltalk.FileServer)})},
  567. args: ["aModuleString"],
  568. source: "require: aModuleString\x0a\x09\x22call to the require function\x22\x0a\x09^require value: aModuleString",
  569. messageSends: ["value:"],
  570. referencedClasses: []
  571. }),
  572. smalltalk.FileServer);
  573. smalltalk.addMethod(
  574. smalltalk.method({
  575. selector: "respondAuthenticationRequiredTo:",
  576. category: 'request handling',
  577. fn: function (aResponse){
  578. var self=this;
  579. return smalltalk.withContext(function($ctx1) {
  580. var $1,$2;
  581. $1=aResponse;
  582. _st($1)._writeHead_options_((401),smalltalk.HashedCollection._from_(["WWW-Authenticate".__minus_gt("Basic realm=\x22Secured Developer Area\x22")]));
  583. _st($1)._write_("<html><body>Authentication needed</body></html>");
  584. $2=_st($1)._end();
  585. return self}, function($ctx1) {$ctx1.fill(self,"respondAuthenticationRequiredTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  586. args: ["aResponse"],
  587. 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.",
  588. messageSends: ["writeHead:options:", "->", "write:", "end"],
  589. referencedClasses: []
  590. }),
  591. smalltalk.FileServer);
  592. smalltalk.addMethod(
  593. smalltalk.method({
  594. selector: "respondCreatedTo:",
  595. category: 'request handling',
  596. fn: function (aResponse){
  597. var self=this;
  598. return smalltalk.withContext(function($ctx1) {
  599. var $1,$2;
  600. $1=aResponse;
  601. _st($1)._writeHead_options_((201),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain"),"Access-Control-Allow-Origin".__minus_gt("*")]));
  602. $2=_st($1)._end();
  603. return self}, function($ctx1) {$ctx1.fill(self,"respondCreatedTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  604. args: ["aResponse"],
  605. source: "respondCreatedTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 201 options: #{'Content-Type' -> 'text/plain'. 'Access-Control-Allow-Origin' -> '*'};\x0a\x09\x09end.",
  606. messageSends: ["writeHead:options:", "->", "end"],
  607. referencedClasses: []
  608. }),
  609. smalltalk.FileServer);
  610. smalltalk.addMethod(
  611. smalltalk.method({
  612. selector: "respondFileNamed:to:",
  613. category: 'request handling',
  614. fn: function (aFilename,aResponse){
  615. var self=this;
  616. var type,filename;
  617. return smalltalk.withContext(function($ctx1) {
  618. var $1,$2,$3,$4,$5;
  619. filename=aFilename;
  620. $1=_st(_st(self["@fs"])._statSync_(aFilename))._isDirectory();
  621. if(smalltalk.assert($1)){
  622. filename=_st(filename).__comma("index.html");
  623. filename;
  624. };
  625. _st(self["@fs"])._readFile_do_(filename,(function(ex,file){
  626. return smalltalk.withContext(function($ctx2) {
  627. $2=_st(ex)._notNil();
  628. if(smalltalk.assert($2)){
  629. _st(console)._log_(_st(filename).__comma(" does not exist"));
  630. return self._respondInternalErrorTo_(aResponse);
  631. } else {
  632. type=_st(self._class())._mimeTypeFor_(filename);
  633. type;
  634. $3=_st(type).__eq("application/javascript");
  635. if(smalltalk.assert($3)){
  636. type=_st(type).__comma(";charset=utf-8");
  637. type;
  638. };
  639. $4=aResponse;
  640. _st($4)._writeHead_options_((200),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt(type)]));
  641. _st($4)._write_encoding_(file,"binary");
  642. $5=_st($4)._end();
  643. return $5;
  644. };
  645. }, function($ctx2) {$ctx2.fillBlock({ex:ex,file:file},$ctx1)})}));
  646. return self}, function($ctx1) {$ctx1.fill(self,"respondFileNamed:to:",{aFilename:aFilename,aResponse:aResponse,type:type,filename:filename},smalltalk.FileServer)})},
  647. args: ["aFilename", "aResponse"],
  648. 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]]",
  649. messageSends: ["ifTrue:", ",", "isDirectory", "statSync:", "readFile:do:", "ifTrue:ifFalse:", "log:", "respondInternalErrorTo:", "mimeTypeFor:", "class", "=", "writeHead:options:", "->", "write:encoding:", "end", "notNil"],
  650. referencedClasses: []
  651. }),
  652. smalltalk.FileServer);
  653. smalltalk.addMethod(
  654. smalltalk.method({
  655. selector: "respondInternalErrorTo:",
  656. category: 'request handling',
  657. fn: function (aResponse){
  658. var self=this;
  659. return smalltalk.withContext(function($ctx1) {
  660. var $1,$2;
  661. $1=aResponse;
  662. _st($1)._writeHead_options_((500),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain")]));
  663. _st($1)._write_("500 Internal server error");
  664. $2=_st($1)._end();
  665. return self}, function($ctx1) {$ctx1.fill(self,"respondInternalErrorTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  666. args: ["aResponse"],
  667. source: "respondInternalErrorTo: aResponse\x0a\x09aResponse \x0a\x09\x09writeHead: 500 options: #{'Content-Type' -> 'text/plain'};\x0a\x09\x09write: '500 Internal server error';\x0a\x09\x09end",
  668. messageSends: ["writeHead:options:", "->", "write:", "end"],
  669. referencedClasses: []
  670. }),
  671. smalltalk.FileServer);
  672. smalltalk.addMethod(
  673. smalltalk.method({
  674. selector: "respondNotCreatedTo:",
  675. category: 'request handling',
  676. fn: function (aResponse){
  677. var self=this;
  678. return smalltalk.withContext(function($ctx1) {
  679. var $1,$2;
  680. $1=aResponse;
  681. _st($1)._writeHead_options_((400),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain")]));
  682. _st($1)._write_("File could not be created. Did you forget to create the st/js directories on the server?");
  683. $2=_st($1)._end();
  684. return self}, function($ctx1) {$ctx1.fill(self,"respondNotCreatedTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  685. args: ["aResponse"],
  686. 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.",
  687. messageSends: ["writeHead:options:", "->", "write:", "end"],
  688. referencedClasses: []
  689. }),
  690. smalltalk.FileServer);
  691. smalltalk.addMethod(
  692. smalltalk.method({
  693. selector: "respondNotFoundTo:",
  694. category: 'request handling',
  695. fn: function (aResponse){
  696. var self=this;
  697. return smalltalk.withContext(function($ctx1) {
  698. var $1,$2,$3,$4;
  699. $1=_st(self._fallbackPage())._isNil();
  700. if(! smalltalk.assert($1)){
  701. $2=self._respondFileNamed_to_(self._fallbackPage(),aResponse);
  702. return $2;
  703. };
  704. $3=aResponse;
  705. _st($3)._writeHead_options_((404),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain")]));
  706. _st($3)._write_("404 Not found");
  707. $4=_st($3)._end();
  708. return self}, function($ctx1) {$ctx1.fill(self,"respondNotFoundTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  709. args: ["aResponse"],
  710. 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",
  711. messageSends: ["ifFalse:", "respondFileNamed:to:", "fallbackPage", "isNil", "writeHead:options:", "->", "write:", "end"],
  712. referencedClasses: []
  713. }),
  714. smalltalk.FileServer);
  715. smalltalk.addMethod(
  716. smalltalk.method({
  717. selector: "respondOKTo:",
  718. category: 'request handling',
  719. fn: function (aResponse){
  720. var self=this;
  721. return smalltalk.withContext(function($ctx1) {
  722. var $1,$2;
  723. $1=aResponse;
  724. _st($1)._writeHead_options_((200),smalltalk.HashedCollection._from_(["Content-Type".__minus_gt("text/plain"),"Access-Control-Allow-Origin".__minus_gt("*")]));
  725. $2=_st($1)._end();
  726. return self}, function($ctx1) {$ctx1.fill(self,"respondOKTo:",{aResponse:aResponse},smalltalk.FileServer)})},
  727. args: ["aResponse"],
  728. source: "respondOKTo: aResponse\x0a\x09aResponse\x0a\x09\x09writeHead: 200 options: #{'Content-Type' -> 'text/plain'. 'Access-Control-Allow-Origin' -> '*'};\x0a\x09\x09end.",
  729. messageSends: ["writeHead:options:", "->", "end"],
  730. referencedClasses: []
  731. }),
  732. smalltalk.FileServer);
  733. smalltalk.addMethod(
  734. smalltalk.method({
  735. selector: "start",
  736. category: 'starting',
  737. fn: function (){
  738. var self=this;
  739. return smalltalk.withContext(function($ctx1) {
  740. var $1,$2;
  741. self._checkDirectoryLayout();
  742. $1=_st(self["@http"])._createServer_((function(request,response){
  743. return smalltalk.withContext(function($ctx2) {
  744. return self._handleRequest_respondTo_(request,response);
  745. }, function($ctx2) {$ctx2.fillBlock({request:request,response:response},$ctx1)})}));
  746. _st($1)._on_do_("error",(function(error){
  747. return smalltalk.withContext(function($ctx2) {
  748. return _st(console)._log_("Error starting server: ".__comma(error));
  749. }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1)})}));
  750. _st($1)._on_do_("listening",(function(){
  751. return smalltalk.withContext(function($ctx2) {
  752. return _st(console)._log_(_st(_st("Starting file server on http://".__comma(self._host())).__comma(":")).__comma(_st(self._port())._asString()));
  753. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  754. $2=_st($1)._listen_host_(self._port(),self._host());
  755. return self}, function($ctx1) {$ctx1.fill(self,"start",{},smalltalk.FileServer)})},
  756. args: [],
  757. 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.",
  758. messageSends: ["checkDirectoryLayout", "on:do:", "log:", ",", "createServer:", "handleRequest:respondTo:", "asString", "port", "host", "listen:host:"],
  759. referencedClasses: []
  760. }),
  761. smalltalk.FileServer);
  762. smalltalk.addMethod(
  763. smalltalk.method({
  764. selector: "startOn:",
  765. category: 'starting',
  766. fn: function (aPort){
  767. var self=this;
  768. return smalltalk.withContext(function($ctx1) {
  769. self._port_(aPort);
  770. self._start();
  771. return self}, function($ctx1) {$ctx1.fill(self,"startOn:",{aPort:aPort},smalltalk.FileServer)})},
  772. args: ["aPort"],
  773. source: "startOn: aPort\x0a\x09self port: aPort.\x0a\x09self start",
  774. messageSends: ["port:", "start"],
  775. referencedClasses: []
  776. }),
  777. smalltalk.FileServer);
  778. smalltalk.addMethod(
  779. smalltalk.method({
  780. selector: "username:",
  781. category: 'accessing',
  782. fn: function (aUsername){
  783. var self=this;
  784. return smalltalk.withContext(function($ctx1) {
  785. self["@username"]=aUsername;
  786. return self}, function($ctx1) {$ctx1.fill(self,"username:",{aUsername:aUsername},smalltalk.FileServer)})},
  787. args: ["aUsername"],
  788. source: "username: aUsername\x0a\x09username := aUsername.",
  789. messageSends: [],
  790. referencedClasses: []
  791. }),
  792. smalltalk.FileServer);
  793. smalltalk.addMethod(
  794. smalltalk.method({
  795. selector: "writeData:toFileNamed:",
  796. category: 'private',
  797. fn: function (data,aFilename){
  798. var self=this;
  799. return smalltalk.withContext(function($ctx1) {
  800. _st(console)._log_(aFilename);
  801. return self}, function($ctx1) {$ctx1.fill(self,"writeData:toFileNamed:",{data:data,aFilename:aFilename},smalltalk.FileServer)})},
  802. args: ["data", "aFilename"],
  803. source: "writeData: data toFileNamed: aFilename\x0a\x09console log: aFilename",
  804. messageSends: ["log:"],
  805. referencedClasses: []
  806. }),
  807. smalltalk.FileServer);
  808. smalltalk.FileServer.klass.iVarNames = ['mimeTypes'];
  809. smalltalk.addMethod(
  810. smalltalk.method({
  811. selector: "commandLineSwitches",
  812. category: 'accessing',
  813. fn: function (){
  814. var self=this;
  815. var switches;
  816. return smalltalk.withContext(function($ctx1) {
  817. var $1;
  818. switches=_st(self._methodsInProtocol_("accessing"))._collect_((function(each){
  819. return smalltalk.withContext(function($ctx2) {
  820. return _st(each)._selector();
  821. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  822. switches=_st(switches)._select_((function(each){
  823. return smalltalk.withContext(function($ctx2) {
  824. return _st(each)._match_("^[^:]*:$");
  825. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  826. switches=_st(switches)._collect_((function(each){
  827. return smalltalk.withContext(function($ctx2) {
  828. return _st(_st(_st(_st(each)._allButLast())._replace_with_("([A-Z])","-$1"))._asLowercase())._replace_with_("^([a-z])","--$1");
  829. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  830. $1=switches;
  831. return $1;
  832. }, function($ctx1) {$ctx1.fill(self,"commandLineSwitches",{switches:switches},smalltalk.FileServer.klass)})},
  833. args: [],
  834. 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",
  835. messageSends: ["collect:", "selector", "methodsInProtocol:", "select:", "match:", "replace:with:", "asLowercase", "allButLast"],
  836. referencedClasses: []
  837. }),
  838. smalltalk.FileServer.klass);
  839. smalltalk.addMethod(
  840. smalltalk.method({
  841. selector: "createServerWithArguments:",
  842. category: 'initialization',
  843. fn: function (options){
  844. var self=this;
  845. var server,popFront,front,optionName,optionValue,switches;
  846. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  847. return smalltalk.withContext(function($ctx1) {
  848. var $1,$2,$3,$4,$5;
  849. var $early={};
  850. try {
  851. switches=self._commandLineSwitches();
  852. server=self._new();
  853. _st(options)._ifEmpty_((function(){
  854. return smalltalk.withContext(function($ctx2) {
  855. $1=server;
  856. throw $early=[$1];
  857. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  858. $2=_st(_st(options)._size())._even();
  859. if(! smalltalk.assert($2)){
  860. _st(console)._log_("Using default parameters.");
  861. _st(console)._log_("Wrong commandline options or not enough arguments for: ".__comma(options));
  862. _st(console)._log_("Use any of the following ones: ".__comma(switches));
  863. $3=server;
  864. return $3;
  865. };
  866. popFront=(function(args){
  867. return smalltalk.withContext(function($ctx2) {
  868. front=_st(args)._first();
  869. front;
  870. _st(args)._remove_(front);
  871. return front;
  872. }, function($ctx2) {$ctx2.fillBlock({args:args},$ctx1)})});
  873. _st((function(){
  874. return smalltalk.withContext(function($ctx2) {
  875. return _st(options)._notEmpty();
  876. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  877. return smalltalk.withContext(function($ctx2) {
  878. optionName=_st(popFront)._value_(options);
  879. optionName;
  880. optionValue=_st(popFront)._value_(options);
  881. optionValue;
  882. $4=_st(switches)._includes_(optionName);
  883. if(smalltalk.assert($4)){
  884. optionName=self._selectorForCommandLineSwitch_(optionName);
  885. optionName;
  886. return _st(server)._perform_withArguments_(optionName,_st($Array())._with_(optionValue));
  887. } else {
  888. _st(console)._log_(_st(optionName).__comma(" is not a valid commandline option"));
  889. return _st(console)._log_("Use any of the following ones: ".__comma(switches));
  890. };
  891. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  892. $5=server;
  893. return $5;
  894. }
  895. catch(e) {if(e===$early)return e[0]; throw e}
  896. }, function($ctx1) {$ctx1.fill(self,"createServerWithArguments:",{options:options,server:server,popFront:popFront,front:front,optionName:optionName,optionValue:optionValue,switches:switches},smalltalk.FileServer.klass)})},
  897. args: ["options"],
  898. 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.",
  899. messageSends: ["commandLineSwitches", "new", "ifEmpty:", "ifFalse:", "log:", ",", "even", "size", "first", "remove:", "whileTrue:", "value:", "ifTrue:ifFalse:", "selectorForCommandLineSwitch:", "perform:withArguments:", "with:", "includes:", "notEmpty"],
  900. referencedClasses: ["Array"]
  901. }),
  902. smalltalk.FileServer.klass);
  903. smalltalk.addMethod(
  904. smalltalk.method({
  905. selector: "defaultHost",
  906. category: 'accessing',
  907. fn: function (){
  908. var self=this;
  909. return smalltalk.withContext(function($ctx1) {
  910. return "127.0.0.1";
  911. }, function($ctx1) {$ctx1.fill(self,"defaultHost",{},smalltalk.FileServer.klass)})},
  912. args: [],
  913. source: "defaultHost\x0a\x09^'127.0.0.1'",
  914. messageSends: [],
  915. referencedClasses: []
  916. }),
  917. smalltalk.FileServer.klass);
  918. smalltalk.addMethod(
  919. smalltalk.method({
  920. selector: "defaultMimeTypes",
  921. category: 'accessing',
  922. fn: function (){
  923. var self=this;
  924. return smalltalk.withContext(function($ctx1) {
  925. var $1;
  926. $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")]);
  927. return $1;
  928. }, function($ctx1) {$ctx1.fill(self,"defaultMimeTypes",{},smalltalk.FileServer.klass)})},
  929. args: [],
  930. 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}",
  931. messageSends: ["->"],
  932. referencedClasses: []
  933. }),
  934. smalltalk.FileServer.klass);
  935. smalltalk.addMethod(
  936. smalltalk.method({
  937. selector: "defaultPort",
  938. category: 'accessing',
  939. fn: function (){
  940. var self=this;
  941. return smalltalk.withContext(function($ctx1) {
  942. return (4000);
  943. }, function($ctx1) {$ctx1.fill(self,"defaultPort",{},smalltalk.FileServer.klass)})},
  944. args: [],
  945. source: "defaultPort\x0a\x09^4000",
  946. messageSends: [],
  947. referencedClasses: []
  948. }),
  949. smalltalk.FileServer.klass);
  950. smalltalk.addMethod(
  951. smalltalk.method({
  952. selector: "main",
  953. category: 'initialization',
  954. fn: function (){
  955. var self=this;
  956. var fileServer,args;
  957. function $FileServer(){return smalltalk.FileServer||(typeof FileServer=="undefined"?nil:FileServer)}
  958. return smalltalk.withContext(function($ctx1) {
  959. var $1,$2;
  960. var $early={};
  961. try {
  962. args=_st(process)._argv();
  963. _st(args)._removeFrom_to_((1),(3));
  964. _st(args)._detect_ifNone_((function(each){
  965. return smalltalk.withContext(function($ctx2) {
  966. $1=_st(each).__eq("--help");
  967. if(smalltalk.assert($1)){
  968. return _st($FileServer())._printHelp();
  969. };
  970. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  971. return smalltalk.withContext(function($ctx2) {
  972. fileServer=_st($FileServer())._createServerWithArguments_(args);
  973. fileServer;
  974. $2=_st(fileServer)._start();
  975. throw $early=[$2];
  976. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  977. return self}
  978. catch(e) {if(e===$early)return e[0]; throw e}
  979. }, function($ctx1) {$ctx1.fill(self,"main",{fileServer:fileServer,args:args},smalltalk.FileServer.klass)})},
  980. args: [],
  981. 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]",
  982. messageSends: ["argv", "removeFrom:to:", "detect:ifNone:", "ifTrue:", "printHelp", "=", "createServerWithArguments:", "start"],
  983. referencedClasses: ["FileServer"]
  984. }),
  985. smalltalk.FileServer.klass);
  986. smalltalk.addMethod(
  987. smalltalk.method({
  988. selector: "mimeTypeFor:",
  989. category: 'accessing',
  990. fn: function (aString){
  991. var self=this;
  992. return smalltalk.withContext(function($ctx1) {
  993. var $1;
  994. $1=_st(self._mimeTypes())._at_ifAbsent_(_st(aString)._replace_with_(".*[\x5c.]",""),(function(){
  995. return smalltalk.withContext(function($ctx2) {
  996. return "text/plain";
  997. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  998. return $1;
  999. }, function($ctx1) {$ctx1.fill(self,"mimeTypeFor:",{aString:aString},smalltalk.FileServer.klass)})},
  1000. args: ["aString"],
  1001. source: "mimeTypeFor: aString\x0a\x09^self mimeTypes at: (aString replace: '.*[\x5c.]' with: '') ifAbsent: ['text/plain']",
  1002. messageSends: ["at:ifAbsent:", "replace:with:", "mimeTypes"],
  1003. referencedClasses: []
  1004. }),
  1005. smalltalk.FileServer.klass);
  1006. smalltalk.addMethod(
  1007. smalltalk.method({
  1008. selector: "mimeTypes",
  1009. category: 'accessing',
  1010. fn: function (){
  1011. var self=this;
  1012. return smalltalk.withContext(function($ctx1) {
  1013. var $2,$1;
  1014. $2=self["@mimeTypes"];
  1015. if(($receiver = $2) == nil || $receiver == undefined){
  1016. self["@mimeTypes"]=self._defaultMimeTypes();
  1017. $1=self["@mimeTypes"];
  1018. } else {
  1019. $1=$2;
  1020. };
  1021. return $1;
  1022. }, function($ctx1) {$ctx1.fill(self,"mimeTypes",{},smalltalk.FileServer.klass)})},
  1023. args: [],
  1024. source: "mimeTypes\x0a\x09^mimeTypes ifNil: [mimeTypes := self defaultMimeTypes]",
  1025. messageSends: ["ifNil:", "defaultMimeTypes"],
  1026. referencedClasses: []
  1027. }),
  1028. smalltalk.FileServer.klass);
  1029. smalltalk.addMethod(
  1030. smalltalk.method({
  1031. selector: "printHelp",
  1032. category: 'accessing',
  1033. fn: function (){
  1034. var self=this;
  1035. return smalltalk.withContext(function($ctx1) {
  1036. _st(console)._log_("Available commandline options are:");
  1037. _st(console)._log_("--help");
  1038. _st(self._commandLineSwitches())._do_((function(each){
  1039. return smalltalk.withContext(function($ctx2) {
  1040. return _st(console)._log_(_st(each).__comma(" <parameter>"));
  1041. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1042. return self}, function($ctx1) {$ctx1.fill(self,"printHelp",{},smalltalk.FileServer.klass)})},
  1043. args: [],
  1044. source: "printHelp\x0a\x09console log: 'Available commandline options are:'.\x0a\x09console log: '--help'.\x0a\x09self commandLineSwitches do: [ :each |\x0a\x09\x09console log: each, ' <parameter>']",
  1045. messageSends: ["log:", "do:", ",", "commandLineSwitches"],
  1046. referencedClasses: []
  1047. }),
  1048. smalltalk.FileServer.klass);
  1049. smalltalk.addMethod(
  1050. smalltalk.method({
  1051. selector: "selectorForCommandLineSwitch:",
  1052. category: 'accessing',
  1053. fn: function (aSwitch){
  1054. var self=this;
  1055. return smalltalk.withContext(function($ctx1) {
  1056. var $1;
  1057. $1=_st(_st(_st(aSwitch)._replace_with_("^--",""))._replace_with_("-[a-z]",(function(each){
  1058. return smalltalk.withContext(function($ctx2) {
  1059. return _st(_st(each)._second())._asUppercase();
  1060. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}))).__comma(":");
  1061. return $1;
  1062. }, function($ctx1) {$ctx1.fill(self,"selectorForCommandLineSwitch:",{aSwitch:aSwitch},smalltalk.FileServer.klass)})},
  1063. args: ["aSwitch"],
  1064. 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 ]), ':'",
  1065. messageSends: [",", "replace:with:", "asUppercase", "second"],
  1066. referencedClasses: []
  1067. }),
  1068. smalltalk.FileServer.klass);
  1069. smalltalk.addClass('Repl', smalltalk.Object, ['readline', 'interface', 'util', 'session', 'resultCount', 'commands'], 'AmberCli');
  1070. 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.";
  1071. smalltalk.addMethod(
  1072. smalltalk.method({
  1073. selector: "addVariableNamed:to:",
  1074. category: 'private',
  1075. fn: function (aString,anObject){
  1076. var self=this;
  1077. var newClass,newObject;
  1078. return smalltalk.withContext(function($ctx1) {
  1079. var $1;
  1080. newClass=self._subclass_withVariable_(_st(anObject)._class(),aString);
  1081. self._encapsulateVariable_withValue_in_(aString,anObject,newClass);
  1082. newObject=_st(newClass)._new();
  1083. self._setPreviousVariablesFor_from_(newObject,anObject);
  1084. $1=newObject;
  1085. return $1;
  1086. }, function($ctx1) {$ctx1.fill(self,"addVariableNamed:to:",{aString:aString,anObject:anObject,newClass:newClass,newObject:newObject},smalltalk.Repl)})},
  1087. args: ["aString", "anObject"],
  1088. 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",
  1089. messageSends: ["subclass:withVariable:", "class", "encapsulateVariable:withValue:in:", "new", "setPreviousVariablesFor:from:"],
  1090. referencedClasses: []
  1091. }),
  1092. smalltalk.Repl);
  1093. smalltalk.addMethod(
  1094. smalltalk.method({
  1095. selector: "assignNewVariable:do:",
  1096. category: 'private',
  1097. fn: function (buffer,aBlock){
  1098. var self=this;
  1099. return smalltalk.withContext(function($ctx1) {
  1100. var $2,$3,$5,$7,$6,$4,$1;
  1101. $1=self._parseAssignment_do_(buffer,(function(name,expr){
  1102. var varName,value;
  1103. return smalltalk.withContext(function($ctx2) {
  1104. $2=name;
  1105. if(($receiver = $2) == nil || $receiver == undefined){
  1106. varName=self._nextResultName();
  1107. } else {
  1108. varName=$2;
  1109. };
  1110. varName;
  1111. self["@session"]=self._addVariableNamed_to_(varName,self["@session"]);
  1112. self["@session"];
  1113. $3=self;
  1114. $5=_st(varName).__comma(" := ");
  1115. $7=expr;
  1116. if(($receiver = $7) == nil || $receiver == undefined){
  1117. $6=buffer;
  1118. } else {
  1119. $6=$7;
  1120. };
  1121. $4=_st($5).__comma($6);
  1122. value=_st($3)._eval_on_($4,self["@session"]);
  1123. value;
  1124. return _st(aBlock)._value_value_(varName,value);
  1125. }, function($ctx2) {$ctx2.fillBlock({name:name,expr:expr,varName:varName,value:value},$ctx1)})}));
  1126. return $1;
  1127. }, function($ctx1) {$ctx1.fill(self,"assignNewVariable:do:",{buffer:buffer,aBlock:aBlock},smalltalk.Repl)})},
  1128. args: ["buffer", "aBlock"],
  1129. 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]",
  1130. messageSends: ["parseAssignment:do:", "ifNil:", "nextResultName", "addVariableNamed:to:", "eval:on:", ",", "value:value:"],
  1131. referencedClasses: []
  1132. }),
  1133. smalltalk.Repl);
  1134. smalltalk.addMethod(
  1135. smalltalk.method({
  1136. selector: "clearScreen",
  1137. category: 'private',
  1138. fn: function (){
  1139. var self=this;
  1140. var esc,cls;
  1141. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  1142. return smalltalk.withContext(function($ctx1) {
  1143. esc=_st($String())._fromCharCode_((27));
  1144. cls=_st(_st(_st(esc).__comma("[2J")).__comma(esc)).__comma("[0;0f");
  1145. _st(_st(process)._stdout())._write_(cls);
  1146. _st(self["@interface"])._prompt();
  1147. return self}, function($ctx1) {$ctx1.fill(self,"clearScreen",{esc:esc,cls:cls},smalltalk.Repl)})},
  1148. args: [],
  1149. 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",
  1150. messageSends: ["fromCharCode:", ",", "write:", "stdout", "prompt"],
  1151. referencedClasses: ["String"]
  1152. }),
  1153. smalltalk.Repl);
  1154. smalltalk.addMethod(
  1155. smalltalk.method({
  1156. selector: "close",
  1157. category: 'actions',
  1158. fn: function (){
  1159. var self=this;
  1160. return smalltalk.withContext(function($ctx1) {
  1161. _st(_st(process)._stdin())._destroy();
  1162. return self}, function($ctx1) {$ctx1.fill(self,"close",{},smalltalk.Repl)})},
  1163. args: [],
  1164. source: "close\x0a\x09process stdin destroy",
  1165. messageSends: ["destroy", "stdin"],
  1166. referencedClasses: []
  1167. }),
  1168. smalltalk.Repl);
  1169. smalltalk.addMethod(
  1170. smalltalk.method({
  1171. selector: "commands",
  1172. category: 'accessing',
  1173. fn: function (){
  1174. var self=this;
  1175. return smalltalk.withContext(function($ctx1) {
  1176. var $1;
  1177. $1=self["@commands"];
  1178. return $1;
  1179. }, function($ctx1) {$ctx1.fill(self,"commands",{},smalltalk.Repl)})},
  1180. args: [],
  1181. source: "commands\x0a\x09^ commands",
  1182. messageSends: [],
  1183. referencedClasses: []
  1184. }),
  1185. smalltalk.Repl);
  1186. smalltalk.addMethod(
  1187. smalltalk.method({
  1188. selector: "createInterface",
  1189. category: 'actions',
  1190. fn: function (){
  1191. var self=this;
  1192. return smalltalk.withContext(function($ctx1) {
  1193. var $1,$2;
  1194. self["@interface"]=_st(self["@readline"])._createInterface_stdout_(_st(process)._stdin(),_st(process)._stdout());
  1195. _st(self["@interface"])._on_do_("line",(function(buffer){
  1196. return smalltalk.withContext(function($ctx2) {
  1197. return self._processLine_(buffer);
  1198. }, function($ctx2) {$ctx2.fillBlock({buffer:buffer},$ctx1)})}));
  1199. _st(self["@interface"])._on_do_("close",(function(){
  1200. return smalltalk.withContext(function($ctx2) {
  1201. return self._close();
  1202. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1203. $1=self;
  1204. _st($1)._printWelcome();
  1205. _st($1)._setupHotkeys();
  1206. $2=_st($1)._setPrompt();
  1207. _st(self["@interface"])._prompt();
  1208. return self}, function($ctx1) {$ctx1.fill(self,"createInterface",{},smalltalk.Repl)})},
  1209. args: [],
  1210. 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",
  1211. messageSends: ["createInterface:stdout:", "stdin", "stdout", "on:do:", "processLine:", "close", "printWelcome", "setupHotkeys", "setPrompt", "prompt"],
  1212. referencedClasses: []
  1213. }),
  1214. smalltalk.Repl);
  1215. smalltalk.addMethod(
  1216. smalltalk.method({
  1217. selector: "encapsulateVariable:withValue:in:",
  1218. category: 'private',
  1219. fn: function (aString,anObject,aClass){
  1220. var self=this;
  1221. var compiler;
  1222. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  1223. return smalltalk.withContext(function($ctx1) {
  1224. compiler=_st($Compiler())._new();
  1225. _st(compiler)._install_forClass_category_(_st(_st(_st(aString).__comma(": anObject ^ ")).__comma(aString)).__comma(" := anObject"),aClass,"session");
  1226. _st(compiler)._install_forClass_category_(_st(_st(aString).__comma(" ^ ")).__comma(aString),aClass,"session");
  1227. return self}, function($ctx1) {$ctx1.fill(self,"encapsulateVariable:withValue:in:",{aString:aString,anObject:anObject,aClass:aClass,compiler:compiler},smalltalk.Repl)})},
  1228. args: ["aString", "anObject", "aClass"],
  1229. 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'.",
  1230. messageSends: ["new", "install:forClass:category:", ","],
  1231. referencedClasses: ["Compiler"]
  1232. }),
  1233. smalltalk.Repl);
  1234. smalltalk.addMethod(
  1235. smalltalk.method({
  1236. selector: "eval:",
  1237. category: 'actions',
  1238. fn: function (buffer){
  1239. var self=this;
  1240. function $DoIt(){return smalltalk.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  1241. return smalltalk.withContext(function($ctx1) {
  1242. var $1;
  1243. $1=self._eval_on_(buffer,_st($DoIt())._new());
  1244. return $1;
  1245. }, function($ctx1) {$ctx1.fill(self,"eval:",{buffer:buffer},smalltalk.Repl)})},
  1246. args: ["buffer"],
  1247. source: "eval: buffer\x0a\x09^ self eval: buffer on: DoIt new.",
  1248. messageSends: ["eval:on:", "new"],
  1249. referencedClasses: ["DoIt"]
  1250. }),
  1251. smalltalk.Repl);
  1252. smalltalk.addMethod(
  1253. smalltalk.method({
  1254. selector: "eval:on:",
  1255. category: 'actions',
  1256. fn: function (buffer,anObject){
  1257. var self=this;
  1258. var result;
  1259. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  1260. function $ErrorHandler(){return smalltalk.ErrorHandler||(typeof ErrorHandler=="undefined"?nil:ErrorHandler)}
  1261. return smalltalk.withContext(function($ctx1) {
  1262. var $1,$2,$3;
  1263. $1=_st(buffer)._isEmpty();
  1264. if(! smalltalk.assert($1)){
  1265. self._try_catch_((function(){
  1266. return smalltalk.withContext(function($ctx2) {
  1267. result=_st(_st($Compiler())._new())._evaluateExpression_on_(buffer,anObject);
  1268. return result;
  1269. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),(function(e){
  1270. return smalltalk.withContext(function($ctx2) {
  1271. $2=_st(e)._isSmalltalkError();
  1272. if(smalltalk.assert($2)){
  1273. return _st(_st($ErrorHandler())._new())._handleError_(e);
  1274. } else {
  1275. return _st(_st(process)._stdout())._write_(_st(e)._jsStack());
  1276. };
  1277. }, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1)})}));
  1278. };
  1279. $3=result;
  1280. return $3;
  1281. }, function($ctx1) {$ctx1.fill(self,"eval:on:",{buffer:buffer,anObject:anObject,result:result},smalltalk.Repl)})},
  1282. args: ["buffer", "anObject"],
  1283. 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",
  1284. messageSends: ["ifFalse:", "try:catch:", "evaluateExpression:on:", "new", "ifTrue:ifFalse:", "handleError:", "write:", "jsStack", "stdout", "isSmalltalkError", "isEmpty"],
  1285. referencedClasses: ["Compiler", "ErrorHandler"]
  1286. }),
  1287. smalltalk.Repl);
  1288. smalltalk.addMethod(
  1289. smalltalk.method({
  1290. selector: "executeCommand:",
  1291. category: 'private',
  1292. fn: function (aString){
  1293. var self=this;
  1294. return smalltalk.withContext(function($ctx1) {
  1295. var $1;
  1296. var $early={};
  1297. try {
  1298. _st(self._commands())._keysAndValuesDo_((function(names,cmd){
  1299. return smalltalk.withContext(function($ctx2) {
  1300. $1=_st(names)._includes_(aString);
  1301. if(smalltalk.assert($1)){
  1302. _st(cmd)._value();
  1303. throw $early=[true];
  1304. };
  1305. }, function($ctx2) {$ctx2.fillBlock({names:names,cmd:cmd},$ctx1)})}));
  1306. return false;
  1307. }
  1308. catch(e) {if(e===$early)return e[0]; throw e}
  1309. }, function($ctx1) {$ctx1.fill(self,"executeCommand:",{aString:aString},smalltalk.Repl)})},
  1310. args: ["aString"],
  1311. 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",
  1312. messageSends: ["keysAndValuesDo:", "ifTrue:", "value", "includes:", "commands"],
  1313. referencedClasses: []
  1314. }),
  1315. smalltalk.Repl);
  1316. smalltalk.addMethod(
  1317. smalltalk.method({
  1318. selector: "initialize",
  1319. category: 'initialization',
  1320. fn: function (){
  1321. var self=this;
  1322. function $DoIt(){return smalltalk.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  1323. return smalltalk.withContext(function($ctx1) {
  1324. smalltalk.Object.fn.prototype._initialize.apply(_st(self), []);
  1325. self["@session"]=_st($DoIt())._new();
  1326. self["@readline"]=_st(require)._value_("readline");
  1327. self["@util"]=_st(require)._value_("util");
  1328. self._setupCommands();
  1329. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.Repl)})},
  1330. args: [],
  1331. source: "initialize\x0a\x09super initialize.\x0a\x09session := DoIt new.\x0a\x09readline := require value: 'readline'.\x0a\x09util := require value: 'util'.\x0a\x09self setupCommands",
  1332. messageSends: ["initialize", "new", "value:", "setupCommands"],
  1333. referencedClasses: ["DoIt"]
  1334. }),
  1335. smalltalk.Repl);
  1336. smalltalk.addMethod(
  1337. smalltalk.method({
  1338. selector: "instanceVariableNamesFor:",
  1339. category: 'private',
  1340. fn: function (aClass){
  1341. var self=this;
  1342. return smalltalk.withContext(function($ctx1) {
  1343. var $2,$1;
  1344. $2=_st(aClass)._superclass();
  1345. if(($receiver = $2) == nil || $receiver == undefined){
  1346. $1=_st(aClass)._instanceVariableNames();
  1347. } else {
  1348. $1=_st(_st(aClass)._instanceVariableNames())._copyWithAll_(self._instanceVariableNamesFor_(_st(aClass)._superclass()));
  1349. };
  1350. return $1;
  1351. }, function($ctx1) {$ctx1.fill(self,"instanceVariableNamesFor:",{aClass:aClass},smalltalk.Repl)})},
  1352. args: ["aClass"],
  1353. 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]",
  1354. messageSends: ["ifNotNil:ifNil:", "copyWithAll:", "instanceVariableNamesFor:", "superclass", "instanceVariableNames"],
  1355. referencedClasses: []
  1356. }),
  1357. smalltalk.Repl);
  1358. smalltalk.addMethod(
  1359. smalltalk.method({
  1360. selector: "isIdentifier:",
  1361. category: 'private',
  1362. fn: function (aString){
  1363. var self=this;
  1364. return smalltalk.withContext(function($ctx1) {
  1365. var $1;
  1366. $1=_st(aString)._match_("^[a-z_]\x5cw+$"._asRegexp());
  1367. return $1;
  1368. }, function($ctx1) {$ctx1.fill(self,"isIdentifier:",{aString:aString},smalltalk.Repl)})},
  1369. args: ["aString"],
  1370. source: "isIdentifier: aString\x0a\x09^ aString match: '^[a-z_]\x5cw+$' asRegexp",
  1371. messageSends: ["match:", "asRegexp"],
  1372. referencedClasses: []
  1373. }),
  1374. smalltalk.Repl);
  1375. smalltalk.addMethod(
  1376. smalltalk.method({
  1377. selector: "isVariableDefined:",
  1378. category: 'private',
  1379. fn: function (aString){
  1380. var self=this;
  1381. return smalltalk.withContext(function($ctx1) {
  1382. var $1;
  1383. $1=_st(self._instanceVariableNamesFor_(_st(self["@session"])._class()))._includes_(aString);
  1384. return $1;
  1385. }, function($ctx1) {$ctx1.fill(self,"isVariableDefined:",{aString:aString},smalltalk.Repl)})},
  1386. args: ["aString"],
  1387. source: "isVariableDefined: aString\x0a\x09^ (self instanceVariableNamesFor: session class) includes: aString",
  1388. messageSends: ["includes:", "instanceVariableNamesFor:", "class"],
  1389. referencedClasses: []
  1390. }),
  1391. smalltalk.Repl);
  1392. smalltalk.addMethod(
  1393. smalltalk.method({
  1394. selector: "nextResultName",
  1395. category: 'private',
  1396. fn: function (){
  1397. var self=this;
  1398. return smalltalk.withContext(function($ctx1) {
  1399. var $1,$2;
  1400. $1=self["@resultCount"];
  1401. if(($receiver = $1) == nil || $receiver == undefined){
  1402. self["@resultCount"]=(1);
  1403. } else {
  1404. self["@resultCount"]=_st(self["@resultCount"]).__plus((1));
  1405. };
  1406. $2="res".__comma(_st(self["@resultCount"])._asString());
  1407. return $2;
  1408. }, function($ctx1) {$ctx1.fill(self,"nextResultName",{},smalltalk.Repl)})},
  1409. args: [],
  1410. source: "nextResultName\x0a\x09resultCount := resultCount\x0a \x09ifNotNil: [resultCount + 1]\x0a \x09ifNil: [1].\x0a ^ 'res', resultCount asString",
  1411. messageSends: ["ifNotNil:ifNil:", "+", ",", "asString"],
  1412. referencedClasses: []
  1413. }),
  1414. smalltalk.Repl);
  1415. smalltalk.addMethod(
  1416. smalltalk.method({
  1417. selector: "onKeyPress:",
  1418. category: 'private',
  1419. fn: function (key){
  1420. var self=this;
  1421. return smalltalk.withContext(function($ctx1) {
  1422. var $1;
  1423. $1=_st(_st(key)._ctrl())._and_((function(){
  1424. return smalltalk.withContext(function($ctx2) {
  1425. return _st(_st(key)._name()).__eq("l");
  1426. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1427. if(smalltalk.assert($1)){
  1428. self._clearScreen();
  1429. };
  1430. return self}, function($ctx1) {$ctx1.fill(self,"onKeyPress:",{key:key},smalltalk.Repl)})},
  1431. args: ["key"],
  1432. source: "onKeyPress: key\x0a\x09(key ctrl and: [key name = 'l'])\x0a\x09\x09ifTrue: [self clearScreen]",
  1433. messageSends: ["ifTrue:", "clearScreen", "and:", "=", "name", "ctrl"],
  1434. referencedClasses: []
  1435. }),
  1436. smalltalk.Repl);
  1437. smalltalk.addMethod(
  1438. smalltalk.method({
  1439. selector: "parseAssignment:do:",
  1440. category: 'private',
  1441. fn: function (aString,aBlock){
  1442. var self=this;
  1443. var assignment;
  1444. return smalltalk.withContext(function($ctx1) {
  1445. var $2,$1;
  1446. assignment=_st(_st(aString)._tokenize_(":="))._collect_((function(s){
  1447. return smalltalk.withContext(function($ctx2) {
  1448. return _st(s)._trimBoth();
  1449. }, function($ctx2) {$ctx2.fillBlock({s:s},$ctx1)})}));
  1450. $2=_st(_st(_st(assignment)._size()).__eq((2)))._and_((function(){
  1451. return smalltalk.withContext(function($ctx2) {
  1452. return self._isIdentifier_(_st(assignment)._first());
  1453. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1454. if(smalltalk.assert($2)){
  1455. $1=_st(aBlock)._value_value_(_st(assignment)._first(),_st(assignment)._last());
  1456. } else {
  1457. $1=_st(aBlock)._value_value_(nil,nil);
  1458. };
  1459. return $1;
  1460. }, function($ctx1) {$ctx1.fill(self,"parseAssignment:do:",{aString:aString,aBlock:aBlock,assignment:assignment},smalltalk.Repl)})},
  1461. args: ["aString", "aBlock"],
  1462. 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]",
  1463. messageSends: ["collect:", "trimBoth", "tokenize:", "ifTrue:ifFalse:", "value:value:", "first", "last", "and:", "isIdentifier:", "=", "size"],
  1464. referencedClasses: []
  1465. }),
  1466. smalltalk.Repl);
  1467. smalltalk.addMethod(
  1468. smalltalk.method({
  1469. selector: "presentResultNamed:withValue:",
  1470. category: 'private',
  1471. fn: function (varName,value){
  1472. var self=this;
  1473. function $Transcript(){return smalltalk.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
  1474. return smalltalk.withContext(function($ctx1) {
  1475. var $1,$2;
  1476. $1=$Transcript();
  1477. _st($1)._show_(_st(_st(_st(_st(varName).__comma(": ")).__comma(_st(_st(value)._class())._name())).__comma(" = ")).__comma(_st(value)._asString()));
  1478. $2=_st($1)._cr();
  1479. _st(self["@interface"])._prompt();
  1480. return self}, function($ctx1) {$ctx1.fill(self,"presentResultNamed:withValue:",{varName:varName,value:value},smalltalk.Repl)})},
  1481. args: ["varName", "value"],
  1482. source: "presentResultNamed: varName withValue: value\x0a\x09Transcript show: varName, ': ', value class name, ' = ', value asString; cr.\x0a\x09interface prompt",
  1483. messageSends: ["show:", ",", "asString", "name", "class", "cr", "prompt"],
  1484. referencedClasses: ["Transcript"]
  1485. }),
  1486. smalltalk.Repl);
  1487. smalltalk.addMethod(
  1488. smalltalk.method({
  1489. selector: "printWelcome",
  1490. category: 'private',
  1491. fn: function (){
  1492. var self=this;
  1493. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1494. function $Transcript(){return smalltalk.Transcript||(typeof Transcript=="undefined"?nil:Transcript)}
  1495. return smalltalk.withContext(function($ctx1) {
  1496. var $1,$2;
  1497. _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(")."));
  1498. $1=$Transcript();
  1499. _st($1)._show_("Type :q to exit.");
  1500. $2=_st($1)._cr();
  1501. return self}, function($ctx1) {$ctx1.fill(self,"printWelcome",{},smalltalk.Repl)})},
  1502. args: [],
  1503. source: "printWelcome\x0a\x09Transcript show: 'Welcome to Amber version ', Smalltalk current version, ' (NodeJS ', process versions node, ').'.\x0a\x09Transcript show: 'Type :q to exit.'; cr.",
  1504. messageSends: ["show:", ",", "node", "versions", "version", "current", "cr"],
  1505. referencedClasses: ["Smalltalk", "Transcript"]
  1506. }),
  1507. smalltalk.Repl);
  1508. smalltalk.addMethod(
  1509. smalltalk.method({
  1510. selector: "processLine:",
  1511. category: 'private',
  1512. fn: function (buffer){
  1513. var self=this;
  1514. var show;
  1515. return smalltalk.withContext(function($ctx1) {
  1516. var $1,$2;
  1517. show=(function(varName,value){
  1518. return smalltalk.withContext(function($ctx2) {
  1519. return self._presentResultNamed_withValue_(varName,value);
  1520. }, function($ctx2) {$ctx2.fillBlock({varName:varName,value:value},$ctx1)})});
  1521. $1=self._executeCommand_(buffer);
  1522. if(! smalltalk.assert($1)){
  1523. $2=self._isVariableDefined_(buffer);
  1524. if(smalltalk.assert($2)){
  1525. _st(show)._value_value_(buffer,_st(self["@session"])._perform_(buffer));
  1526. } else {
  1527. self._assignNewVariable_do_(buffer,show);
  1528. };
  1529. };
  1530. return self}, function($ctx1) {$ctx1.fill(self,"processLine:",{buffer:buffer,show:show},smalltalk.Repl)})},
  1531. args: ["buffer"],
  1532. 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]]",
  1533. messageSends: ["presentResultNamed:withValue:", "ifFalse:", "ifTrue:ifFalse:", "value:value:", "perform:", "assignNewVariable:do:", "isVariableDefined:", "executeCommand:"],
  1534. referencedClasses: []
  1535. }),
  1536. smalltalk.Repl);
  1537. smalltalk.addMethod(
  1538. smalltalk.method({
  1539. selector: "prompt",
  1540. category: 'accessing',
  1541. fn: function (){
  1542. var self=this;
  1543. return smalltalk.withContext(function($ctx1) {
  1544. return "amber >> ";
  1545. }, function($ctx1) {$ctx1.fill(self,"prompt",{},smalltalk.Repl)})},
  1546. args: [],
  1547. source: "prompt\x0a\x09^'amber >> '",
  1548. messageSends: [],
  1549. referencedClasses: []
  1550. }),
  1551. smalltalk.Repl);
  1552. smalltalk.addMethod(
  1553. smalltalk.method({
  1554. selector: "setPreviousVariablesFor:from:",
  1555. category: 'private',
  1556. fn: function (newObject,oldObject){
  1557. var self=this;
  1558. return smalltalk.withContext(function($ctx1) {
  1559. _st(self._instanceVariableNamesFor_(_st(oldObject)._class()))._do_((function(each){
  1560. return smalltalk.withContext(function($ctx2) {
  1561. return _st(newObject)._perform_withArguments_(_st(each).__comma(":"),[_st(oldObject)._perform_(each)]);
  1562. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1563. return self}, function($ctx1) {$ctx1.fill(self,"setPreviousVariablesFor:from:",{newObject:newObject,oldObject:oldObject},smalltalk.Repl)})},
  1564. args: ["newObject", "oldObject"],
  1565. source: "setPreviousVariablesFor: newObject from: oldObject\x0a\x09(self instanceVariableNamesFor: oldObject class) do: [:each |\x0a\x09\x09newObject perform: each, ':' withArguments: {oldObject perform: each}].",
  1566. messageSends: ["do:", "perform:withArguments:", ",", "perform:", "instanceVariableNamesFor:", "class"],
  1567. referencedClasses: []
  1568. }),
  1569. smalltalk.Repl);
  1570. smalltalk.addMethod(
  1571. smalltalk.method({
  1572. selector: "setPrompt",
  1573. category: 'actions',
  1574. fn: function (){
  1575. var self=this;
  1576. return smalltalk.withContext(function($ctx1) {
  1577. _st(self["@interface"])._setPrompt_(self._prompt());
  1578. return self}, function($ctx1) {$ctx1.fill(self,"setPrompt",{},smalltalk.Repl)})},
  1579. args: [],
  1580. source: "setPrompt\x0a\x09interface setPrompt: self prompt",
  1581. messageSends: ["setPrompt:", "prompt"],
  1582. referencedClasses: []
  1583. }),
  1584. smalltalk.Repl);
  1585. smalltalk.addMethod(
  1586. smalltalk.method({
  1587. selector: "setupCommands",
  1588. category: 'initialization',
  1589. fn: function (){
  1590. var self=this;
  1591. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  1592. return smalltalk.withContext(function($ctx1) {
  1593. self["@commands"]=_st($Dictionary())._from_([_st([":q"]).__minus_gt((function(){
  1594. return smalltalk.withContext(function($ctx2) {
  1595. return _st(process)._exit();
  1596. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})),_st([""]).__minus_gt((function(){
  1597. return smalltalk.withContext(function($ctx2) {
  1598. return _st(self["@interface"])._prompt();
  1599. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))]);
  1600. return self}, function($ctx1) {$ctx1.fill(self,"setupCommands",{},smalltalk.Repl)})},
  1601. args: [],
  1602. source: "setupCommands\x0a\x09commands := Dictionary from: {\x0a\x09\x09{':q'} -> [process exit].\x0a\x09\x09{''} -> [interface prompt]}",
  1603. messageSends: ["from:", "->", "exit", "prompt"],
  1604. referencedClasses: ["Dictionary"]
  1605. }),
  1606. smalltalk.Repl);
  1607. smalltalk.addMethod(
  1608. smalltalk.method({
  1609. selector: "setupHotkeys",
  1610. category: 'initialization',
  1611. fn: function (){
  1612. var self=this;
  1613. return smalltalk.withContext(function($ctx1) {
  1614. var $1;
  1615. _st(_st(process)._stdin())._on_do_("keypress",(function(s,key){
  1616. return smalltalk.withContext(function($ctx2) {
  1617. $1=key;
  1618. if(($receiver = $1) == nil || $receiver == undefined){
  1619. return $1;
  1620. } else {
  1621. return self._onKeyPress_(key);
  1622. };
  1623. }, function($ctx2) {$ctx2.fillBlock({s:s,key:key},$ctx1)})}));
  1624. return self}, function($ctx1) {$ctx1.fill(self,"setupHotkeys",{},smalltalk.Repl)})},
  1625. args: [],
  1626. source: "setupHotkeys\x0a\x09process stdin on: 'keypress' do: [:s :key | key ifNotNil: [self onKeyPress: key]].",
  1627. messageSends: ["on:do:", "ifNotNil:", "onKeyPress:", "stdin"],
  1628. referencedClasses: []
  1629. }),
  1630. smalltalk.Repl);
  1631. smalltalk.addMethod(
  1632. smalltalk.method({
  1633. selector: "subclass:withVariable:",
  1634. category: 'private',
  1635. fn: function (aClass,varName){
  1636. var self=this;
  1637. function $ClassBuilder(){return smalltalk.ClassBuilder||(typeof ClassBuilder=="undefined"?nil:ClassBuilder)}
  1638. return smalltalk.withContext(function($ctx1) {
  1639. var $1;
  1640. $1=_st(_st($ClassBuilder())._new())._addSubclassOf_named_instanceVariableNames_package_(aClass,_st(self._subclassNameFor_(aClass))._asSymbol(),[varName],"Compiler-Core");
  1641. return $1;
  1642. }, function($ctx1) {$ctx1.fill(self,"subclass:withVariable:",{aClass:aClass,varName:varName},smalltalk.Repl)})},
  1643. args: ["aClass", "varName"],
  1644. 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'",
  1645. messageSends: ["addSubclassOf:named:instanceVariableNames:package:", "asSymbol", "subclassNameFor:", "new"],
  1646. referencedClasses: ["ClassBuilder"]
  1647. }),
  1648. smalltalk.Repl);
  1649. smalltalk.addMethod(
  1650. smalltalk.method({
  1651. selector: "subclassNameFor:",
  1652. category: 'private',
  1653. fn: function (aClass){
  1654. var self=this;
  1655. return smalltalk.withContext(function($ctx1) {
  1656. var $2,$1;
  1657. $2=_st(_st(aClass)._name())._matchesOf_("\x5cd+$");
  1658. if(($receiver = $2) == nil || $receiver == undefined){
  1659. $1=_st(_st(aClass)._name()).__comma("2");
  1660. } else {
  1661. var counter;
  1662. counter=_st(_st(_st(_st(_st(aClass)._name())._matchesOf_("\x5cd+$"))._first())._asNumber()).__plus((1));
  1663. counter;
  1664. $1=_st(_st(aClass)._name())._replaceRegexp_with_("\x5cd+$"._asRegexp(),_st(counter)._asString());
  1665. };
  1666. return $1;
  1667. }, function($ctx1) {$ctx1.fill(self,"subclassNameFor:",{aClass:aClass},smalltalk.Repl)})},
  1668. args: ["aClass"],
  1669. 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'].",
  1670. messageSends: ["ifNotNil:ifNil:", "+", "asNumber", "first", "matchesOf:", "name", "replaceRegexp:with:", "asRegexp", "asString", ","],
  1671. referencedClasses: []
  1672. }),
  1673. smalltalk.Repl);
  1674. smalltalk.addMethod(
  1675. smalltalk.method({
  1676. selector: "main",
  1677. category: 'initialization',
  1678. fn: function (){
  1679. var self=this;
  1680. return smalltalk.withContext(function($ctx1) {
  1681. _st(self._new())._createInterface();
  1682. return self}, function($ctx1) {$ctx1.fill(self,"main",{},smalltalk.Repl.klass)})},
  1683. args: [],
  1684. source: "main\x0a\x09self new createInterface",
  1685. messageSends: ["createInterface", "new"],
  1686. referencedClasses: []
  1687. }),
  1688. smalltalk.Repl.klass);