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/03 00:59:32 UTC

[1/2] git commit: Disable core/console:debug when running in production mode

Updated Branches:
  refs/heads/5.4-js-rewrite 4407ba9a1 -> 4936ee3e3


Disable core/console:debug when running in production mode


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

Branch: refs/heads/5.4-js-rewrite
Commit: 4936ee3e3f7fd01a6813a904eb60acf07fcc5065
Parents: 758f867
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Fri Nov 2 16:59:27 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Fri Nov 2 16:59:27 2012 -0700

----------------------------------------------------------------------
 .../META-INF/modules/core/console.coffee           |   16 +++++++++++--
 .../javascript/ConfigureHTMLElementFilter.java     |   17 ++++++++++++--
 2 files changed, 27 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4936ee3e/tapestry-core/src/main/coffeescript/META-INF/modules/core/console.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/console.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/console.coffee
index 6f61807..d27127a 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/console.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/console.coffee
@@ -76,13 +76,23 @@ define ["core/spi", "core/builder", "_"], (spi, builder, _) ->
 
       return
 
-  # If native console available, go for it.  IE doesn't have debug, so we use log instead.
 
-  exports.debug = level "t-debug", (nativeConsole.debug or nativeConsole.log)
+  # Determine whether debug is enabled by checking for the necessary attribute (which is missing
+  # in production mode).
+  exports.debugEnabled = (document.documentElement.getAttribute "data-debug-enabled")?
+
+  # When debugging is not enabled, then the debug function becomes a no-op.
+  exports.debug =
+    if exports.debugEnabled
+      # If native console available, go for it.  IE doesn't have debug, so we use log instead.
+      level "t-debug", (nativeConsole.debug or nativeConsole.log)
+    else
+      ->
+
   exports.info = level "t-info", nativeConsole.info
   exports.warn = level "t-warn", nativeConsole.warn
   exports.error = level "t-err", nativeConsole.error
 
   # Return the exports; we keep a reference to it, so we can see exports.DURATION, even
-  # if some other module imports this one and modified that property.
+  # if some other module imports this one and modifies that property.
   return exports
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4936ee3e/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ConfigureHTMLElementFilter.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ConfigureHTMLElementFilter.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ConfigureHTMLElementFilter.java
index 2ec3df7..2ebd84e 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ConfigureHTMLElementFilter.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ConfigureHTMLElementFilter.java
@@ -15,7 +15,9 @@
 package org.apache.tapestry5.internal.services.javascript;
 
 import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.SymbolConstants;
 import org.apache.tapestry5.dom.Element;
+import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.ioc.services.ThreadLocale;
 import org.apache.tapestry5.services.MarkupRenderer;
 import org.apache.tapestry5.services.MarkupRendererFilter;
@@ -30,9 +32,12 @@ public class ConfigureHTMLElementFilter implements MarkupRendererFilter
 {
     private final ThreadLocale threadLocale;
 
-    public ConfigureHTMLElementFilter(ThreadLocale threadLocale)
+    private final boolean debugEnabled;
+
+    public ConfigureHTMLElementFilter(ThreadLocale threadLocale, @Symbol(SymbolConstants.PRODUCTION_MODE) boolean productionMode)
     {
         this.threadLocale = threadLocale;
+        this.debugEnabled = !productionMode;
     }
 
     @Override
@@ -44,11 +49,17 @@ public class ConfigureHTMLElementFilter implements MarkupRendererFilter
 
         Element html = writer.getDocument().find("html");
 
-        // If it is an HTML document, with a root HTML node, put data-locale
-        // attribute inplace for the client.
+        // If it is an HTML document, with a root HTML node, add attributes
+        // to describe locale, and if debug is enabled.
         if (html != null)
         {
             html.attributes("data-locale", threadLocale.getLocale().toString());
+
+            if (debugEnabled)
+            {
+                html.attributes("data-debug-enabled", "true");
+            }
+
         }
     }
 }