tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [9/15] git commit: Setup a no-op AssetRequestHandler for module requests
Date Wed, 27 Jun 2012 01:10:17 GMT
Setup a no-op AssetRequestHandler for module requests


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

Branch: refs/heads/5.4-js-rewrite
Commit: 682ae3d946f393e8820d0071a8eccbf3d7573542
Parents: 3d93678
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Tue Jun 26 16:11:25 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Tue Jun 26 16:11:25 2012 -0700

----------------------------------------------------------------------
 .../javascript/ModuleAssetRequestHandler.java      |   35 +++++++++++++++
 .../services/javascript/ModuleManagerImpl.java     |   14 +++++-
 .../services/javascript/JavaScriptModule.java      |   10 ++++
 3 files changed, 57 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/682ae3d9/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleAssetRequestHandler.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleAssetRequestHandler.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleAssetRequestHandler.java
new file mode 100644
index 0000000..baac006
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleAssetRequestHandler.java
@@ -0,0 +1,35 @@
+// 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.
+
+package org.apache.tapestry5.internal.services.javascript;
+
+import org.apache.tapestry5.internal.services.AssetDispatcher;
+import org.apache.tapestry5.services.Request;
+import org.apache.tapestry5.services.Response;
+import org.apache.tapestry5.services.assets.AssetRequestHandler;
+
+import java.io.IOException;
+
+/**
+ * Handler contributed to {@link AssetDispatcher} with key "module-root". It interprets the
extra path as a module name,
+ * and searches for the corresponding JavaScript module.
+ */
+public class ModuleAssetRequestHandler implements AssetRequestHandler
+{
+    @Override
+    public boolean handleAssetRequest(Request request, Response response, String extraPath)
throws IOException
+    {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/682ae3d9/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java
index c329872..f84ccdf 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java
@@ -15,14 +15,24 @@
 package org.apache.tapestry5.internal.services.javascript;
 
 import org.apache.tapestry5.dom.Element;
+import org.apache.tapestry5.services.assets.AssetPathConstructor;
 import org.apache.tapestry5.services.javascript.ModuleManager;
 
 public class ModuleManagerImpl implements ModuleManager
 {
+    private final String configuration;
+
+    public ModuleManagerImpl(AssetPathConstructor constructor)
+    {
+        String baseURL = constructor.constructAssetPath("module-root", "");
+
+        configuration = String.format("require.config({baseUrl:\"%s\"});\n",
+                baseURL);
+    }
+
     @Override
     public void writeConfiguration(Element scriptElement)
     {
-        scriptElement.raw(String.format("require.config({baseUrl:\"%s\"});\n",
-                "/placeholder-base-url"));
+        scriptElement.raw(configuration);
     }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/682ae3d9/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java
b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java
index 9342cc1..11026a0 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java
@@ -16,6 +16,7 @@ package org.apache.tapestry5.services.javascript;
 
 import org.apache.tapestry5.MarkupWriter;
 import org.apache.tapestry5.RenderSupport;
+import org.apache.tapestry5.services.AssetRequestDispatcher;
 import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.internal.services.DocumentLinker;
 import org.apache.tapestry5.internal.services.RenderSupportImpl;
@@ -29,6 +30,7 @@ import org.apache.tapestry5.ioc.services.SymbolSource;
 import org.apache.tapestry5.ioc.util.IdAllocator;
 import org.apache.tapestry5.json.JSONObject;
 import org.apache.tapestry5.services.*;
+import org.apache.tapestry5.services.assets.AssetRequestHandler;
 
 /**
  * Defines the services related to JavaScript.
@@ -209,4 +211,12 @@ public class JavaScriptModule
         configuration.add("JavaScriptSupport", javascriptSupport, "after:DocumentLinker");
         configuration.add("RenderSupport", renderSupport);
     }
+
+    @Contribute(Dispatcher.class)
+    @AssetRequestDispatcher
+    public static void handleModuleAssetRequests(MappedConfiguration<String, AssetRequestHandler>
configuration)
+    {
+        configuration.addInstance("module-root", ModuleAssetRequestHandler.class);
+    }
+
 }


Mime
View raw message