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/07/06 02:38:00 UTC

[1/16] git commit: Move responsibility for loading script libraries and initialization from DocumentLinker to ModuleManager

Updated Branches:
  refs/heads/5.4-js-rewrite 4cd5be6b3 -> 3d84263dd


Move responsibility for loading script libraries and initialization from DocumentLinker to ModuleManager


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

Branch: refs/heads/5.4-js-rewrite
Commit: 3d84263dd27991a868451107f727bf16d751ad7f
Parents: fe438b0
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Thu Jul 5 17:36:22 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Thu Jul 5 17:36:22 2012 -0700

----------------------------------------------------------------------
 .../internal/services/DocumentLinkerImpl.java      |   98 +++-------
 .../services/javascript/ModuleManagerImpl.java     |   43 ++++-
 .../apache/tapestry5/services/TapestryModule.java  |    8 +-
 .../services/javascript/ModuleManager.java         |   15 ++-
 .../resources/org/apache/tapestry5/core.properties |    5 +
 .../services/DocumentLinkerImplTest.groovy         |  154 ++++-----------
 6 files changed, 127 insertions(+), 196 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d84263d/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
index 1f529c5..02e0a79 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
@@ -23,6 +23,7 @@ import org.apache.tapestry5.services.javascript.InitializationPriority;
 import org.apache.tapestry5.services.javascript.ModuleManager;
 import org.apache.tapestry5.services.javascript.StylesheetLink;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -36,8 +37,6 @@ public class DocumentLinkerImpl implements DocumentLinker
 
     private final ModuleManager moduleManager;
 
-    private final boolean compactJSON;
-
     private final boolean omitGeneratorMetaTag;
 
     private final String tapestryBanner;
@@ -45,23 +44,22 @@ public class DocumentLinkerImpl implements DocumentLinker
     // Initially false; set to true when a scriptURL or any kind of initialization is added.
     private boolean hasScriptsOrInitializations;
 
+    private int initCount;
+
     /**
      * @param moduleManager
      *         used to identify the root folder for dynamically loaded modules
      * @param omitGeneratorMetaTag
      *         via symbol configuration
      * @param tapestryVersion
-     *         version of Tapestry framework (for meta tag)
-     * @param compactJSON
+ *         version of Tapestry framework (for meta tag)
      */
-    public DocumentLinkerImpl(ModuleManager moduleManager, boolean omitGeneratorMetaTag, String tapestryVersion, boolean compactJSON)
+    public DocumentLinkerImpl(ModuleManager moduleManager, boolean omitGeneratorMetaTag, String tapestryVersion)
     {
         this.moduleManager = moduleManager;
         this.omitGeneratorMetaTag = omitGeneratorMetaTag;
 
         tapestryBanner = String.format("Apache Tapestry Framework (version %s)", tapestryVersion);
-
-        this.compactJSON = compactJSON;
     }
 
     public void addStylesheetLink(StylesheetLink sheet)
@@ -81,7 +79,6 @@ public class DocumentLinkerImpl implements DocumentLinker
         addInitialization(priority, "core/pageinit", "evalJavaScript", new JSONArray().put(script));
     }
 
