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 2010/05/21 22:05:40 UTC

svn commit: r947150 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/services/ main/java/org/apache/tapestry5/services/javascript/ test/app1/css/ test/java/org/apache/tapestry5/integration/app1/pages/nested/ tes...

Author: hlship
Date: Fri May 21 20:05:40 2010
New Revision: 947150

URL: http://svn.apache.org/viewvc?rev=947150&view=rev
Log:
TAP5-56: Add support for IE conditionals around included stylesheet links

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/css/ie-only.css   (with props)
    tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/ie_conditional_stylesheet.txt   (with props)
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StylesheetLink.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavascriptSupport.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/integration/app1/pages/nested/AssetDemo.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.tml

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StylesheetLink.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StylesheetLink.java?rev=947150&r1=947149&r2=947150&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StylesheetLink.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StylesheetLink.java Fri May 21 20:05:40 2010
@@ -16,6 +16,7 @@ package org.apache.tapestry5.internal.se
 
 import org.apache.tapestry5.dom.Element;
 import org.apache.tapestry5.internal.TapestryInternalUtils;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.services.javascript.StylesheetOptions;
 
 /**
@@ -65,7 +66,16 @@ public final class StylesheetLink
      */
     void add(Element container)
     {
+        String condition = options.getCondition();
+        boolean hasCondition = InternalUtils.isNonBlank(condition);
+
+        if (hasCondition)
+            container.raw(String.format("\n<!--[if %s]>\n", condition));
+
         container.element("link", "href", url, "rel", "stylesheet", "type", "text/css", "media", options.getMedia());
+
+        if (hasCondition)
+            container.raw("\n<![endif]-->\n");
     }
 
     @Override

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavascriptSupport.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavascriptSupport.java?rev=947150&r1=947149&r2=947150&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavascriptSupport.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavascriptSupport.java Fri May 21 20:05:40 2010
@@ -36,6 +36,10 @@ import org.apache.tapestry5.services.Env
  * <p>
  * The term "import" is used on many methods to indicate that the indicated resource (stack, library or stylesheet) will
  * only be added to the final Document once.
