tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [4/4] git commit: Create a core/console module Convert T5.console to dynamically re-invoke against core/console Add missing copyrights
Date Fri, 29 Jun 2012 01:11:45 GMT
Create a core/console module
Convert T5.console to dynamically re-invoke against core/console
Add missing copyrights


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/db60af79
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/db60af79
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/db60af79

Branch: refs/heads/5.4-js-rewrite
Commit: db60af7961d2cdf5f4ea626d8d0508ec95c00296
Parents: af4cc29
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Thu Jun 28 17:49:57 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Thu Jun 28 17:49:57 2012 -0700

----------------------------------------------------------------------
 .../tapestry5/corelib/modulejs/console.coffee      |   60 +++++++++++++
 .../apache/tapestry5/corelib/modulejs/init.coffee  |   14 +++
 .../tapestry5/corelib/modulejs/pageinit.coffee     |   21 ++++-
 .../resources/org/apache/tapestry5/t5-console.js   |   68 +++------------
 .../tapestry5/integration/app1/modulejs/alert.js   |   10 ++-
 5 files changed, 112 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/db60af79/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/console.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/console.coffee
b/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/console.coffee
new file mode 100644
index 0000000..fae394d
--- /dev/null
+++ b/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/console.coffee
@@ -0,0 +1,60 @@
+# Copyright 2012 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http:#www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+define ->
+  nativeConsole = {}
+  floatingConsole = null
+
+  exports =
+    DURATION : 10 # seconds
+
+  try
+    nativeConsole = console
+  catch e
+
+  display = (className, message) ->
+    # TODO: Dependency on Prototype here
+
+    unless floatingConsole
+      floatingConsole = new Element "div", class: "t-console"
+      $(document.body).insert top: floatingConsole
+
+    div = new Element "div", class: "t-console-entry #{className}"
+    div.update(message).hide()
+    floatingConsole.insert top:div
+
+    new Effect.Appear div, duration: .25
+
+    fade = new Effect.Fade div,
+      delay: exports.DURATION
+      afterFinish: -> div.remove()  # was T5.dom.remove(div)
+
+    div.observe "click", ->
+      effect.cancel()
+      div.remove() # was T5.dom.remove(div)
+
+  level = (className, consolefn) ->
+    (message) ->
+      # Display it floating
+      display className, message
+
+      # If native console available, go for it
+      consolefn and consolefn.call(console, message)
+
+  exports[name] = level("t-#{name}", nativeConsole[name]) for name in ["debug", "info", "warn"]
+  exports.error = level("t-err", nativeConsole.error)
+
+  # Return the exports; we keep a reference to it, so we can see exports.DURATION, even
+  # if someone else modifies it.
+  return exports
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/db60af79/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/init.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/init.coffee
b/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/init.coffee
index 31690da..f0c54b3 100644
--- a/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/init.coffee
+++ b/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/init.coffee
@@ -1,3 +1,17 @@
+# Copyright 2012 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http:#www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 # Compatibility module
 # Invokes functions on the T5.initializers namespace.
 # Introduced in 5.4, to be removed at some point in the future, when T5.initializers is itself
no more.

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/db60af79/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/pageinit.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/pageinit.coffee
b/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/pageinit.coffee
index a5ab345..42b611e 100644
--- a/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/pageinit.coffee
+++ b/tapestry-core/src/main/coffeescript/org/apache/tapestry5/corelib/modulejs/pageinit.coffee
@@ -1,5 +1,23 @@
-define ->
+# Copyright 2012 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http:#www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 
+# Single function module used for page initialization. The function is passed an array of
arrays;
+# the first value in the array defines the module to invoke. The module name may also indicate
the
+# function exported by the module, as a suffix following a colon: e.g., "my/module:myfunc".
+# Any additional values in the array are passed to the function. The context of the function
(this) is null.
+define ->
   invokeInitializer = (qualifiedName, initArguments...) ->
 
     [moduleName, functionName] = qualifiedName.split ':'
@@ -10,5 +28,6 @@ define ->
 
   # Exports this single function:
   (inits) ->
+    # apply will split the first value from the rest for us, implicitly.
     invokeInitializer.apply null, init for init in inits
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/db60af79/tapestry-core/src/main/resources/org/apache/tapestry5/t5-console.js
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/t5-console.js b/tapestry-core/src/main/resources/org/apache/tapestry5/t5-console.js
index df4c5c4..fe500f5 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/t5-console.js
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/t5-console.js
@@ -1,4 +1,4 @@
-// Copyright 2011 The Apache Software Foundation
+// Copyright 2011, 2012 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -12,63 +12,17 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-T5.define("console", function() {
+T5.define("console", function () {
 
-    // FireFox throws an exception is you reference the console when it is not enabled.
+    exports = {};
 
-    var nativeConsole = {}, floatingConsole;
+    T5._.each(["debug", "info", "warn", "error"], function (name) {
+        exports[name] = function (message) {
+            require(["core/console"], function (cc) {
+                cc[name].call(null, message);
+            });
+        };
+    });
 
-    try {
-        if (console) {
-            nativeConsole = console;
-        }
-    }
-    catch (e) {
-        // No true native console, the empty nativeConsole object will take its place.
-    }
-
-    function display(className, message) {
-        if (!floatingConsole) {
-            floatingConsole = new Element("div", { "class" : "t-console" });
-
-            $(document.body).insert({top: floatingConsole});
-        }
-
-        var div = new Element("div", { 'class' : "t-console-entry " + className }).update(message).hide();
-
-        floatingConsole.insert({ top: div });
-
-        new Effect.Appear(div, { duration: .25 });
-
-        var effect = new Effect.Fade(div, { delay:  T5.console.DURATION,
-            afterFinish: function () {
-                T5.dom.remove(div);
-            }
-        });
-
-        div.observe("click", function() {
-            effect.cancel();
-            T5.dom.remove(div);
-        });
-    }
-
-    function level(className, consolefn) {
-        return function (message) {
-            display(className, message);
-
-            // consolefn may be null when there is no native console, in which case
-            // do nothing more
-            consolefn && consolefn.call(console, message);
-        }
-    }
-
-    return {
-        /** Time, in seconds, that floating console messages are displayed to the user. */
-        DURATION  : 10,
-
-        debug : level("t-debug", nativeConsole.debug),
-        info : level("t-info", nativeConsole.info),
-        warn : level("t-warn", nativeConsole.warn),
-        error : level("t-err", nativeConsole.error)
-    };
+    return exports;
 });
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/db60af79/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/modulejs/alert.js
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/modulejs/alert.js
b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/modulejs/alert.js
index e88d257..487fabc 100644
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/modulejs/alert.js
+++ b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/modulejs/alert.js
@@ -1,4 +1,8 @@
-/** Simple module: no dependencies, exports an object directory (no hygenic function wrapper).
*/
-define({
-    alert: function (message) { window.alert("app/alert: " + message); }
+define(["core/console"], function (cc) {
+    return {
+        alert: function (message) {
+            cc.info("app/alert (module): " + message);
+            T5.console.info("app/alert (T5): " + message);
+        }
+    };
 });
\ No newline at end of file


Mime
View raw message