-    @Override
     public void addInitialization(InitializationPriority priority, String moduleName, String functionName, JSONArray arguments)
     {
         JSONArray init = new JSONArray();
@@ -101,6 +98,8 @@ public class DocumentLinkerImpl implements DocumentLinker
         InternalUtils.addToMapList(priorityToModuleInit, priority, init);
 
         hasScriptsOrInitializations = true;
+
+        initCount++;
     }
 
     /**
@@ -116,7 +115,9 @@ public class DocumentLinkerImpl implements DocumentLinker
         // If the document failed to render at all, that's a different problem and is reported elsewhere.
 
         if (root == null)
+        {
             return;
+        }
 
         addStylesheetsToHead(root, includedStylesheets);
 
@@ -194,6 +195,23 @@ public class DocumentLinkerImpl implements DocumentLinker
         return container;
     }
 
+    private List<JSONArray> forPriority(InitializationPriority... priorities)
+    {
+        List<JSONArray> result = new ArrayList<JSONArray>(initCount);
+
+        for (InitializationPriority p : priorities)
+        {
+            List<JSONArray> inits = priorityToModuleInit.get(p);
+
+            if (inits != null)
+            {
+                result.addAll(inits);
+            }
+        }
+
+        return result;
+    }
+
     /**
      * Adds {@code <script>} elements for the RequireJS library, then any statically includes JavaScript libraries
      * (including JavaScript stack virtual assets), then the initialization script block.
@@ -206,68 +224,10 @@ public class DocumentLinkerImpl implements DocumentLinker
         // In prior releases of Tapestry, we've vacillated about where the <script> tags go
         // (in <head> or at bottom of <body>). Switching to a module approach gives us a new chance to fix this.
         // Eventually, (nearly) everything will be loaded as modules.
-        // TODO: Do we need to include type="text/javascript"?
-
-        moduleManager.writeInitialization(body);
-
-        // Next, include all stacks and individual JavaScript files *after* RequireJS.
-
-        for (String scriptURL : scriptURLs)
-        {
-            body.element("script", "type", "text/javascript", "src", scriptURL);
-        }
-
-        if (priorityToModuleInit.isEmpty())
-        {
-            return;
-        }
-
-        StringBuilder block = new StringBuilder();
-
-        boolean wrapped = false;
-
-        for (InitializationPriority p : InitializationPriority.values())
-        {
-            if (p != InitializationPriority.IMMEDIATE && !wrapped
-                    && priorityToModuleInit.containsKey(p))
-            {
-
-                block.append("Tapestry.onDOMLoaded(function() {\n");
-
-                wrapped = true;
-            }
-
-            addModuleInits(block, priorityToModuleInit.get(p));
-        }
-
-        if (wrapped)
-        {
-            block.append("});\n");
-        }
-
-        body.element("script", "type", "text/javascript").raw(block.toString());
-    }
-
-    private void addModuleInits(StringBuilder block, List<JSONArray> moduleInits)
-    {
-        if (moduleInits == null)
-        {
-            return;
-        }
-
-        block.append("require([\"core/pageinit\"], function (pageinit) {\n");
-        block.append("  pageinit.initialize([");
-
-        String sep = "";
-
-        for (JSONArray init : moduleInits)
-        {
-            block.append(sep);
-            block.append(init.toString(compactJSON));
-            sep = ",\n  ";
-        }
 
-        block.append("]);\n});\n");
+        moduleManager.writeInitialization(body, scriptURLs,
+                forPriority(InitializationPriority.IMMEDIATE),
+                forPriority(InitializationPriority.EARLY, InitializationPriority.NORMAL, InitializationPriority.LATE));
     }
 
     private static Element createTemporaryContainer(Element headElement, String existingElementName, String newElementName)

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d84263d/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 7827151..d1fc891 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
@@ -21,11 +21,13 @@ import org.apache.tapestry5.dom.Element;
 import org.apache.tapestry5.func.F;
 import org.apache.tapestry5.func.Worker;
 import org.apache.tapestry5.internal.services.assets.ResourceChangeTracker;
+import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.annotations.PostInjection;
 import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.json.JSONArray;
 import org.apache.tapestry5.json.JSONObject;
 import org.apache.tapestry5.services.AssetSource;
 import org.apache.tapestry5.services.ComponentClassResolver;
@@ -42,6 +44,9 @@ public class ModuleManagerImpl implements ModuleManager
     private final String requireConfig;
 
     private final Asset requireJS;
+    private final Messages globalMessages;
+
+    private final boolean compactJSON;
 
     // Library names, sorted by order of descending length.
     private final List<String> libraryNames;
@@ -59,12 +64,14 @@ public class ModuleManagerImpl implements ModuleManager
                              @Path("${" + SymbolConstants.REQUIRE_JS + "}")
                              Asset requireJS,
                              Map<String, ShimModule> configuration,
-                             @Symbol(SymbolConstants.COMPACT_JSON)
-                             boolean compactJSON)
+                             Messages globalMessages, @Symbol(SymbolConstants.COMPACT_JSON)
+    boolean compactJSON)
     {
         this.requireJS = requireJS;
+        this.globalMessages = globalMessages;
+        this.compactJSON = compactJSON;
 
-        this.requireConfig = buildRequireJSConfig(constructor.constructAssetPath("module-root", ""), compactJSON, configuration);
+        this.requireConfig = buildRequireJSConfig(constructor.constructAssetPath("module-root", ""), configuration);
 
         classpathRoot = assetSource.resourceForPath("");
 
@@ -90,7 +97,7 @@ public class ModuleManagerImpl implements ModuleManager
         libraryNameToPackageNames.put("app", resolver.getPackagesForLibrary(""));
     }
 
-    private String buildRequireJSConfig(String baseURL, boolean compactJSON, Map<String, ShimModule> configuration)
+    private String buildRequireJSConfig(String baseURL, Map<String, ShimModule> configuration)
     {
         JSONObject shims = new JSONObject();
         JSONObject config = new JSONObject().put("baseUrl", baseURL).put("shim", shims);
@@ -129,12 +136,34 @@ public class ModuleManagerImpl implements ModuleManager
         tracker.clearOnInvalidation(cache);
     }
 
-    @Override
-    public void writeInitialization(Element body)
+    public void writeInitialization(Element body, List<String> scriptURLs, List<JSONArray> immediateInits, List<JSONArray> deferredInits)
     {
         body.element("script", "src", requireJS.toClientURL());
 
-        body.element("script", "type", "text/javascript").raw(requireConfig);
+        Element element = body.element("script", "type", "text/javascript");
+
+        element.raw(requireConfig);
+
+        StringBuilder content = new StringBuilder(1000);
+
+        content.append(globalMessages.format("core-page-initialization-template",
+                convert(scriptURLs),
+                convert(immediateInits),
+                convert(deferredInits)));
+
+        element.raw(content.toString());
+    }
+
+    private String convert(List<?> input)
+    {
+        JSONArray array = new JSONArray();
+
+        for (Object o : input)
+        {
+            array.put(o);
+        }
+
+        return array.toString(compactJSON);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d84263d/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
index 24176f2..74b0b87 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
@@ -1799,18 +1799,12 @@ public final class TapestryModule
 
                                          final ModuleManager moduleManager,
 
-                                         @Path("${" + SymbolConstants.REQUIRE_JS + "}")
-                                         final Asset requireJS,
-
                                          @Symbol(SymbolConstants.OMIT_GENERATOR_META)
                                          final boolean omitGeneratorMeta,
 
                                          @Symbol(SymbolConstants.TAPESTRY_VERSION)
                                          final String tapestryVersion,
 
-                                         @Symbol(SymbolConstants.COMPACT_JSON)
-                                         final boolean compactJSON,
-
                                          final ValidationDecoratorFactory validationDecoratorFactory,
 
                                          @Path("${tapestry.default-stylesheet}")
@@ -1820,7 +1814,7 @@ public final class TapestryModule
         {
             public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer)
             {
-                DocumentLinkerImpl linker = new DocumentLinkerImpl(moduleManager, omitGeneratorMeta, tapestryVersion, compactJSON);
+                DocumentLinkerImpl linker = new DocumentLinkerImpl(moduleManager, omitGeneratorMeta, tapestryVersion);
 
                 environment.push(DocumentLinker.class, linker);
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d84263d/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ModuleManager.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ModuleManager.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ModuleManager.java
index b7208ff..29d42fb 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ModuleManager.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ModuleManager.java
@@ -17,6 +17,10 @@ package org.apache.tapestry5.services.javascript;
 import org.apache.tapestry5.dom.Element;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.annotations.UsesMappedConfiguration;
+import org.apache.tapestry5.json.JSONArray;
+import org.apache.tapestry5.json.JSONObject;
+
+import java.util.List;
 
 /**
  * Responsible for managing access to the JavaScript modules.
@@ -34,12 +38,19 @@ public interface ModuleManager
      * Invoked by the internal {@link org.apache.tapestry5.internal.services.DocumentLinker} service to write the configuration
      * of the module system into the page, including the tag to load the RequireJS library, and the
      * necessary initialization of the client-side {@code require} object, including
-     * (critically) its baseUrl property.
+     * (critically) its baseUrl property. In addition, a call to the client-side function {@code core/pageinit:loadScriptsAndInitialize}
+     * is constructed to load static scripts and perform page initializations.
      *
      * @param body
      *         {@code <body>} element of the page, to which new {@code <script>>} element(s) will be added.
+     * @param scriptURLs
+     *         list of static JavaScript library URLs that must be loaded on the page, prior to any initializations
+     * @param immediateInits
+     *         list of immediate initializations that occur as soon as the static   JavaScript libraries are loaded
+     * @param deferredInits
+     *         List of deferred initializations that occur once the page has loaded
      */
