Examples.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. define(["amber/boot", "require", "amber/web/Web"], function($boot,requirejs){"use strict";
  2. var $core=$boot.api,nil=$boot.nilAsValue,$nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. var $pkg = $core.addPackage("Examples");
  4. $pkg.innerEval = function (expr) { return eval(expr); };
  5. $pkg.transport = {"type":"amd","amdNamespace":"amber/legacy"};
  6. $core.addClass("Counter", $globals.Widget, ["count", "header"], "Examples");
  7. //>>excludeStart("ide", pragmas.excludeIdeData);
  8. $globals.Counter.comment="This is a trivial Widget example mimicking the classic Counter example in Seaside.\x0aIn order to play with it, just evaluate the doit below in a workspace.\x0aThen take a look in the HTML document above the IDE.\x0a\x0a\x09\x09Counter tryExample";
  9. //>>excludeEnd("ide");
  10. $core.addMethod(
  11. $core.method({
  12. selector: "decrease",
  13. protocol: "actions",
  14. fn: function (){
  15. var self=this,$self=this;
  16. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  17. return $core.withContext(function($ctx1) {
  18. //>>excludeEnd("ctx");
  19. $self.count=$recv($self.count).__minus((1));
  20. $recv($self.header)._contents_((function(html){
  21. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  22. return $core.withContext(function($ctx2) {
  23. //>>excludeEnd("ctx");
  24. return $recv(html)._with_($recv($self.count)._asString());
  25. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  26. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)});
  27. //>>excludeEnd("ctx");
  28. }));
  29. return self;
  30. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  31. }, function($ctx1) {$ctx1.fill(self,"decrease",{})});
  32. //>>excludeEnd("ctx");
  33. },
  34. //>>excludeStart("ide", pragmas.excludeIdeData);
  35. args: [],
  36. source: "decrease\x0a\x09count := count - 1.\x0a\x09header contents: [ :html | html with: count asString ]",
  37. referencedClasses: [],
  38. //>>excludeEnd("ide");
  39. pragmas: [],
  40. messageSends: ["-", "contents:", "with:", "asString"]
  41. }),
  42. $globals.Counter);
  43. $core.addMethod(
  44. $core.method({
  45. selector: "increase",
  46. protocol: "actions",
  47. fn: function (){
  48. var self=this,$self=this;
  49. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  50. return $core.withContext(function($ctx1) {
  51. //>>excludeEnd("ctx");
  52. $self.count=$recv($self.count).__plus((1));
  53. $recv($self.header)._contents_((function(html){
  54. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  55. return $core.withContext(function($ctx2) {
  56. //>>excludeEnd("ctx");
  57. return $recv(html)._with_($recv($self.count)._asString());
  58. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  59. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)});
  60. //>>excludeEnd("ctx");
  61. }));
  62. return self;
  63. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  64. }, function($ctx1) {$ctx1.fill(self,"increase",{})});
  65. //>>excludeEnd("ctx");
  66. },
  67. //>>excludeStart("ide", pragmas.excludeIdeData);
  68. args: [],
  69. source: "increase\x0a\x09count := count + 1.\x0a\x09header contents: [ :html | html with: count asString ]",
  70. referencedClasses: [],
  71. //>>excludeEnd("ide");
  72. pragmas: [],
  73. messageSends: ["+", "contents:", "with:", "asString"]
  74. }),
  75. $globals.Counter);
  76. $core.addMethod(
  77. $core.method({
  78. selector: "initialize",
  79. protocol: "initialization",
  80. fn: function (){
  81. var self=this,$self=this;
  82. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  83. return $core.withContext(function($ctx1) {
  84. //>>excludeEnd("ctx");
  85. (
  86. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  87. $ctx1.supercall = true,
  88. //>>excludeEnd("ctx");
  89. ($globals.Counter.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($self, []));
  90. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  91. $ctx1.supercall = false;
  92. //>>excludeEnd("ctx");;
  93. $self.count=(0);
  94. return self;
  95. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  96. }, function($ctx1) {$ctx1.fill(self,"initialize",{})});
  97. //>>excludeEnd("ctx");
  98. },
  99. //>>excludeStart("ide", pragmas.excludeIdeData);
  100. args: [],
  101. source: "initialize\x0a\x09super initialize.\x0a\x09count := 0",
  102. referencedClasses: [],
  103. //>>excludeEnd("ide");
  104. pragmas: [],
  105. messageSends: ["initialize"]
  106. }),
  107. $globals.Counter);
  108. $core.addMethod(
  109. $core.method({
  110. selector: "renderOn:",
  111. protocol: "rendering",
  112. fn: function (html){
  113. var self=this,$self=this;
  114. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  115. return $core.withContext(function($ctx1) {
  116. //>>excludeEnd("ctx");
  117. var $1,$2,$3;
  118. $1=$recv(html)._h1();
  119. $recv($1)._with_($recv($self.count)._asString());
  120. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  121. $ctx1.sendIdx["with:"]=1;
  122. //>>excludeEnd("ctx");
  123. $self.header=$recv($1)._yourself();
  124. $2=$recv(html)._button();
  125. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  126. $ctx1.sendIdx["button"]=1;
  127. //>>excludeEnd("ctx");
  128. $recv($2)._with_("++");
  129. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  130. $ctx1.sendIdx["with:"]=2;
  131. //>>excludeEnd("ctx");
  132. $recv($2)._onClick_((function(){
  133. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  134. return $core.withContext(function($ctx2) {
  135. //>>excludeEnd("ctx");
  136. return $self._increase();
  137. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  138. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  139. //>>excludeEnd("ctx");
  140. }));
  141. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  142. $ctx1.sendIdx["onClick:"]=1;
  143. //>>excludeEnd("ctx");
  144. $3=$recv(html)._button();
  145. $recv($3)._with_("--");
  146. $recv($3)._onClick_((function(){
  147. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  148. return $core.withContext(function($ctx2) {
  149. //>>excludeEnd("ctx");
  150. return $self._decrease();
  151. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  152. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  153. //>>excludeEnd("ctx");
  154. }));
  155. return self;
  156. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  157. }, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html})});
  158. //>>excludeEnd("ctx");
  159. },
  160. //>>excludeStart("ide", pragmas.excludeIdeData);
  161. args: ["html"],
  162. source: "renderOn: html\x0a\x09header := html h1\x0a\x09\x09with: count asString;\x0a\x09\x09yourself.\x0a\x09html button\x0a\x09\x09with: '++';\x0a\x09\x09onClick: [ self increase ].\x0a\x09html button\x0a\x09\x09with: '--';\x0a\x09\x09onClick: [ self decrease ]",
  163. referencedClasses: [],
  164. //>>excludeEnd("ide");
  165. pragmas: [],
  166. messageSends: ["with:", "h1", "asString", "yourself", "button", "onClick:", "increase", "decrease"]
  167. }),
  168. $globals.Counter);
  169. $core.addMethod(
  170. $core.method({
  171. selector: "tryExample",
  172. protocol: "example",
  173. fn: function (){
  174. var self=this,$self=this;
  175. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  176. return $core.withContext(function($ctx1) {
  177. //>>excludeEnd("ctx");
  178. $recv($self._new())._appendToBrush_("body"._asBrush());
  179. return self;
  180. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  181. }, function($ctx1) {$ctx1.fill(self,"tryExample",{})});
  182. //>>excludeEnd("ctx");
  183. },
  184. //>>excludeStart("ide", pragmas.excludeIdeData);
  185. args: [],
  186. source: "tryExample\x0a\x09\x22In order to play with the Counter, just select the\x0a\x09doit below and press the Do it button. Then take a\x0a\x09look in the HTML document above the IDE.\x22\x0a\x0a\x09\x22Counter tryExample\x22\x0a\x09\x09self new appendToBrush: 'body' asBrush",
  187. referencedClasses: [],
  188. //>>excludeEnd("ide");
  189. pragmas: [],
  190. messageSends: ["appendToBrush:", "new", "asBrush"]
  191. }),
  192. $globals.Counter.a$cls);
  193. });