]> source.dussan.org Git - vaadin-framework.git/commitdiff
Applied patch fixing #9347 (mixin w/ args + nested blocks), includes test
authorMarc Englund <marc@vaadin.com>
Wed, 29 Aug 2012 15:19:21 +0000 (18:19 +0300)
committerMarc Englund <marc@vaadin.com>
Wed, 29 Aug 2012 15:19:21 +0000 (18:19 +0300)
build/build.xml
sass/src/com/vaadin/sass/tree/BlockNode.java
sass/src/com/vaadin/sass/util/Clonable.java [new file with mode: 0644]
sass/src/com/vaadin/sass/util/DeepCopy.java
tests/sass/resources/css/mixins.css
tests/sass/resources/scss/mixins.scss
tests/sass/src/com/vaadin/sass/testcases/scss/Mixins.java

index 9d0ca0069c2b6b1bc62d0c5e3f82ab3c0c7ebf8c..01775520d0e8e81c94b56f5d23e3305e6d6bf813 100644 (file)
                </javac>
     </target>
     
+       <target name="compile-sass-parser">
+       <javacc target="${parserDir}/Parser.jj" javacchome="${JavaCChome}">
+       </javacc>
+       </target>
+       
     <target name="compile-sass" depends="init, preprocess-src">
        <!-- TODO also perform javacc compilation of the parser -->
         <mkdir dir="${result-classes-sass}" />
               <property name="deps.initialized"  value="${deps.initialized}"/>
         </ant>
     </target>
+       
 </project>
 
 <!-- These are for emacs. -->
index 2879cd57eabc8af9dd455a697d1df1c9449963a3..685c3ac3f0adf319473c873c3dae9c9bf3aca94a 100644 (file)
@@ -20,8 +20,10 @@ import org.w3c.css.sac.SelectorList;
 
 import com.vaadin.sass.parser.SelectorListImpl;
 import com.vaadin.sass.selector.SelectorUtil;
+import com.vaadin.sass.util.Clonable;
+import com.vaadin.sass.util.DeepCopy;
 
