Browse Source

added hello app from wiki 'My First Amber Project'

hhzl 11 years ago
parent
commit
b836ee4179
5 changed files with 72 additions and 0 deletions
  1. 0 0
      hello/New Text Document.txt
  2. 1 0
      hello/README.md
  3. 26 0
      hello/index.html
  4. 29 0
      hello/js/HelloApp.js
  5. 16 0
      hello/st/HelloApp.st

+ 0 - 0
hello/New Text Document.txt


+ 1 - 0
hello/README.md

@@ -0,0 +1 @@
+The 'hello' application from https://github.com/amber-smalltalk/amber/wiki/Writing-my-first-app

+ 26 - 0
hello/index.html

@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>My First Amber Project</title>
+    <script src="../vendor/amber/support/amber.js"></script>
+    <script src="../vendor/amber/support/requirejs/require.min.js"></script>
+    <script type="text/javascript">
+      require.config({ paths: {
+        'com_example_hello': 'js', //mapping compiled .js files
+        'com_example_hello/_source': 'st' //mapping smalltalk source files
+      }});
+      require(['amber/devel','com_example_hello/HelloApp'], function (smalltalk) {
+        smalltalk.defaultAmdNamespace = "com_example_hello"; //used for all new packages in IDE
+        smalltalk.initialize();
+        smalltalk.Hello._new()._begin();
+      });
+    </script>
+  </head>
+  <body>
+    <article>
+      <h1>My First Amber Project</h1>
+      <button onclick="require('amber_vm/smalltalk').Browser._open()">class browser</button>
+      <button id="sayHello">say hello</button>
+    </article>
+  </body>
+</html>

+ 29 - 0
hello/js/HelloApp.js

@@ -0,0 +1,29 @@
+define("com_example_hello/HelloApp", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_core/Kernel-Objects"], function(smalltalk,nil,_st){
+smalltalk.addPackage('HelloApp');
+smalltalk.packages["HelloApp"].transport = {"type":"amd","amdNamespace":"com_example_hello"};
+
+smalltalk.addClass('Hello', smalltalk.Object, [], 'HelloApp');
+smalltalk.addMethod(
+smalltalk.method({
+selector: "begin",
+category: 'not yet classified',
+fn: function (){
+var self=this;
+var msg,button;
+return smalltalk.withContext(function($ctx1) { 
+msg="Hello world!";
+button="#sayHello"._asJQuery();
+_st(button)._click_((function(){
+return smalltalk.withContext(function($ctx2) {
+return _st(button)._after_(_st("<p>".__comma(msg)).__comma("</p>"));
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
+return self}, function($ctx1) {$ctx1.fill(self,"begin",{msg:msg,button:button},smalltalk.Hello)})},
+args: [],
+source: "begin\x0a\x22Makes me say hello to the user.\x22\x0a\x0a| msg button |\x0amsg := 'Hello world!'.\x0abutton := '#sayHello' asJQuery.\x0abutton click: [button after: '<p>' , msg , '</p>'].",
+messageSends: ["asJQuery", "click:", "after:", ","],
+referencedClasses: []
+}),
+smalltalk.Hello);
+
+
+});

+ 16 - 0
hello/st/HelloApp.st

@@ -0,0 +1,16 @@
+Smalltalk current createPackage: 'HelloApp'!
+Object subclass: #Hello
+	instanceVariableNames: ''
+	package: 'HelloApp'!
+
+!Hello methodsFor: 'not yet classified'!
+
+begin
+"Makes me say hello to the user."
+
+| msg button |
+msg := 'Hello world!!'.
+button := '#sayHello' asJQuery.
+button click: [button after: '<p>' , msg , '</p>'].
+! !
+