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/12/22 00:31:47 UTC

git commit: TAP5-1807: In development mode, Tapestry should include a tag to identify the active page

Updated Branches:
  refs/heads/master 50b94acb6 -> a40c691db


TAP5-1807: In development mode, Tapestry should include a <meta> tag to identify the active page


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

Branch: refs/heads/master
Commit: a40c691db54d6ebacdecce18a4da70b462ef5c32
Parents: 50b94ac
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Fri Dec 21 15:31:44 2012 -0800
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Fri Dec 21 15:31:44 2012 -0800

----------------------------------------------------------------------
 .../internal/services/PageNameMetaInjector.java    |   58 +++++++++++++++
 .../apache/tapestry5/services/TapestryModule.java  |   23 +++++-
 .../tapestry5/integration/app1/MiscTests.groovy    |    8 ++
 3 files changed, 84 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a40c691d/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageNameMetaInjector.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageNameMetaInjector.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageNameMetaInjector.java
new file mode 100644
index 0000000..d46c589
--- /dev/null
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageNameMetaInjector.java
@@ -0,0 +1,58 @@
+// 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;
+
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.dom.Document;
+import org.apache.tapestry5.dom.Element;
+import org.apache.tapestry5.services.MarkupRenderer;
+import org.apache.tapestry5.services.MarkupRendererFilter;
+import org.apache.tapestry5.services.RequestGlobals;
+
+/**
+ * Injects a {@code <meta/>} element into the {@code <head/>} to identify the Tapestry page name.
+ * This filter is only active during development, not production.
+ *
+ * @since 5.4
+ */
+public class PageNameMetaInjector implements MarkupRendererFilter
+{
+    private final RequestGlobals globals;
+
+    public PageNameMetaInjector(RequestGlobals globals)
+    {
+        this.globals = globals;
+    }
+
+    @Override
+    public void renderMarkup(MarkupWriter writer, MarkupRenderer delegate)
+    {
+        delegate.renderMarkup(writer);
+
+        String pageName = globals.getActivePageName();
+
+        Document document = writer.getDocument();
+
+        Element element = document.find("html/head");
+
+        if (element != null)
+        {
+            element.element("meta",
+                    "name", "tapestry-page-name",
+                    "content", pageName);
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a40c691d/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 be30ea1..c68da8b 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
@@ -1210,7 +1210,7 @@ public final class TapestryModule
 
     public static ComponentClassResolver buildComponentClassResolver(@Autobuild
                                                                      ComponentClassResolverImpl service, @ComponentClasses
-    InvalidationEventHub hub)
+                                                                     InvalidationEventHub hub)
     {
         // Allow the resolver to clean its cache when the component classes
         // change
@@ -1430,7 +1430,7 @@ public final class TapestryModule
      */
     public static DataTypeAnalyzer buildDefaultDataTypeAnalyzer(@Autobuild
                                                                 DefaultDataTypeAnalyzer service, @ComponentClasses
-    InvalidationEventHub hub)
+                                                                InvalidationEventHub hub)
     {
         hub.addInvalidationCallback(service);
 
@@ -1796,12 +1796,14 @@ public final class TapestryModule
      * <dl>
      * <dt>DocumentLinker</dt>
      * <dd>Provides {@link org.apache.tapestry5.internal.services.DocumentLinker}</dd>
-     * <dt>ClientBehaviorSupport</dt>
+     * <dt>ClientBehaviorSupport (deprecated in 5.4)</dt>
      * <dd>Provides {@link ClientBehaviorSupport}</dd>
      * <dt>Heartbeat</dt>
      * <dd>Provides {@link org.apache.tapestry5.services.Heartbeat}</dd>
-     * <dt>ValidationDecorator</dt>
+     * <dt>ValidationDecorator (deprecated in 5.4)</dt>
      * <dd>Provides {@link org.apache.tapestry5.ValidationDecorator} (via {@link ValidationDecoratorFactory#newInstance(org.apache.tapestry5.MarkupWriter)})</dd>
+     * <dt>PageNameMeta (since 5.4)</dt>
+     * <dd>Renders a {@code <meta/>} tag describing the active page name (development mode only)</dd>
      * </dl>
      */
     public void contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter> configuration,
@@ -1814,6 +1816,9 @@ public final class TapestryModule
                                          @Symbol(SymbolConstants.TAPESTRY_VERSION)
                                          final String tapestryVersion,
 
+                                         @Symbol(SymbolConstants.PRODUCTION_MODE)
+                                         boolean productionMode,
+
                                          final ValidationDecoratorFactory validationDecoratorFactory)
     {
         MarkupRendererFilter documentLinker = new MarkupRendererFilter()
@@ -1883,6 +1888,14 @@ public final class TapestryModule
         configuration.add("ClientBehaviorSupport", clientBehaviorSupport, "after:JavaScriptSupport");
         configuration.add("Heartbeat", heartbeat);
         configuration.add("ValidationDecorator", defaultValidationDecorator);
+
+        if (productionMode)
+        {
+            configuration.add("PageNameMeta", null);
+        } else
+        {
+            configuration.addInstance("PageNameMeta", PageNameMetaInjector.class);
+        }
     }
 
     /**
@@ -2212,7 +2225,7 @@ public final class TapestryModule
     public void contributeApplicationInitializer(OrderedConfiguration<ApplicationInitializerFilter> configuration,
                                                  final TypeCoercer typeCoercer, final ComponentClassResolver componentClassResolver, @ComponentClasses
     final InvalidationEventHub invalidationEventHub, final @Autobuild
-    RestoreDirtySessionObjects restoreDirtySessionObjects)
+                                                 RestoreDirtySessionObjects restoreDirtySessionObjects)
     {
         final Runnable callback = new Runnable()
         {

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a40c691d/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy
index 472d2f4..1bd6c4f 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy
@@ -15,4 +15,12 @@ class MiscTests extends TapestryCoreTestCase {
 
     assertTextPresent "[Operation Description]"
   }
+
+    @Test
+    void meta_tag_identifying_page_name_is_present()
+    {
+        openLinks "Zone Demo"
+
+        assertAttribute "//meta[@name='tapestry-page-name']/@content", "nested/ZoneDemo"
+    }
 }