Browse Source

Merge pull request #64 from hhzl/gh56

Gh56 hello
Hannes Hirzel 9 years ago
parent
commit
3264af6ed3

+ 91 - 24
hello/Gruntfile.js

@@ -1,24 +1,91 @@
-module.exports = function(grunt) {
-  grunt.loadNpmTasks('../../node_modules/amber-dev');
-
-  grunt.registerTask('default', ['amberc:hello']);
-
-  grunt.initConfig({
-    pkg: grunt.file.readJSON('../package.json'),
-
-    amberc: {  
-      options: {
-        amber_dir: '../bower_components/amber',
-        closure_jar: ''
-      },
-      hello: {
-        src: ['st/HelloApp.st'],
-        libraries: ['Web'],
-        output_dir: 'js',
-        deploy: true,
-        amd_namespace: 'com_examples_hello'
-      }
-    }
-  });
-
-}
+'use strict';
+
+module.exports = function (grunt) {
+    var path = require('path');
+
+    // These plugins provide necessary tasks.
+    grunt.loadNpmTasks('grunt-contrib-clean');
+    grunt.loadNpmTasks('grunt-contrib-requirejs');
+    grunt.loadNpmTasks('grunt-execute');
+    grunt.loadNpmTasks('amber-dev');
+
+    // Default task.
+    grunt.registerTask('default', ['amberc:all']);
+    grunt.registerTask('test', ['amberc:test_runner', 'execute:test_runner', 'clean:test_runner']);
+    grunt.registerTask('devel', ['amdconfig:app', 'requirejs:devel']);
+    grunt.registerTask('deploy', ['amdconfig:app', 'requirejs:deploy']);
+
+    // Project configuration.
+    grunt.initConfig({
+        // Metadata.
+        // pkg: grunt.file.readJSON(''),
+        banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
+            '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
+            '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
+            '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
+            ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
+        // task configuration
+        amberc: {
+            options: {
+                amber_dir: path.join(__dirname, "bower_components", "amber"),
+                library_dirs: ['src'],
+                closure_jar: ''
+            },
+            all: {
+                src: [
+                    'src/HelloApp.st', // list all sources in dependency order
+                    'src/HelloApp-Tests.st' // list all tests in dependency order
+                ],
+                amd_namespace: 'amber-helloapp',
+                libraries: ['SUnit', 'Web']
+            },
+            test_runner: {
+                src: ['node_modules/amber-dev/lib/Test.st'],
+                libraries: [
+                    /* add dependencies packages here */
+                    'HelloApp', /* add other code-to-test packages here */
+                    'SUnit',
+                    'HelloApp-Tests' /* add other test packages here */
+                ],
+                main_class: 'NodeTestRunner',
+                output_name: 'test_runner'
+            }
+        },
+
+        amdconfig: {app: {dest: 'config.js'}},
+
+        requirejs: {
+            deploy: {options: {
+                mainConfigFile: "config.js",
+                onBuildWrite: function (moduleName, path, contents) {
+                    return moduleName === "config" ? contents + "\nrequire.config({map:{'*':{app:'deploy'}}});" : contents;
+                },
+                pragmas: {
+                    excludeIdeData: true,
+                    excludeDebugContexts: true
+                },
+                include: ['config', 'node_modules/requirejs/require', 'deploy'],
+                out: "the.js"
+            }},
+            devel: {options: {
+                mainConfigFile: "config.js",
+                onBuildWrite: function (moduleName, path, contents) {
+                    return moduleName === "config" ? contents + "\nrequire.config({map:{'*':{app:'devel'}}});" : contents;
+                },
+                include: ['config', 'node_modules/requirejs/require'],
+                out: "the.js"
+            }}
+        },
+
+        execute: {
+            test_runner: {
+                src: ['test_runner.js']
+            }
+        },
+
+        clean: {
+            test_runner: ['test_runner.js']
+        }
+    });
+
+};

+ 22 - 0
hello/LICENSE-MIT

@@ -0,0 +1,22 @@
+Copyright (c) 2014 hhzl
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.

+ 17 - 1
hello/README.md

@@ -1 +1,17 @@
-The 'hello' application from https://github.com/amber-smalltalk/amber/wiki/Writing-my-first-app
+# Hello Application
+
+Result of amber init
+
+## Getting Started
+
+Brought project alive (for example after `git clone`):
+
+```sh
+npm install
+bower install
+grunt devel
+```
+
+Developing the project (after brought alive):
+ 
+Start server with `amber serve` and go to `http://localhost:4000/` in your browser and follow the instructions

