You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2012/11/01 21:44:31 UTC
[1/5] git commit: Add a STACK extension type for use with
ExtensibleJavaScriptStack
Updated Branches:
refs/heads/5.4-js-rewrite b1bd02711 -> 8131b9a8d
Add a STACK extension type for use with ExtensibleJavaScriptStack
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/8131b9a8
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/8131b9a8
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/8131b9a8
Branch: refs/heads/5.4-js-rewrite
Commit: 8131b9a8da8b8e99ab7d585c839640a0e1a70840
Parents: 58d8a7a
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Thu Nov 1 13:44:19 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Thu Nov 1 13:44:19 2012 -0700
----------------------------------------------------------------------
.../javascript/ExtensibleJavaScriptStack.java | 31 +++++++----
.../services/javascript/StackExtensionType.java | 10 ++++
.../ExtensibleJavaScriptStackTest.groovy | 41 +++++++++++----
3 files changed, 60 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8131b9a8/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ExtensibleJavaScriptStack.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ExtensibleJavaScriptStack.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ExtensibleJavaScriptStack.java
index a4b07b1..8a71505 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ExtensibleJavaScriptStack.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ExtensibleJavaScriptStack.java
@@ -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.
@@ -14,9 +14,6 @@
package org.apache.tapestry5.services.javascript;
-import java.util.Collections;
-import java.util.List;
-
import org.apache.tapestry5.Asset;
import org.apache.tapestry5.func.F;
import org.apache.tapestry5.func.Flow;
@@ -28,6 +25,8 @@ import org.apache.tapestry5.ioc.annotations.UsesOrderedConfiguration;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.services.AssetSource;
+import java.util.List;
+
/**
* An extensible implementation of {@link JavaScriptStack} that can be used as the implementation of a service.
* The contributions to the service are used to supply the libraries, stylesheets, and initialization for a
@@ -35,11 +34,11 @@ import org.apache.tapestry5.services.AssetSource;
* {@link ServiceBinder#bind(Class, Class)} and {@link ServiceBindingOptions#withMarker(Class...)} to construct the
* service, then use the marker annotation to inject the service when contributing the service into to the
* {@link JavaScriptStackSource}.
- * <p>
+ * <p/>
* A limitation of this implementation is that the contributed assets are not localized at all.
- *
- * @since 5.3
+ *
* @see StackExtension
+ * @since 5.3
*/
@UsesOrderedConfiguration(StackExtension.class)
public class ExtensibleJavaScriptStack implements JavaScriptStack
@@ -50,6 +49,8 @@ public class ExtensibleJavaScriptStack implements JavaScriptStack
private final List<StylesheetLink> stylesheets;
+ private final List<String> stacks;
+
private final String initialization;
private final Predicate<StackExtension> by(final StackExtensionType type)
@@ -68,7 +69,9 @@ public class ExtensibleJavaScriptStack implements JavaScriptStack
public String map(StackExtension element)
{
return element.value;
- };
+ }
+
+ ;
};
private final Mapper<String, Asset> stringToAsset = new Mapper<String, Asset>()
@@ -76,7 +79,9 @@ public class ExtensibleJavaScriptStack implements JavaScriptStack
public Asset map(String value)
{
return assetSource.getExpandedAsset(value);
- };
+ }
+
+ ;
};
private final Mapper<Asset, StylesheetLink> assetToStylesheetLink = new Mapper<Asset, StylesheetLink>()
@@ -84,7 +89,9 @@ public class ExtensibleJavaScriptStack implements JavaScriptStack
public StylesheetLink map(Asset asset)
{
return new StylesheetLink(asset);
- };
+ }
+
+ ;
};
public ExtensibleJavaScriptStack(AssetSource assetSource, List<StackExtension> configuration)
@@ -95,6 +102,8 @@ public class ExtensibleJavaScriptStack implements JavaScriptStack
libraries = extensions.filter(by(StackExtensionType.LIBRARY)).map(extractValue).map(stringToAsset).toList();
+ stacks = extensions.filter(by(StackExtensionType.STACK)).map(extractValue).toList();
+
stylesheets = extensions.filter(by(StackExtensionType.STYLESHEET)).map(extractValue).map(stringToAsset)
.map(assetToStylesheetLink).toList();
@@ -106,7 +115,7 @@ public class ExtensibleJavaScriptStack implements JavaScriptStack
public List<String> getStacks()
{
- return Collections.emptyList();
+ return stacks;
}
public List<Asset> getJavaScriptLibraries()
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8131b9a8/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/StackExtensionType.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/StackExtensionType.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/StackExtensionType.java
index 6bbb9c8..d6ca2a3 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/StackExtensionType.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/StackExtensionType.java
@@ -36,6 +36,16 @@ public enum StackExtensionType
LIBRARY,
/**
+ * A dependency on another JavaScriptStack. Note that this is especially useful as, starting in 5.4, there is
+ * no automatic dependency on the "core" stack, as there was in earlier versions.
+ *
+ * @see JavaScriptSupport#importStack(String)
+ * @see org.apache.tapestry5.services.javascript.JavaScriptStack#getStylesheets()
+ * @since 5.4
+ */
+ STACK,
+
+ /**
* A stylesheet. The extension value will be converted using {@link AssetSource#getExpandedAsset(String)},
* meaning that {@linkplain SymbolSource symbols} will be expanded.
*
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8131b9a8/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ExtensibleJavaScriptStackTest.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ExtensibleJavaScriptStackTest.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ExtensibleJavaScriptStackTest.groovy
index 7bbd196..1615c4b 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ExtensibleJavaScriptStackTest.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ExtensibleJavaScriptStackTest.groovy
@@ -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.
@@ -14,10 +14,11 @@
package org.apache.tapestry5.services.javascript;
-import org.apache.tapestry5.Asset;
-import org.apache.tapestry5.services.AssetSource;
-import org.apache.tapestry5.test.TapestryTestCase;
-import org.testng.annotations.Test;
+
+import org.apache.tapestry5.Asset
+import org.apache.tapestry5.services.AssetSource
+import org.apache.tapestry5.test.TapestryTestCase
+import org.testng.annotations.Test
/** @since 5.3 */
class ExtensibleJavaScriptStackTest extends TapestryTestCase {
@@ -37,8 +38,8 @@ class ExtensibleJavaScriptStackTest extends TapestryTestCase {
replay()
ExtensibleJavaScriptStack stack = new ExtensibleJavaScriptStack(mockSource, [
- new StackExtension (StackExtensionType.LIBRARY, lib1path),
- new StackExtension (StackExtensionType.LIBRARY, lib2path),
+ new StackExtension(StackExtensionType.LIBRARY, lib1path),
+ new StackExtension(StackExtensionType.LIBRARY, lib2path),
])
assert stack.stacks.empty
@@ -50,6 +51,24 @@ class ExtensibleJavaScriptStackTest extends TapestryTestCase {
}
@Test
+ void contributed_stack() {
+ AssetSource mockSource = mockAssetSource()
+
+ replay()
+
+ ExtensibleJavaScriptStack stack = new ExtensibleJavaScriptStack(mockSource, [
+ new StackExtension(StackExtensionType.STACK, "stacka"),
+ new StackExtension(StackExtensionType.STACK, "stackb"),
+ ])
+
+ assert stack.stacks == ["stacka", "stackb"]
+ assert stack.javaScriptLibraries.empty
+
+ verify()
+
+ }
+
+ @Test
void contributed_stylesheets_are_expanded() {
def stylesheet1path = '${stylesheet1}/stylesheet.css'
def stylesheet1URL = "/foo/ss1/stylesheet.css"
@@ -70,8 +89,8 @@ class ExtensibleJavaScriptStackTest extends TapestryTestCase {
replay()
ExtensibleJavaScriptStack stack = new ExtensibleJavaScriptStack(mockSource, [
- new StackExtension (StackExtensionType.STYLESHEET, stylesheet1path),
- new StackExtension (StackExtensionType.STYLESHEET, stylesheet2path),
+ new StackExtension(StackExtensionType.STYLESHEET, stylesheet1path),
+ new StackExtension(StackExtensionType.STYLESHEET, stylesheet2path),
])
assert stack.stacks.empty
@@ -89,8 +108,8 @@ class ExtensibleJavaScriptStackTest extends TapestryTestCase {
@Test
void initializations_are_combined() {
ExtensibleJavaScriptStack stack = new ExtensibleJavaScriptStack(null, [
- new StackExtension (StackExtensionType.INITIALIZATION, "doThis();"),
- new StackExtension (StackExtensionType.INITIALIZATION, "doThat();"),
+ new StackExtension(StackExtensionType.INITIALIZATION, "doThis();"),
+ new StackExtension(StackExtensionType.INITIALIZATION, "doThat();"),
])
assert stack.initialization == "doThis();\ndoThat();"