+ * <p>
+ * The name is slightly a misnomer, since there's a side-line of
+ * {@linkplain #importStylesheet(Asset, StylesheetOptions)
+ * importing stylesheets} as well.
  * 
  * @since 5.2.0
  */

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=947150&r1=947149&r2=947150&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 Fri May 21 20:05:40 2010
@@ -23,11 +23,17 @@ import org.apache.tapestry5.internal.Tap
  */
 public class StylesheetOptions
 {
-    private final String media;
+    private final String media, condition;
 
     public StylesheetOptions(String media)
     {
+        this(media, null);
+    }
+
+    public StylesheetOptions(String media, String condition)
+    {
         this.media = media;
+        this.condition = condition;
     }
 
     /**
@@ -39,20 +45,36 @@ public class StylesheetOptions
         return media;
     }
 
+    /**
+     * The Internet Explorer condition associated with the link. When non-blank, the
+     * &lt;link&gt; element will be written inside a specially formatted comment interpreted
+     * by Internet Explorer. Usually null.
+     * 
+     * @see http://en.wikipedia.org/wiki/Conditional_comment
+     */
+    public String getCondition()
+    {
+        return condition;
+    }
+
     @Override
     public String toString()
     {
-        return String.format("StylesheetOptions[media=%s]", media);
+        return String.format("StylesheetOptions[media=%s condition=%s]", media);
     }
 
     @Override
     public boolean equals(Object obj)
     {
+        if (obj == this)
+            return true;
+
         if (obj == null || !(obj instanceof StylesheetOptions))
             return false;
 
         StylesheetOptions sso = (StylesheetOptions) obj;
 
-        return TapestryInternalUtils.isEqual(media, sso.media);
+        return TapestryInternalUtils.isEqual(media, sso.media)
+                && TapestryInternalUtils.isEqual(condition, sso.condition);
     }
 }

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/css/ie-only.css
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/css/ie-only.css?rev=947150&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/css/ie-only.css (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/css/ie-only.css Fri May 21 20:05:40 2010
@@ -0,0 +1,6 @@
+DIV.ie-big-blue
+{
+    color: blue;
+    font-weight: bold;
+    size: x-large;
+}
\ No newline at end of file

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/css/ie-only.css
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.java?rev=947150&r1=947149&r2=947150&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.java Fri May 21 20:05:40 2010
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2010 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
+// 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,
@@ -15,8 +15,11 @@
 package org.apache.tapestry5.integration.app1.pages.nested;
 
 import org.apache.tapestry5.Asset;
+import org.apache.tapestry5.annotations.Environmental;
 import org.apache.tapestry5.annotations.Path;
 import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.javascript.JavascriptSupport;
+import org.apache.tapestry5.services.javascript.StylesheetOptions;
 
 public class AssetDemo
 {
@@ -28,6 +31,18 @@ public class AssetDemo
     @Path("tapestry-button.png")
     private Asset button;
 
+    @Inject
+    @Path("context:css/ie-only.css")
+    private Asset ieOnly;
+
+    @Environmental
+    private JavascriptSupport javascriptSupport;
+
+    void afterRender()
+    {
+        javascriptSupport.importStylesheet(ieOnly, new StylesheetOptions(null, "IE"));
+    }
+
     public Asset getIcon()
     {
         return icon;

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java?rev=947150&r1=947149&r2=947150&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java Fri May 21 20:05:40 2010
@@ -368,4 +368,22 @@ public class DocumentLinkerImplTest exte
 
         assertEquals(document.toString(), readFile("other_initialization.txt"));
     }
+
+    @Test
+    public void ie_conditional_stylesheet() throws Exception
+    {
+        Document document = new Document();
+
+        document.newRootElement("html");
+
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true, "1.2.3", true);
+
+        linker.addStylesheetLink(new StylesheetLink("everybody.css"));
+        linker.addStylesheetLink(new StylesheetLink("just_ie.css", new StylesheetOptions(null, "IE")));
+
+        linker.updateDocument(document);
+
+        assertEquals(document.toString(), readFile("ie_conditional_stylesheet.txt"));
+
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.tml?rev=947150&r1=947149&r2=947150&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/nested/AssetDemo.tml Fri May 21 20:05:40 2010
@@ -1,32 +1,41 @@
 <html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
 
-    <p>
-        This page demonstrates the ability to inject assets into components and pass them around as parameters.
+  <p>
+    This page demonstrates the ability to inject assets into components and pass them around as
+    parameters.
     </p>
 
-    <p>
-        The Tapestry banner:
+  <p>
+    The Tapestry banner:
     </p>
 
-    <img id="icon" src="${icon}"/>
+  <img id="icon" src="${icon}"/>
 
-    <p>
-        A classpath asset:
+  <p>
+    A classpath asset:
     </p>
 
-    <img id="button" src="${button}"/>
+  <img id="button" src="${button}"/>
 
 
-    <p>
-        Relative asset via asset: binding
+  <p>
+    Relative asset via asset: binding
     </p>
 
-    <img src="${asset:../smiley.png}"/>
+  <img src="${asset:../smiley.png}"/>
 
 
-    <p>
-        Context asset via context: binding
+  <p>
+    Context asset via context: binding
     </p>
 
-    <img id="viaContext" src="${context:images/asf_logo_wide.gif}"/>
+  <img id="viaContext" src="${context:images/asf_logo_wide.gif}"/>
+
+  <p>
+    IE Conditional Stylesheet:      
+    </p>
+
+  <div class="ie-big-blue">
+    Normal in most browsers, but Big and Blue in IE.
+    </div>
 </html>
\ No newline at end of file

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/ie_conditional_stylesheet.txt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/ie_conditional_stylesheet.txt?rev=947150&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/ie_conditional_stylesheet.txt (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/ie_conditional_stylesheet.txt Fri May 21 20:05:40 2010
@@ -0,0 +1,5 @@
+<html><head><link type="text/css" rel="stylesheet" href="everybody.css"></link>
+<!--[if IE]>
+<link type="text/css" rel="stylesheet" href="just_ie.css"></link>
+<![endif]-->
+</head></html>
\ No newline at end of file

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/ie_conditional_stylesheet.txt
------------------------------------------------------------------------------
    svn:eol-style = native