+ 60 - 0
hello/config.js

@@ -0,0 +1,60 @@
+/* DO NOT EDIT! This file is generated. */
+
+var require;
+if (!require) require = {config: function (x) {require = x;}};
+require.config({
+  "paths": {
+    "helios/showdown": "bower_components/showdown/src/showdown",
+    "requireJS": "node_modules/requirejs/require",
+    "jquery": "bower_components/jquery/jquery",
+    "jquery-ui": "bower_components/jquery-ui/jquery-ui.min",
+    "codemirror": "bower_components/codemirror",
+    "bootstrap2.3.2": "bower_components/bootstrap2.3.2/bootstrap",
+    "mousetrap": "bower_components/mousetrap/mousetrap",
+    "jquery.blockUI": "bower_components/blockui/jquery.blockUI",
+    "require-css": "bower_components/require-css",
+    "amber_lib/es5-shim": "bower_components/es5-shim",
+    "helios": "bower_components/helios/src",
+    "helios/resources": "bower_components/helios/resources",
+    "helios/index": "bower_components/helios/index",
+    "amber-ide-starter-dialog": "bower_components/amber-ide-starter-dialog/lib/idestarter",
+    "amber": "bower_components/amber/support",
+    "amber_vm": "bower_components/amber/support/deprecated-vm-files",
+    "amber_vm/_st": "bower_components/amber/support/deprecated-vm-files/as-receiver",
+    "amber_css": "bower_components/amber/support/resources",
+    "amber_core": "bower_components/amber/src",
+    "amber-helloapp": "src"
+  },
+  "rjs_comment1": "require.min should be removed",
+  "rjs_comment2": "it's backward compatibility hack if config finds",
+  "rjs_comment3": "support/requirejs before node_modules/requirejs;",
+  "rjs_comment4": "the former will go away in 0.14.0",
+  "shim": {
+    "jquery-ui": {
+      "deps": [
+        "jquery",
+        "jquery"
+      ]
+    },
+    "codemirror/lib/codemirror": {
+      "deps": [
+        "css!codemirror/lib/codemirror",
+        "css!codemirror/lib/codemirror"
+      ]
+    },
+    "bootstrap2.3.2/js/bootstrap": {
+      "deps": [
+        "jquery",
+        "css!bootstrap2.3.2/css/bootstrap"
+      ]
+    },
+    "ensure-console": {
+      "exports": "console"
+    }
+  },
+  "map": {
+    "*": {
+      "css": "require-css/css"
+    }
+  }
+});

+ 8 - 0
hello/deploy.js

@@ -0,0 +1,8 @@
+define([
+    'amber/deploy',
+    // --- packages to be deployed begin here ---
+    'amber-helloapp/HelloApp'
+    // --- packages to be deployed end here ---
+], function (amber) {
+    return amber;
+});

+ 9 - 0
hello/devel.js

@@ -0,0 +1,9 @@
+define([
+    'amber/devel',
+    './deploy',
+    // --- packages used only during development begin here ---
+    'amber-helloapp/HelloApp-Tests'
+    // --- packages used only during development end here ---
+], function (amber) {
+    return amber;
+});

+ 25 - 21
hello/index.html

@@ -1,26 +1,30 @@
-<!DOCTYPE html>
+<!DOCTYPE html>
 <html>
+
   <head>
-    <title>My First Amber Project</title>
-    <script src="../bower_components/amber/support/amber.js"></script>
-    <script src="../bower_components/amber/support/requirejs/require.min.js"></script>
-    <script type="text/javascript">
-      require.config({ paths: {
-        'com_examples_hello': 'js', //mapping compiled .js files
-        'com_examples_hello/_source': 'st' //mapping smalltalk source files
-      }});
-      require(['amber/devel','com_examples_hello/HelloApp'], function (smalltalk) {
-        smalltalk.defaultAmdNamespace = "com_examples_hello"; //used for all new packages in IDE
-        smalltalk.initialize();
-        smalltalk.Hello._new()._begin();
-      });
-    </script>
+    <title>Hello Application</title>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+    <meta name="author" content="hhzl" />
+    <script type='text/javascript' src='the.js'></script>
   </head>
+
   <body>
