tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r980565 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/annotations/ main/java/org/apache/tapestry5/internal/services/ajax/ main/java/org/apache/tapestry5/internal/services/javascript/ main/java/org/apache/t...
Date Thu, 29 Jul 2010 20:38:04 GMT
Author: hlship
Date: Thu Jul 29 20:38:03 2010
New Revision: 980565

URL: http://svn.apache.org/viewvc?rev=980565&view=rev
Log:
Add support for dependencies from one JavaScriptStack to others

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/Import.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavaScriptStack.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptStack.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/StylesheetOptions.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/Import.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/Import.java?rev=980565&r1=980564&r2=980565&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/Import.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/Import.java
Thu Jul 29 20:38:03 2010
@@ -49,7 +49,9 @@ import org.apache.tapestry5.services.jav
 public @interface Import
 {
     /**
-     * JavaScript Stacks to import. Stacks are imported before individual libraries.
+     * JavaScript Stacks to import. Stacks are imported before individual libraries. Note
that
+     * stacks themselves may have {@linkplain JavaScriptStack#getStacks() dependencies on
other
+     * stacks}.
      * 
      * @see JavaScriptStack
      * @see JavaScriptSupport#importStack(String)

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java?rev=980565&r1=980564&r2=980565&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java
Thu Jul 29 20:38:03 2010
@@ -220,6 +220,11 @@ public class JavaScriptSupportImpl imple
 
         JavaScriptStack stack = javascriptStackSource.getStack(stackName);
 
+        for (String dependentStackname : stack.getStacks())
+        {
+            addAssetsFromStack(dependentStackname);
+        }
+
         stackLibraries.addAll(stackPathConstructor.constructPathsForJavaScriptStack(stackName));
 
         stylesheetLinks.addAll(stack.getStylesheets());

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavaScriptStack.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavaScriptStack.java?rev=980565&r1=980564&r2=980565&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavaScriptStack.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavaScriptStack.java
Thu Jul 29 20:38:03 2010
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry5.internal.services.javascript;
 
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.tapestry5.Asset;
@@ -61,4 +62,9 @@ public class CoreJavaScriptStack impleme
                 .toList();
     }
 
+    public List<String> getStacks()
+    {
+        return Collections.emptyList();
+    }
+
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java?rev=980565&r1=980564&r2=980565&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java
Thu Jul 29 20:38:03 2010
@@ -16,6 +16,7 @@ package org.apache.tapestry5.internal.se
 
 import java.text.DateFormatSymbols;
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 
@@ -59,8 +60,9 @@ public class DateFieldStack implements J
         Mapper<String, StylesheetLink> pathToStylesheetLink = pathToAsset
                 .combine(TapestryInternalUtils.assetToStylesheetLink);
 
-        javaScriptStack = F.flow("${tapestry.datepicker}/js/datepicker.js",
-                "org/apache/tapestry5/corelib/components/datefield.js").map(pathToAsset).toList();
+        javaScriptStack = F
+                .flow("${tapestry.datepicker}/js/datepicker.js", "org/apache/tapestry5/corelib/components/datefield.js")
+                .map(pathToAsset).toList();
 
         stylesheetStack = F.flow("${tapestry.datepicker}/css/datepicker.css").map(pathToStylesheetLink).toList();
     }
@@ -113,4 +115,8 @@ public class DateFieldStack implements J
         return stylesheetStack;
     }
 
+    public List<String> getStacks()
+    {
+        return Collections.emptyList();
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptStack.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptStack.java?rev=980565&r1=980564&r2=980565&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptStack.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptStack.java
Thu Jul 29 20:38:03 2010
@@ -18,6 +18,7 @@ import java.util.List;
 
 import org.apache.tapestry5.Asset;
 import org.apache.tapestry5.SymbolConstants;
+import org.apache.tapestry5.TapestryConstants;
 import org.apache.tapestry5.ioc.services.ThreadLocale;
 import org.apache.tapestry5.services.AssetSource;
 import org.apache.tapestry5.services.ClientInfrastructure;
@@ -30,16 +31,15 @@ import org.apache.tapestry5.services.Cli
  * of the ExtJS or YUI libraries.
  * <p>
  * A JavaScriptStack can be thought of as a generalization of Tapestry 5.1's {@link ClientInfrastructure},
which exists
- * now to define the "core" Javascript stack.
+ * now to define the "core" JavaScript stack.
  * <p>
  * A JavaScript assets of a stack may (when {@linkplain SymbolConstants#COMBINE_SCRIPTS enabled})
be exposed to the
  * client as a single URL (identifying the stack by name). The individual assets are combined
into a single virtual
  * asset, which is then streamed to the client.
  * <p>
  * Implementations may need to inject the {@link ThreadLocale} service in order to determine
the current locale (if any
- * of the assets are localized). They will generally need to inject they {@link AssetSource}
service as well.
- * <p>
- * A planned extension to this interface is to allow for dependencies between JavaScriptStacks.
+ * of the JavaScript library or stylesheet assets are localized). They will generally need
to inject the
+ * {@link AssetSource} service as well.
  * 
  * @since 5.2.0
  * @see ThreadLocale
@@ -47,12 +47,19 @@ import org.apache.tapestry5.services.Cli
 public interface JavaScriptStack
 {
     /**
+     * Returns a list of JavaScriptStack names that this stack depends on. Each stack will
be processed before
+     * the current stack (thus a dependency stack's libraries, stylesheets and initialization
is emitted before
+     * the dependent stack).
+     */
+    List<String> getStacks();
+
+    /**
      * Returns a list of <em>localized</em> assets for JavaScript libraries that
form the stack.
      */
     List<Asset> getJavaScriptLibraries();
 
     /**
-     * Returns a list of <em>localized<m/e> links for stylesheets that form the
stack.
+     * Returns a list of <em>localized</em> links for stylesheets that form the
stack.
      */
     List<StylesheetLink> getStylesheets();
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/StylesheetOptions.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/StylesheetOptions.java?rev=980565&r1=980564&r2=980565&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/StylesheetOptions.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/StylesheetOptions.java
Thu Jul 29 20:38:03 2010
@@ -60,7 +60,7 @@ public class StylesheetOptions
     @Override
     public String toString()
     {
-        return String.format("StylesheetOptions[media=%s condition=%s]", media);
+        return String.format("StylesheetOptions[media=%s condition=%s]", media, condition);
     }
 
     @Override

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java?rev=980565&r1=980564&r2=980565&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
Thu Jul 29 20:38:03 2010
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry5.internal.services.ajax;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -110,6 +111,7 @@ public class JavaScriptSupportImplTest e
 
         List<String> libraryPaths = Collections.emptyList();
         List<StylesheetLink> stylesheets = Collections.emptyList();
+        List<String> stacks = libraryPaths;
 
         expect(stackSource.getStack(InternalConstants.CORE_STACK_NAME)).andReturn(stack);
         expect(pathConstructor.constructPathsForJavaScriptStack(InternalConstants.CORE_STACK_NAME)).andReturn(
@@ -117,6 +119,8 @@ public class JavaScriptSupportImplTest e
         expect(stack.getStylesheets()).andReturn(stylesheets);
 
         expect(stack.getInitialization()).andReturn(null);
+
+        expect(stack.getStacks()).andReturn(stacks);
     }
 
     private void trainForCoreStack(DocumentLinker linker, JavaScriptStackSource stackSource,
@@ -133,6 +137,9 @@ public class JavaScriptSupportImplTest e
 
         expect(stack.getInitialization()).andReturn("stackInit();");
 
+        List<String> stacks = Collections.emptyList();
+        expect(stack.getStacks()).andReturn(stacks);
+
         linker.addScriptLink("stack1.js");
         linker.addScriptLink("stack2.js");
         linker.addStylesheetLink(stylesheetLink);
@@ -215,6 +222,9 @@ public class JavaScriptSupportImplTest e
 
         expect(stack.getInitialization()).andReturn("customInit();");
 
+        List<String> stacks = Collections.emptyList();
+        expect(stack.getStacks()).andReturn(stacks);
+
         linker.addScriptLink("stack.js");
         linker.addStylesheetLink(stylesheetLink);
 
@@ -236,6 +246,61 @@ public class JavaScriptSupportImplTest e
     }
 
     @Test
+    public void import_stack_with_dependencies()
+    {
+        DocumentLinker linker = mockDocumentLinker();
+        JavaScriptStackSource stackSource = mockJavaScriptStackSource();
+        JavaScriptStackPathConstructor pathConstructor = mockJavaScriptStackPathConstructor();
+
+        trainForCoreStack(linker, stackSource, pathConstructor);
+
+        JavaScriptStack child = mockJavaScriptStack();
+        JavaScriptStack parent = mockJavaScriptStack();
+
+        StylesheetLink parentStylesheetLink = new StylesheetLink("parent.css");
+
+        StylesheetLink childStylesheetLink = new StylesheetLink("child.css");
+
+        expect(stackSource.getStack("child")).andReturn(child);
+
+        expect(child.getStacks()).andReturn(Arrays.asList("parent"));
+
+        expect(stackSource.getStack("parent")).andReturn(parent);
+
+        expect(pathConstructor.constructPathsForJavaScriptStack("parent")).andReturn(Arrays.asList("parent.js"));
+        expect(parent.getStylesheets()).andReturn(Arrays.asList(parentStylesheetLink));
+
+        expect(parent.getInitialization()).andReturn("parentInit();");
+
+        expect(pathConstructor.constructPathsForJavaScriptStack("child")).andReturn(Arrays.asList("child.js"));
+        expect(child.getStylesheets()).andReturn(Arrays.asList(childStylesheetLink));
+
+        expect(child.getInitialization()).andReturn("childInit();");
+
+        expect(parent.getStacks()).andReturn(Collections.<String> emptyList());
+
+        linker.addScriptLink("parent.js");
+        linker.addScriptLink("child.js");
+
+        linker.addStylesheetLink(parentStylesheetLink);
+        linker.addStylesheetLink(childStylesheetLink);
+
+        linker.addScript(InitializationPriority.IMMEDIATE, "stackInit();");
+        linker.addScript(InitializationPriority.IMMEDIATE, "parentInit();");
+        linker.addScript(InitializationPriority.IMMEDIATE, "childInit();");
+
+        replay();
+
+        JavaScriptSupportImpl jss = new JavaScriptSupportImpl(linker, stackSource, pathConstructor);
+
+        jss.importStack("child");
+
+        jss.commit();
+
+        verify();
+    }
+
+    @Test
     public void duplicate_imported_libraries_are_filtered()
     {
         DocumentLinker linker = mockDocumentLinker();



Mime
View raw message