-    void writeInitialization(Element body);
+    void writeInitialization(Element body, List<String> scriptURLs, List<JSONArray> immediateInits, List<JSONArray> deferredInits);
 
     /**
      * Given a module name (which may be a path of names separated by slashes), locates the corresponding {@link Resource}.

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d84263d/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties b/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties
index 8c7b79d..e21b4d4 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties
@@ -46,3 +46,8 @@ minimum-string-length=You must provide at least %d characters for %s.
 number-format-exception=You must provide a numeric value for %s.
 regexp=%2$s does not match pattern '%1$s'.
 required=You must provide a value for %s.
+
+core-page-initialization-template=\
+require(["core/pageinit"], function(pageinit) {\
+  pageinit.loadScriptsAndInitialize(%s, %s, %s); \
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/3d84263d/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
index 3b592e4..c25523a 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
@@ -14,6 +14,9 @@ import org.easymock.EasyMock
 import org.easymock.IAnswer
 import org.testng.annotations.Test
 
+import static org.easymock.EasyMock.eq
+import static org.easymock.EasyMock.isA
+
 class DocumentLinkerImplTest extends InternalBaseTestCase {
 
     def check(Document document, String expectedContent) throws Exception {
@@ -30,7 +33,7 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         document.newRootElement("not-html").text("not an HTML document")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3", true)
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3")
 
         // Only checked if there's something to link.
 
@@ -53,7 +56,7 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         document.newRootElement("not-html").text("not an HTML document")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3", true)
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3")
 
         // Only checked if there's something to link.
 
@@ -74,7 +77,7 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
     void missing_root_element_is_a_noop() {
         Document document = new Document()
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3", true)
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3")
 
         linker.addScriptLink("foo.js")
         linker.addScript(InitializationPriority.NORMAL, "doSomething();")
@@ -90,7 +93,9 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         document.newRootElement("html").element("body").element("p").text("Ready to be updated with scripts.")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(mockModuleManager(), true, "1.2.3", true)
+        def manager = mockModuleManager(["foo.js", "bar/baz.js"], [], [new JSONArray("core/pageinit:evalJavaScript", "pageInitialization();")])
+
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(manager, true, "1.2.3")
 
         replay()
 
@@ -102,12 +107,7 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         check document, '''
 <?xml version="1.0"?>
-<html><body><p>Ready to be updated with scripts.</p><!--MODULE-MANAGER-INITIALIZATION--><script src="foo.js" type="text/javascript"/><script src="bar/baz.js" type="text/javascript"/><script type="text/javascript">Tapestry.onDOMLoaded(function() {
-require(["core/pageinit"], function (pageinit) {
-  pageinit.initialize([["core/pageinit:evalJavaScript","pageInitialization();"]]);
-});
-});
-</script></body></html>
+<html><body><p>Ready to be updated with scripts.</p><!--MODULE-MANAGER-INITIALIZATION--></body></html>
 '''
 
         verify()
@@ -122,7 +122,7 @@ require(["core/pageinit"], function (pageinit) {
 
         document.newRootElement("html").element("body").element("p").text("Ready to be marked with generator meta.")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, false, "1.2.3", true)
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, false, "1.2.3")
 
         linker.updateDocument(document)
 
@@ -141,7 +141,7 @@ require(["core/pageinit"], function (pageinit) {
 
         document.newRootElement("no_html").text("Generator meta only added if root is html tag.")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, false, "1.2.3", true)
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, false, "1.2.3")
 
         linker.updateDocument(document)
 
@@ -158,7 +158,7 @@ require(["core/pageinit"], function (pageinit) {
 
         document.newRootElement("html").element("body").element("p").text("Ready to be updated with styles.")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3", true)
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3")
 
         linker.addStylesheetLink(new StylesheetLink("foo.css"))
         linker.addStylesheetLink(new StylesheetLink("bar/baz.css", new StylesheetOptions("print")))
@@ -178,7 +178,7 @@ require(["core/pageinit"], function (pageinit) {
         document.newRootElement("html").element("head").comment(" existing head ").container.element("body").text(
             "body content")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3", true)
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3")
 
         linker.addStylesheetLink(new StylesheetLink("foo.css"))
 
@@ -196,21 +196,18 @@ require(["core/pageinit"], function (pageinit) {
 
         document.newRootElement("html").element("body").element("p").text("Ready to be updated with scripts.")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(mockModuleManager(), true, "1.2.3", true)
+        def manager = mockModuleManager([], [new JSONArray("core/pageinit:evalJavaScript", "doSomething();")], [])
+
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(manager, true, "1.2.3")
 
         replay()
 
         linker.addScript(InitializationPriority.IMMEDIATE, "doSomething();")
-        linker.addScript(InitializationPriority.IMMEDIATE, "doSomethingElse();")
 
         linker.updateDocument(document)
 
         check document, '''
-<html><body><p>Ready to be updated with scripts.</p><!--MODULE-MANAGER-INITIALIZATION--><script type="text/javascript">require(["core/pageinit"], function (pageinit) {
-  pageinit.initialize([["core/pageinit:evalJavaScript","doSomething();"],
-  ["core/pageinit:evalJavaScript","doSomethingElse();"]]);
-});
-</script></body></html>
+<html><body><p>Ready to be updated with scripts.</p><!--MODULE-MANAGER-INITIALIZATION--></body></html>
 '''
 
         verify()
@@ -225,7 +222,9 @@ require(["core/pageinit"], function (pageinit) {
 
         document.newRootElement("html").element("notbody").element("p").text("Ready to be updated with scripts.")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(mockModuleManager(), true, "1.2.3", true)
+        def manager = mockModuleManager(["foo.js"], [], [])
+
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(manager, true, "1.2.3")
 
         replay()
 
@@ -235,33 +234,13 @@ require(["core/pageinit"], function (pageinit) {
 
         check document, '''
 <?xml version="1.0"?>
-<html><notbody><p>Ready to be updated with scripts.</p></notbody><body><!--MODULE-MANAGER-INITIALIZATION--><script src="foo.js" type="text/javascript"/></body></html>
+<html><notbody><p>Ready to be updated with scripts.</p></notbody><body><!--MODULE-MANAGER-INITIALIZATION--></body></html>
 '''
 
         verify()
     }
 
     @Test
-    void non_asset_script_link_disables_aggregation() throws Exception {
-        Document document = new Document()
-
-        document.newRootElement("html").element("body").element("p").text("Ready to be updated with scripts.")
-
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(mockModuleManager(), true, "1.2.3", true)
-
-        replay()
-
-        linker.addScriptLink("/context/foo.js")
-
-        linker.updateDocument(document)
-
-        assert document.toString().contains('''<script src="/context/foo.js" type="text/javascript">''')
-
-        verify()
-    }
-
-
-    @Test
     void immediate_initialization() throws Exception {
         Document document = new Document()
 
@@ -270,7 +249,9 @@ require(["core/pageinit"], function (pageinit) {
         head.element("meta")
         head.element("script")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(mockModuleManager(), true, "1.2.3", true)
+        def manager = mockModuleManager([], [new JSONArray("['immediate/module:myfunc', {'fred':'barney'}]")], [])
+
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(manager, true, "1.2.3")
 
         replay()
 
@@ -279,56 +260,12 @@ require(["core/pageinit"], function (pageinit) {
         linker.updateDocument(document)
 
         check document, '''
-<html><head><meta/><script></script></head><body><!--MODULE-MANAGER-INITIALIZATION--><script type="text/javascript">require(["core/pageinit"], function (pageinit) {
-  pageinit.initialize([["immediate/module:myfunc",{"fred":"barney"}]]);
-});
-</script></body></html>
+<html><head><meta/><script></script></head><body><!--MODULE-MANAGER-INITIALIZATION--></body></html>
 '''
 
         verify()
     }
 
-    @Test
-    void pretty_print_initialization() throws Exception {
-        Document document = new Document()
-
-        Element head = document.newRootElement("html").element("head")
-
-        head.element("meta")
-
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(mockModuleManager(), true, "1.2.3", false)
-
-        replay()
-
-        linker.addInitialization(InitializationPriority.NORMAL, "my/module", null, null)
-        linker.addInitialization(InitializationPriority.NORMAL, "my/other/module", "normal", new JSONArray(111, 222))
-        linker.addInitialization(InitializationPriority.LATE, "my/other/module", "late", new JSONArray(333, 444))
-
-        linker.updateDocument(document)
-
-        check document, '''
-<html><head><meta/></head><body><!--MODULE-MANAGER-INITIALIZATION--><script type="text/javascript">Tapestry.onDOMLoaded(function() {
-require(["core/pageinit"], function (pageinit) {
-  pageinit.initialize([[
-  "my/module"
-],
-  [
-  "my/other/module:normal",
-  111,
-  222
-]]);
-});
-require(["core/pageinit"], function (pageinit) {
-  pageinit.initialize([[
-  "my/other/module:late",
-  333,
-  444
-]]);
-});
-});
-</script></body></html>
-'''
-    }
 
     @Test
     void other_initialization() throws Exception {
@@ -339,7 +276,9 @@ require(["core/pageinit"], function (pageinit) {
         head.element("meta")
         head.element("script")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(mockModuleManager(), true, "1.2.3", true)
+        def manager = mockModuleManager([], [], [new JSONArray("['my/module', 'barney']")])
+
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(manager, true, "1.2.3")
 
         replay()
 
@@ -348,12 +287,7 @@ require(["core/pageinit"], function (pageinit) {
         linker.updateDocument(document)
 
         check document, '''
-<html><head><meta/><script></script></head><body><!--MODULE-MANAGER-INITIALIZATION--><script type="text/javascript">Tapestry.onDOMLoaded(function() {
-require(["core/pageinit"], function (pageinit) {
-  pageinit.initialize([["my/module","barney"]]);
-});
-});
-</script></body></html>
+<html><head><meta/><script></script></head><body><!--MODULE-MANAGER-INITIALIZATION--></body></html>
 '''
         verify()
     }
@@ -364,7 +298,7 @@ require(["core/pageinit"], function (pageinit) {
 
         document.newRootElement("html")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3", true)
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3")
 
         linker.addStylesheetLink(new StylesheetLink("everybody.css"))
         linker.addStylesheetLink(new StylesheetLink("just_ie.css", new StylesheetOptions().withCondition("IE")))
@@ -386,7 +320,7 @@ require(["core/pageinit"], function (pageinit) {
 
         document.newRootElement("html")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3", true)
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(null, true, "1.2.3")
 
         linker.addStylesheetLink(new StylesheetLink("whatever.css"))
         linker.addStylesheetLink(new StylesheetLink("insertion-point.css", new StylesheetOptions().asAjaxInsertionPoint()))
@@ -406,7 +340,11 @@ require(["core/pageinit"], function (pageinit) {
 
         head.element("meta")
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl(mockModuleManager(), true, "1.2.3", true)
+        def manager = mockModuleManager([], [], [new JSONArray("['my/module']"),
+            new JSONArray("my/other/module:normal", 111, 222),
+            new JSONArray("my/other/module:late", 333, 444)])
+
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(manager, true, "1.2.3")
 
         replay()
 
@@ -417,26 +355,20 @@ require(["core/pageinit"], function (pageinit) {
         linker.updateDocument(document)
 
         check document, '''
-<html><head><meta/></head><body><!--MODULE-MANAGER-INITIALIZATION--><script type="text/javascript">Tapestry.onDOMLoaded(function() {
-require(["core/pageinit"], function (pageinit) {
-  pageinit.initialize([["my/module"],
-  ["my/other/module:normal",111,222]]);
-});
-require(["core/pageinit"], function (pageinit) {
-  pageinit.initialize([["my/other/module:late",333,444]]);
-});
-});
-</script></body></html>
+<html><head><meta/></head><body><!--MODULE-MANAGER-INITIALIZATION--></body></html>
 '''
 
         verify()
     }
 
-    private ModuleManager mockModuleManager() {
+    private ModuleManager mockModuleManager(scripts, immediateInits, deferredInits) {
 
         ModuleManager mock = newMock(ModuleManager);
 
-        expect(mock.writeInitialization(EasyMock.isA(Element))).andAnswer({
+        expect(mock.writeInitialization(isA(Element),
+            eq(scripts),
+            eq(immediateInits),
+            eq(deferredInits))).andAnswer({
             def body = EasyMock.currentArguments[0]
 
             body.comment("MODULE-MANAGER-INITIALIZATION")