-    <article>
-      <h1>My First Amber Project</h1>
-      <button onclick="require('amber/helpers').globals.Browser._open()">class browser</button>
-      <button id="sayHello">say hello</button>
-    </article>
+  <p>Hi, hhzl! Welcome to Amber project: "Hello Application".</p>
+  <p>This is the place for your application's HTML. After getting familiar with Amber,
+      just remove this welcome contents from index.html and replace it with your own.</p>
+  <button id="amber-with">Hello from TagBrush >> with:</button>
+  <button id="jquery-append">Hello from jQuery append</button>
+  <ol id="output-list"></ol>
+  <script type='text/javascript'>
+      require(['app'], function (amber) {
+          amber.initialize({
+            //used for all new packages in IDE
+            'transport.defaultAmdNamespace': "amber-helloapp"
+          });
+          require(["amber-ide-starter-dialog"], function (dlg) { dlg.start(); });
+          amber.globals.HelloApp._start();
+      });
+  </script>
   </body>
-</html>
+
+</html>

+ 0 - 34
hello/js/HelloApp.js

@@ -1,34 +0,0 @@
-define("com_examples_hello/HelloApp", ["amber/boot", "amber_core/Kernel-Objects"], function($boot){
-var smalltalk=$boot.vm,nil=$boot.nil,_st=$boot.asReceiver,globals=$boot.globals;
-smalltalk.addPackage('HelloApp');
-smalltalk.packages["HelloApp"].transport = {"type":"amd","amdNamespace":"com_examples_hello"};
-
-smalltalk.addClass('Hello', globals.Object, [], 'HelloApp');
-smalltalk.addMethod(
-smalltalk.method({
-selector: "begin",
-protocol: 'not yet classified',
-fn: function (){
-var self=this;
-var msg,button;
-return smalltalk.withContext(function($ctx1) { 
-var $1,$2;
-msg="Hello world!";
-button="#sayHello"._asJQuery();
-_st(button)._click_((function(){
-return smalltalk.withContext(function($ctx2) {
-$1=button;
-$2=_st("<p>".__comma(msg)).__comma("</p>");
-$ctx2.sendIdx[","]=1;
-return _st($1)._after_($2);
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
-return self}, function($ctx1) {$ctx1.fill(self,"begin",{msg:msg,button:button},globals.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: []
-}),
-globals.Hello);
-
-
-});

+ 5 - 0
hello/local.amd.json

@@ -0,0 +1,5 @@
+{
+    "paths": {
+        "amber-helloapp": "src"
+    }
+}

+ 42 - 0
hello/package.json

@@ -0,0 +1,42 @@
+{
+  "name": "helloapp",
+  "title": "Hello Application",
+  "description": "Result of amber init",
+  "version": "0.1.0",
+  "homepage": "https://github.com/amber-smalltalk/amber-examples",
+  "author": {
+    "name": "",
+    "email": ""
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/amber-smalltalk/amber-examples.git"
+  },
+  "bugs": {
+    "url": "https://github.com/amber-smalltalk/amber-examples/issues"
+  },
+  "licenses": [
+    {
+      "type": "MIT",
+      "url": "https://github.com/amber-smalltalk/amber-examples/blob/master/LICENSE-MIT"
+    }
+  ],
+  "engines": {
+    "node": ">= 0.8.0"
+  },
+  "scripts": {
+    "test": "grunt test"
+  },
+  "devDependencies": {
+    "amber-dev": "^0.2.3",
+    "grunt": "^0.4.5",
+    "grunt-contrib-clean": "^0.6.0",
+    "grunt-contrib-requirejs": "^0.4.4",
+    "grunt-execute": "^0.2.2",
+    "requirejs": "^2.1.15"
+  },
+  "keywords": [
+    "Amber",
+    "Smalltalk"
+  ]
+}

+ 9 - 0
hello/src/HelloApp-Tests.js

@@ -0,0 +1,9 @@
+define("amber-helloapp/HelloApp-Tests", ["amber/boot", "amber_core/SUnit"], function($boot){
+var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
+var smalltalk=$core,_st=$recv,globals=$globals;
+$core.addPackage('HelloApp-Tests');
+$core.packages["HelloApp-Tests"].transport = {"type":"amd","amdNamespace":"amber-helloapp"};
+
+$core.addClass('HelloAppTest', $globals.TestCase, [], 'HelloApp-Tests');
+
+});

+ 5 - 0
hello/src/HelloApp-Tests.st

@@ -0,0 +1,5 @@
+Smalltalk createPackage: 'HelloApp-Tests'!
+TestCase subclass: #HelloAppTest
+	instanceVariableNames: ''
+	package: 'HelloApp-Tests'!
+

+ 144 - 0
hello/src/HelloApp.js

@@ -0,0 +1,144 @@
+define("amber-helloapp/HelloApp", ["amber/boot", "amber_core/Kernel-Objects"], function($boot){
+var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
+var smalltalk=$core,_st=$recv,globals=$globals;
+$core.addPackage('HelloApp');
+$core.packages["HelloApp"].transport = {"type":"amd","amdNamespace":"amber-helloapp"};
+
+$core.addClass('HelloApp', $globals.Object, [], 'HelloApp');
+$core.addMethod(
+$core.method({
+selector: "augmentPage",
+protocol: 'starting',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) { 
+//>>excludeEnd("ctx");
+var $1;
+$1="#amber-with"._asJQuery();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["asJQuery"]=1;
+//>>excludeEnd("ctx");
+$recv($1)._click_((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return self._doAmberWith();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
+//>>excludeEnd("ctx");
+}));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["click:"]=1;
+//>>excludeEnd("ctx");
+$recv("#jquery-append"._asJQuery())._click_((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return self._doJQueryAppend();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
+//>>excludeEnd("ctx");
+}));
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"augmentPage",{},$globals.HelloApp)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "augmentPage\x0a\x09'#amber-with' asJQuery click: [ self doAmberWith ].\x0a\x09'#jquery-append' asJQuery click: [ self doJQueryAppend ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["click:", "asJQuery", "doAmberWith", "doJQueryAppend"]
+}),
+$globals.HelloApp);
+
+$core.addMethod(
+$core.method({
+selector: "doAmberWith",
+protocol: 'action',
+fn: function (){
+var self=this;
+var tag;
+function $HTMLCanvas(){return $globals.HTMLCanvas||(typeof HTMLCanvas=="undefined"?nil:HTMLCanvas)}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) { 
+//>>excludeEnd("ctx");
+tag=$recv($recv($HTMLCanvas())._onJQuery_("#output-list"._asJQuery()))._root();
+$recv(tag)._with_((function(html){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $recv($recv(html)._li())._with_("Amber Web #with: added me!");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)});
+//>>excludeEnd("ctx");
+}));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["with:"]=1;
+//>>excludeEnd("ctx");
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"doAmberWith",{tag:tag},$globals.HelloApp)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "doAmberWith\x0a\x09| tag |\x0a\x09tag := (HTMLCanvas onJQuery: '#output-list' asJQuery) root.\x0a\x09tag with: [ :html | html li with: 'Amber Web #with: added me!' ]",
+referencedClasses: ["HTMLCanvas"],
+//>>excludeEnd("ide");
+messageSends: ["root", "onJQuery:", "asJQuery", "with:", "li"]
+}),
+$globals.HelloApp);
+
+$core.addMethod(
+$core.method({
+selector: "doJQueryAppend",
+protocol: 'action',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) { 
+//>>excludeEnd("ctx");
+$recv("#output-list"._asJQuery())._append_("<li>jQuery append added me!</li>");
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"doJQueryAppend",{},$globals.HelloApp)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "doJQueryAppend\x0a\x09'#output-list' asJQuery append: '<li>jQuery append added me!</li>'",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["append:", "asJQuery"]
+}),
+$globals.HelloApp);
+
+
+$core.addMethod(
+$core.method({
+selector: "start",
+protocol: 'starting',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) { 
+//>>excludeEnd("ctx");
+$recv(self._new())._augmentPage();
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"start",{},$globals.HelloApp.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "start\x0a\x09self new augmentPage",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["augmentPage", "new"]
+}),
+$globals.HelloApp.klass);
+
+});

+ 30 - 0
hello/src/HelloApp.st

@@ -0,0 +1,30 @@
+Smalltalk createPackage: 'HelloApp'!
+Object subclass: #HelloApp
+	instanceVariableNames: ''
+	package: 'HelloApp'!
+
+!HelloApp methodsFor: 'action'!
+
+doAmberWith
+	| tag |
+	tag := (HTMLCanvas onJQuery: '#output-list' asJQuery) root.
+	tag with: [ :html | html li with: 'Amber Web #with: added me!!' ]
+!
+
+doJQueryAppend
+	'#output-list' asJQuery append: '<li>jQuery append added me!!</li>'
+! !
+
+!HelloApp methodsFor: 'starting'!
+
+augmentPage
+	'#amber-with' asJQuery click: [ self doAmberWith ].
+	'#jquery-append' asJQuery click: [ self doJQueryAppend ]
+! !
+
+!HelloApp class methodsFor: 'starting'!
+
+start
+	self new augmentPage
+! !
+

+ 0 - 16
hello/st/HelloApp.st

@@ -1,16 +0,0 @@
-Smalltalk 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>'].
-! !
-

File diff suppressed because it is too large
+ 6 - 0
hello/the.js


Some files were not shown because too many files changed in this diff