-public class BlockNode extends Node {
+public class BlockNode extends Node implements Clonable {
 
     private static final long serialVersionUID = 5742962631468325048L;
 
@@ -62,12 +64,21 @@ public class BlockNode extends Node {
     }
 
     @Override
-    protected Object clone() throws CloneNotSupportedException {
-        SelectorListImpl clonedSelectorList = new SelectorListImpl();
+    public Object clone() throws CloneNotSupportedException {
+
+        SelectorListImpl clonedSelectorList = null;
+
+        if (selectorList != null) {
+            clonedSelectorList = new SelectorListImpl();
         for (int i = 0; i < selectorList.getLength(); i++) {
             clonedSelectorList.addSelector(selectorList.item(i));
         }
-        return null;
-        // BlockNode clone = new BlockNode()
     }
+        final BlockNode clone = new BlockNode(clonedSelectorList);
+        for (Node child : getChildren()) {
+            clone.getChildren().add((Node) DeepCopy.copy(child));
+        }
+        return clone;
+    }
+
 }
diff --git a/sass/src/com/vaadin/sass/util/Clonable.java b/sass/src/com/vaadin/sass/util/Clonable.java
new file mode 100644 (file)
index 0000000..639f158
--- /dev/null
@@ -0,0 +1,7 @@
+package com.vaadin.sass.util;
+
+public interface Clonable {
+
+    public Object clone() throws CloneNotSupportedException;
+
+}
index 712b8ecc1129fa173735cdd4a11d932d15a766e6..23f838671458965040f1b1b3b73bd6448b6d8f10 100644 (file)
@@ -35,7 +35,9 @@ public class DeepCopy {
      * Returns a copy of the object, or null if the object cannot be serialized.
      */
     public static Object copy(Object orig) {
+
         Object obj = null;
+        if (!(orig instanceof Clonable)) {
         try {
             // Write the object out to a byte array
             FastByteArrayOutputStream fbos = new FastByteArrayOutputStream();
@@ -46,7 +48,8 @@ public class DeepCopy {
 
             // Retrieve an input stream from the byte array and read
             // a copy of the object back in.
-            ObjectInputStream in = new ObjectInputStream(fbos.getInputStream());
+                ObjectInputStream in = new ObjectInputStream(
+                        fbos.getInputStream());
             obj = in.readObject();
             in.close();
         } catch (IOException e) {
@@ -55,6 +58,16 @@ public class DeepCopy {
             cnfe.printStackTrace();
         }
         return obj;
+        } else {
+            try {
+                obj = ((Clonable) orig).clone();
+            } catch (ClassCastException e2) {
+                // Can't clone, return obj as null
+            } catch (CloneNotSupportedException e2) {
+                // Can't clone, return obj as null
+            }
+            return obj;
+        }
     }
 
 }
\ No newline at end of file
index cd5c9b85aa9fe2172e437dc7991ea1cd1c415b69..5c727c193b4c8fd819b445b37796159ccb6a4d74 100644 (file)
@@ -8,6 +8,11 @@
        font-weight: bold;
 }
 
+.main .details {
+       font-size: 14px;
+       font-weight: bold;
+}
+
 .footer {
        border: 2px solid black;
        -webkit-border-radius: 10px;
index f16c9a0e0680559ced582d70e0ea1d094e8ae7f1..52e03d62c1bd773e1c4e1c80f1abb020498717cd 100644 (file)
@@ -16,6 +16,7 @@
 .main {
        @include rounded-borders(1px);
        @include font-settings;
+       @include main-details(14px);
 }
 
 .footer {
        }
        @include font-settings;
 }
+
+@mixin main-details($size){
+       .details {
+               font: {
+                       size : $size;
+                       weight: bold;
+               }
+       }
+}
+
 @include layout;
\ No newline at end of file
index c801ab14377c3259bee82f8348ca0eca800329ad..05b3d3c83e7258dd1ed442be3606430fc6df5f6d 100644 (file)
@@ -69,7 +69,7 @@ public class Mixins extends AbstractTestBase {
         Assert.assertEquals(4, mixinDefNode1.getChildren().size());
 
         BlockNode mainBlockNode = (BlockNode) root.getChildren().get(2);
-        Assert.assertEquals(2, mainBlockNode.getChildren().size());
+        Assert.assertEquals(3, mainBlockNode.getChildren().size());
         MixinNode mixinNode0MainBlock = (MixinNode) mainBlockNode.getChildren()
                 .get(0);
         Assert.assertEquals("rounded-borders", mixinNode0MainBlock.getName());
@@ -82,6 +82,11 @@ public class Mixins extends AbstractTestBase {
         Assert.assertEquals("font-settings", mixinNOde1MainBlock.getName());
         Assert.assertTrue(mixinNOde1MainBlock.getArglist().isEmpty());
 
+        MixinNode mixinNOde2MainBlock = (MixinNode) mainBlockNode.getChildren()
+                .get(2);
+        Assert.assertEquals("main-details", mixinNOde2MainBlock.getName());
+        Assert.assertTrue(mixinNOde1MainBlock.getArglist().isEmpty());
+
         MixinNode mixinNode1MainBlock = (MixinNode) mainBlockNode.getChildren()
                 .get(1);
         Assert.assertTrue(mixinNode1MainBlock.getArglist().isEmpty());
@@ -103,9 +108,6 @@ public class Mixins extends AbstractTestBase {
         Assert.assertTrue(root.getChildren().get(4).getChildren().get(3) instanceof MediaNode);
         Assert.assertTrue(root.getChildren().get(4).getChildren().get(4) instanceof MixinNode);
 
-        MixinNode topLevelMixin = (MixinNode) root.getChildren().get(5);
-        Assert.assertEquals("layout", topLevelMixin.getName());
-
     }
 
     @Test