tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject git commit: Juggle things a bit so that Underscore can be rolled into the core JavaScript stack
Date Mon, 11 Nov 2013 20:39:27 GMT
Updated Branches:
  refs/heads/master 8b5e3530d -> 4eb1fd2fd


Juggle things a bit so that Underscore can be rolled into the core JavaScript stack


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

Branch: refs/heads/master
Commit: 4eb1fd2fd71ae6a8c78402e61ee9d2c7f58fd21a
Parents: 8b5e353
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Mon Nov 11 12:19:53 2013 -0800
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Mon Nov 11 12:19:53 2013 -0800

----------------------------------------------------------------------
 .../tapestry5/modules/JavaScriptModule.java     | 12 +++++++++---
 .../assets/tapestry5/underscore-shim.js         | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4eb1fd2f/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
b/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
index e1b4a68..220e575 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
@@ -87,6 +87,8 @@ public class JavaScriptModule
      * <dt>requirejs</dt> <dd>The RequireJS AMD JavaScript library</dd>
      * <dt>scriptaculous.js, effects.js</dt> <dd>Optional JavaScript libraries
in compatibility mode (see {@link Trait#SCRIPTACULOUS})</dd>
      * <dt>t53-compatibility.js</dt> <dd>Optional JavaScript library (see
{@link Trait#INITIALIZERS})</dd>
+     * <dt>underscore-library, underscore-module</dt>
+     * <dt>The Underscore JavaScript library, and the shim that allows underscore to
be injected</dt>
      * <dt>t5/core/init</dt> <dd>Optional module related to t53-compatibility.js</dd>
      * <dt>bootstrap.css, tapestry.css, exception-frame.css, tapestry-console.css,
tree.css</dt>
      * <dd>CSS files</dd>
@@ -107,6 +109,7 @@ public class JavaScriptModule
                                                 String provider)
     {
         configuration.add("requirejs", new StackExtension(StackExtensionType.LIBRARY, requireJS));
+        configuration.add("underscore-library", new StackExtension(StackExtensionType.LIBRARY,
"${tapestry.asset.root}/underscore-1.5.2.js"));
 
         final String ROOT = "${tapestry.asset.root}";
 
@@ -142,6 +145,8 @@ public class JavaScriptModule
             configuration.add(full, new StackExtension(StackExtensionType.MODULE, full));
         }
 
+        configuration.add("underscore-module", new StackExtension(StackExtensionType.MODULE,
"underscore"));
+
         if (provider.equals("jquery"))
         {
             add(configuration, StackExtensionType.MODULE, "jquery");
@@ -260,8 +265,8 @@ public class JavaScriptModule
 
     @Contribute(ModuleManager.class)
     public static void setupBaseModules(MappedConfiguration<String, Object> configuration,
-                                        @Path("${tapestry.asset.root}/underscore-1.5.2.js")
-                                        Resource underscore,
+                                        @Path("${tapestry.asset.root}/underscore-shim.js")
+                                        Resource underscoreShim,
 
                                         @Path("${tapestry.asset.root}/jquery-shim.js")
                                         Resource jqueryShim,
@@ -278,7 +283,8 @@ public class JavaScriptModule
                                         @Path("${" + SymbolConstants.BOOTSTRAP_ROOT + "}/js/transition.js")
                                         Resource transition)
     {
-        configuration.add("underscore", new JavaScriptModuleConfiguration(underscore).exports("_"));
+        // The underscore shim module allows Underscore to be injected
+        configuration.add("underscore", new JavaScriptModuleConfiguration(underscoreShim));
         // Hacking around https://github.com/jrburke/requirejs/issues/534
         configuration.add("jquery-library", new JavaScriptModuleConfiguration(jQuery));
         configuration.add("jquery", new JavaScriptModuleConfiguration(jqueryShim));

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4eb1fd2f/tapestry-core/src/main/resources/META-INF/assets/tapestry5/underscore-shim.js
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/META-INF/assets/tapestry5/underscore-shim.js
b/tapestry-core/src/main/resources/META-INF/assets/tapestry5/underscore-shim.js
new file mode 100644
index 0000000..61c3ebe
--- /dev/null
+++ b/tapestry-core/src/main/resources/META-INF/assets/tapestry5/underscore-shim.js
@@ -0,0 +1,20 @@
+// Copyright 2013 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(function () {
+    // Because Underscore can load globally without causing a conflict, we can have the true
underscore library
+    // just be a part of the core stack. This doesn't work with jQuery because the $ symbol
can be a conflict
+    // between Prototype and jQuery when both are supported.
+    return _.noConflict();
+});


Mime
View raw message