]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixes #9546, #9974, #10100, #10105 15/215/5
authorSebastian Nyholm <sebastian@vaadin.com>
Mon, 22 Oct 2012 08:11:04 +0000 (11:11 +0300)
committerSebastian Nyholm <sebastian@vaadin.com>
Thu, 8 Nov 2012 15:16:10 +0000 (17:16 +0200)
Change-Id: I1baccb5604899707960b1cf06887ada0fe217d08

55 files changed:
theme-compiler/src/com/vaadin/sass/ScssStylesheet.java
theme-compiler/src/com/vaadin/sass/parser/MediaListImpl.java
theme-compiler/src/com/vaadin/sass/parser/Parser.java
theme-compiler/src/com/vaadin/sass/parser/Parser.jj
theme-compiler/src/com/vaadin/sass/tree/BlockNode.java
theme-compiler/src/com/vaadin/sass/tree/CommentNode.java
theme-compiler/src/com/vaadin/sass/tree/ExtendNode.java
theme-compiler/src/com/vaadin/sass/tree/FontFaceNode.java
theme-compiler/src/com/vaadin/sass/tree/ForNode.java
theme-compiler/src/com/vaadin/sass/tree/FunctionNode.java
theme-compiler/src/com/vaadin/sass/tree/ImportNode.java
theme-compiler/src/com/vaadin/sass/tree/InterpolationNode.java [deleted file]
theme-compiler/src/com/vaadin/sass/tree/ListModifyNode.java
theme-compiler/src/com/vaadin/sass/tree/ListRemoveNode.java
theme-compiler/src/com/vaadin/sass/tree/MediaNode.java
theme-compiler/src/com/vaadin/sass/tree/MicrosoftRuleNode.java
theme-compiler/src/com/vaadin/sass/tree/MixinDefNode.java
theme-compiler/src/com/vaadin/sass/tree/MixinNode.java
theme-compiler/src/com/vaadin/sass/tree/NestPropertiesNode.java
theme-compiler/src/com/vaadin/sass/tree/Node.java
theme-compiler/src/com/vaadin/sass/tree/RuleNode.java
theme-compiler/src/com/vaadin/sass/tree/SimpleNode.java
theme-compiler/src/com/vaadin/sass/tree/VariableNode.java
theme-compiler/src/com/vaadin/sass/tree/WhileNode.java
theme-compiler/src/com/vaadin/sass/tree/controldirective/EachDefNode.java
theme-compiler/src/com/vaadin/sass/tree/controldirective/ElseNode.java
theme-compiler/src/com/vaadin/sass/tree/controldirective/IfElseDefNode.java
theme-compiler/src/com/vaadin/sass/tree/controldirective/IfNode.java
theme-compiler/src/com/vaadin/sass/visitor/BlockNodeHandler.java [new file with mode: 0644]
theme-compiler/src/com/vaadin/sass/visitor/BlockVisitor.java [deleted file]
theme-compiler/src/com/vaadin/sass/visitor/EachNodeHandler.java [new file with mode: 0644]
theme-compiler/src/com/vaadin/sass/visitor/EachVisitor.java [deleted file]
theme-compiler/src/com/vaadin/sass/visitor/ExtendNodeHandler.java [new file with mode: 0644]
theme-compiler/src/com/vaadin/sass/visitor/ExtendVisitor.java [deleted file]
theme-compiler/src/com/vaadin/sass/visitor/IfElseNodeHandler.java [new file with mode: 0644]
theme-compiler/src/com/vaadin/sass/visitor/IfElseVisitor.java [deleted file]
theme-compiler/src/com/vaadin/sass/visitor/ImportNodeHandler.java [new file with mode: 0644]
theme-compiler/src/com/vaadin/sass/visitor/ImportVisitor.java [deleted file]
theme-compiler/src/com/vaadin/sass/visitor/ListModifyVisitor.java [deleted file]
theme-compiler/src/com/vaadin/sass/visitor/MixinNodeHandler.java [new file with mode: 0644]
theme-compiler/src/com/vaadin/sass/visitor/MixinVisitor.java [deleted file]
theme-compiler/src/com/vaadin/sass/visitor/NestPropertiesVisitor.java [deleted file]
theme-compiler/src/com/vaadin/sass/visitor/NestedNodeHandler.java [new file with mode: 0644]
theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorHandler.java [new file with mode: 0644]
theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorVisitor.java [deleted file]
theme-compiler/src/com/vaadin/sass/visitor/VariableNodeHandler.java [new file with mode: 0644]
theme-compiler/src/com/vaadin/sass/visitor/VariableVisitor.java [deleted file]
theme-compiler/tests/resources/css/parent-selector.css
theme-compiler/tests/resources/scss/_partial-for-import.scss
theme-compiler/tests/resources/scss/mixins.scss
theme-compiler/tests/resources/scss/parent-selector.scss
theme-compiler/tests/src/com/vaadin/sass/testcases/scss/ParentSelector.java
theme-compiler/tests/src/com/vaadin/sass/testcases/visitor/ImportVisitorTest.java [deleted file]
theme-compiler/tests/src/com/vaadin/sass/testcases/visitor/MixinVisitorTest.java [deleted file]
theme-compiler/tests/src/com/vaadin/sass/testcases/visitor/NestedPropertiesVisitorTest.java [deleted file]

index d0b4b732ead94411876f8f2368df6e89036ea69b..45578deb195639e2e98d0119bdf82a6be78a2268 100644 (file)
@@ -20,7 +20,9 @@ import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.List;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
 
 import org.w3c.css.sac.CSSException;
 import org.w3c.css.sac.InputSource;
@@ -31,24 +33,27 @@ import com.vaadin.sass.handler.SCSSErrorHandler;
 import com.vaadin.sass.parser.Parser;
 import com.vaadin.sass.resolver.ScssStylesheetResolver;
 import com.vaadin.sass.resolver.VaadinResolver;
+import com.vaadin.sass.tree.MixinDefNode;
 import com.vaadin.sass.tree.Node;
 import com.vaadin.sass.tree.VariableNode;
-import com.vaadin.sass.visitor.BlockVisitor;
-import com.vaadin.sass.visitor.EachVisitor;
-import com.vaadin.sass.visitor.ExtendVisitor;
-import com.vaadin.sass.visitor.IfElseVisitor;
-import com.vaadin.sass.visitor.ImportVisitor;
-import com.vaadin.sass.visitor.ListModifyVisitor;
-import com.vaadin.sass.visitor.MixinVisitor;
-import com.vaadin.sass.visitor.NestPropertiesVisitor;
-import com.vaadin.sass.visitor.ParentSelectorVisitor;
-import com.vaadin.sass.visitor.VariableVisitor;
-import com.vaadin.sass.visitor.Visitor;
+import com.vaadin.sass.tree.controldirective.IfElseDefNode;
+import com.vaadin.sass.visitor.ImportNodeHandler;
+import com.vaadin.sass.visitor.ParentSelectorHandler;
 
 public class ScssStylesheet extends Node {
 
     private static final long serialVersionUID = 3849790204404961608L;
 
+    private static ScssStylesheet mainStyleSheet = null;
+
+    private static final HashMap<String, VariableNode> variables = new HashMap<String, VariableNode>();
+
+    private static final Map<String, MixinDefNode> mixinDefs = new HashMap<String, MixinDefNode>();
+
+    private static final HashSet<IfElseDefNode> ifElseDefNodes = new HashSet<IfElseDefNode>();
+
+    private String fileName;
+
     /**
      * Read in a file SCSS and parse it into a ScssStylesheet
      * 
@@ -121,20 +126,32 @@ public class ScssStylesheet extends Node {
      * @throws Exception
      */
     public void compile() throws Exception {
-        List<Visitor> visitors = new ArrayList<Visitor>();
-        visitors.add(new ImportVisitor());
-        visitors.add(new VariableVisitor());
-        visitors.add(new MixinVisitor());
-        visitors.add(new IfElseVisitor());
-        visitors.add(new ParentSelectorVisitor());
-        visitors.add(new BlockVisitor());
-        visitors.add(new NestPropertiesVisitor());
-        visitors.add(new ExtendVisitor());
-        visitors.add(new EachVisitor());
-        visitors.add(new ListModifyVisitor());
-        for (Visitor visitor : visitors) {
-            visitor.traverse(this);
+        mainStyleSheet = this;
+        mixinDefs.clear();
+        variables.clear();
+        ifElseDefNodes.clear();
+        ParentSelectorHandler.clear();
+        importOtherFiles(this);
+        populateDefinitions(this);
+        traverse(this);
+    }
+
+    private void importOtherFiles(ScssStylesheet node) {
+        ImportNodeHandler.traverse(node);
+    }
+
+    private void populateDefinitions(Node node) {
+        if (node instanceof MixinDefNode) {
+            mixinDefs.put(((MixinDefNode) node).getName(), (MixinDefNode) node);
+            node.getParentNode().removeChild(node);
+        } else if (node instanceof IfElseDefNode) {
+            ifElseDefNodes.add((IfElseDefNode) node);
+        }
+
+        for (final Node child : new ArrayList<Node>(node.getChildren())) {
+            populateDefinitions(child);
         }
+
     }
 
     /**
@@ -169,4 +186,63 @@ public class ScssStylesheet extends Node {
         }
     }
 
+    public static ScssStylesheet get() {
+        return mainStyleSheet;
+    }
+
+    @Override
+    public void traverse() {
+        // Not used for ScssStylesheet
+    }
+
+    public void traverse(Node node) {
+        node.traverse();
+
+        @SuppressWarnings("unchecked")
+        HashMap<String, VariableNode> variableScope = (HashMap<String, VariableNode>) variables
+                .clone();
+
+        int maxSize = node.getChildren().size();
+        ArrayList<Node> oldChildren = new ArrayList<Node>(node.getChildren());
+        for (int i = 0; i < maxSize; i++) {
+
+            Node current = node.getChildren().get(i);
+            traverse(current);
+
+            if (!node.getChildren().equals(oldChildren)) {
+                oldChildren = new ArrayList<Node>(node.getChildren());
+                maxSize = node.getChildren().size();
+                i = i - 1;
+            }
+
+        }
+
+        variables.clear();
+        variables.putAll(variableScope);
+    }
+
+    public static void addVariable(VariableNode node) {
+        variables.put(node.getName(), node);
+    }
+
+    public static VariableNode getVariable(String string) {
+        return variables.get(string);
+    }
+
+    public static ArrayList<VariableNode> getVariables() {
+        return new ArrayList<VariableNode>(variables.values());
+    }
+
+    public static MixinDefNode getMixinDefinition(String name) {
+        return mixinDefs.get(name);
+    }
+
+    public void setFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+    public String getFileName() {
+        return fileName;
+    }
+
 }
index 042e385cb3f0fc5ec5fc4dfbb88ec03ac52d3f49..bb321ea3cd36d0c9b164d3e88e2a9f46eed62554 100644 (file)
@@ -8,14 +8,20 @@
  */
 package com.vaadin.sass.parser;
 
+import java.io.Serializable;
+
 import org.w3c.css.sac.SACMediaList;
 
 /**
  * @version $Revision: 1.4 $
  * @author Philippe Le Hegaret
  */
-public class MediaListImpl implements SACMediaList {
+public class MediaListImpl implements SACMediaList, Serializable {
 
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 1L;
     String[] array = new String[10];
     int current;
 
index 33411bd57d10f1822ab89e17a01fb2c0614f3657..996a15d9c8e615c94af8621c60d76c3b31675c68 100644 (file)
@@ -3427,6 +3427,13 @@ boolean isPseudoElement = false;
     case IDENT:
       name = property();
       break;
+    case VARIABLE:
+      name = variableName();
+                                              name = "$"+name;
+      break;
+    case INTERPOLATION:
+      name = interpolation();
+      break;
     case FUNCTION:
       name = functionName();
       args = argValuelist();
@@ -3464,6 +3471,13 @@ boolean isPseudoElement = false;
             documentHandler.includeDirective(name, args);
   }
 
+  final public String interpolation() throws ParseException {
+  Token n;
+    n = jj_consume_token(INTERPOLATION);
+    {if (true) return n.image;}
+    throw new Error("Missing return statement in function");
+  }
+
   final public void listModifyDirective() throws ParseException {
     if (jj_2_12(5)) {
       removeDirective();
@@ -5648,26 +5662,6 @@ LexicalUnitImpl result = null;
     finally { jj_save(14, xla); }
   }
 
-  private boolean jj_3R_205() {
-    if (jj_scan_token(DEG)) return true;
-    return false;
-  }
-
-  private boolean jj_3R_204() {
-    if (jj_scan_token(EXS)) return true;
-    return false;
-  }
-
-  private boolean jj_3R_203() {
-    if (jj_scan_token(EMS)) return true;
-    return false;
-  }
-
-  private boolean jj_3_1() {
-    if (jj_3R_156()) return true;
-    return false;
-  }
-
   private boolean jj_3R_202() {
     if (jj_scan_token(PX)) return true;
     return false;
@@ -5683,6 +5677,11 @@ LexicalUnitImpl result = null;
     return false;
   }
 
+  private boolean jj_3_1() {
+    if (jj_3R_156()) return true;
+    return false;
+  }
+
   private boolean jj_3R_199() {
     if (jj_scan_token(MM)) return true;
     return false;
@@ -5708,22 +5707,11 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3_4() {
-    if (jj_3R_159()) return true;
-    if (jj_3R_160()) return true;
-    return false;
-  }
-
   private boolean jj_3R_185() {
     if (jj_3R_221()) return true;
     return false;
   }
 
-  private boolean jj_3_7() {
-    if (jj_3R_156()) return true;
-    return false;
-  }
-
   private boolean jj_3R_195() {
     if (jj_scan_token(NUMBER)) return true;
     return false;
@@ -5734,16 +5722,6 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_191() {
-    if (jj_scan_token(COLON)) return true;
-    return false;
-  }
-
-  private boolean jj_3_6() {
-    if (jj_3R_161()) return true;
-    return false;
-  }
-
   private boolean jj_3R_181() {
     Token xsp;
     xsp = jj_scanpos;
@@ -5807,6 +5785,12 @@ LexicalUnitImpl result = null;
     return false;
   }
 
+  private boolean jj_3_4() {
+    if (jj_3R_159()) return true;
+    if (jj_3R_160()) return true;
+    return false;
+  }
+
   private boolean jj_3R_179() {
     if (jj_3R_193()) return true;
     return false;
@@ -5826,6 +5810,21 @@ LexicalUnitImpl result = null;
     return false;
   }
 
+  private boolean jj_3_7() {
+    if (jj_3R_156()) return true;
+    return false;
+  }
+
+  private boolean jj_3R_191() {
+    if (jj_scan_token(COLON)) return true;
+    return false;
+  }
+
+  private boolean jj_3_6() {
+    if (jj_3R_161()) return true;
+    return false;
+  }
+
   private boolean jj_3R_161() {
     if (jj_3R_178()) return true;
     if (jj_scan_token(COLON)) return true;
@@ -5873,21 +5872,11 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3_5() {
-    if (jj_3R_161()) return true;
-    return false;
-  }
-
   private boolean jj_3_14() {
     if (jj_3R_166()) return true;
     return false;
   }
 
-  private boolean jj_3_2() {
-    if (jj_3R_156()) return true;
-    return false;
-  }
-
   private boolean jj_3R_240() {
     if (jj_scan_token(URL)) return true;
     return false;
@@ -5908,11 +5897,21 @@ LexicalUnitImpl result = null;
     return false;
   }
 
+  private boolean jj_3_5() {
+    if (jj_3R_161()) return true;
+    return false;
+  }
+
   private boolean jj_3R_167() {
     if (jj_3R_183()) return true;
     return false;
   }
 
+  private boolean jj_3_2() {
+    if (jj_3R_156()) return true;
+    return false;
+  }
+
   private boolean jj_3R_164() {
     if (jj_scan_token(VARIABLE)) return true;
     Token xsp;
@@ -5977,11 +5976,6 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_248() {
-    if (jj_scan_token(INTERPOLATION)) return true;
-    return false;
-  }
-
   private boolean jj_3R_241() {
     if (jj_scan_token(UNICODERANGE)) return true;
     return false;
@@ -5992,11 +5986,6 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3_10() {
-    if (jj_3R_161()) return true;
-    return false;
-  }
-
   private boolean jj_3R_165() {
     if (jj_scan_token(VARIABLE)) return true;
     Token xsp;
@@ -6018,13 +6007,8 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_192() {
-    if (jj_scan_token(LBRACKET)) return true;
-    return false;
-  }
-
-  private boolean jj_3R_158() {
-    if (jj_3R_161()) return true;
+  private boolean jj_3R_248() {
+    if (jj_scan_token(INTERPOLATION)) return true;
     return false;
   }
 
@@ -6038,16 +6022,6 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_178() {
-    if (jj_scan_token(IDENT)) return true;
-    Token xsp;
-    while (true) {
-      xsp = jj_scanpos;
-      if (jj_scan_token(1)) { jj_scanpos = xsp; break; }
-    }
-    return false;
-  }
-
   private boolean jj_3R_237() {
     if (jj_scan_token(FUNCTION)) return true;
     Token xsp;
@@ -6061,13 +6035,8 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_242() {
-    if (jj_scan_token(VARIABLE)) return true;
-    Token xsp;
-    while (true) {
-      xsp = jj_scanpos;
-      if (jj_scan_token(1)) { jj_scanpos = xsp; break; }
-    }
+  private boolean jj_3_10() {
+    if (jj_3R_161()) return true;
     return false;
   }
 
@@ -6091,13 +6060,23 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_235() {
-    if (jj_scan_token(PARENT)) return true;
+  private boolean jj_3R_192() {
+    if (jj_scan_token(LBRACKET)) return true;
     return false;
   }
 
-  private boolean jj_3R_234() {
-    if (jj_scan_token(ANY)) return true;
+  private boolean jj_3R_158() {
+    if (jj_3R_161()) return true;
+    return false;
+  }
+
+  private boolean jj_3R_178() {
+    if (jj_scan_token(IDENT)) return true;
+    Token xsp;
+    while (true) {
+      xsp = jj_scanpos;
+      if (jj_scan_token(1)) { jj_scanpos = xsp; break; }
+    }
     return false;
   }
 
@@ -6106,6 +6085,16 @@ LexicalUnitImpl result = null;
     return false;
   }
 
+  private boolean jj_3R_242() {
+    if (jj_scan_token(VARIABLE)) return true;
+    Token xsp;
+    while (true) {
+      xsp = jj_scanpos;
+      if (jj_scan_token(1)) { jj_scanpos = xsp; break; }
+    }
+    return false;
+  }
+
   private boolean jj_3R_217() {
     if (jj_3R_240()) return true;
     return false;
@@ -6129,6 +6118,21 @@ LexicalUnitImpl result = null;
     return false;
   }
 
+  private boolean jj_3R_216() {
+    if (jj_3R_239()) return true;
+    return false;
+  }
+
+  private boolean jj_3R_235() {
+    if (jj_scan_token(PARENT)) return true;
+    return false;
+  }
+
+  private boolean jj_3R_234() {
+    if (jj_scan_token(ANY)) return true;
+    return false;
+  }
+
   private boolean jj_3R_247() {
     if (jj_scan_token(IDENT)) return true;
     return false;
@@ -6144,11 +6148,6 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_216() {
-    if (jj_3R_239()) return true;
-    return false;
-  }
-
   private boolean jj_3R_233() {
     Token xsp;
     if (jj_3R_243()) return true;
@@ -6294,11 +6293,24 @@ LexicalUnitImpl result = null;
     return false;
   }
 
+  private boolean jj_3R_238() {
+    if (jj_scan_token(DOT)) return true;
+    return false;
+  }
+
   private boolean jj_3R_232() {
     if (jj_scan_token(PRECEDES)) return true;
     return false;
   }
 
+  private boolean jj_3R_215() {
+    Token xsp;
+    xsp = jj_scanpos;
+    if (jj_3R_238()) jj_scanpos = xsp;
+    if (jj_scan_token(IDENT)) return true;
+    return false;
+  }
+
   private boolean jj_3R_231() {
     if (jj_scan_token(PLUS)) return true;
     return false;
@@ -6319,6 +6331,11 @@ LexicalUnitImpl result = null;
     return false;
   }
 
+  private boolean jj_3R_214() {
+    if (jj_scan_token(STRING)) return true;
+    return false;
+  }
+
   private boolean jj_3R_171() {
     if (jj_scan_token(PRECEDES)) return true;
     Token xsp;
@@ -6329,16 +6346,27 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_238() {
-    if (jj_scan_token(DOT)) return true;
+  private boolean jj_3R_213() {
+    if (jj_3R_237()) return true;
     return false;
   }
 
-  private boolean jj_3R_215() {
+  private boolean jj_3R_182() {
     Token xsp;
     xsp = jj_scanpos;
-    if (jj_3R_238()) jj_scanpos = xsp;
-    if (jj_scan_token(IDENT)) return true;
+    if (jj_3R_214()) {
+    jj_scanpos = xsp;
+    if (jj_3R_215()) {
+    jj_scanpos = xsp;
+    if (jj_3R_216()) {
+    jj_scanpos = xsp;
+    if (jj_3R_217()) {
+    jj_scanpos = xsp;
+    if (jj_3R_218()) return true;
+    }
+    }
+    }
+    }
     return false;
   }
 
@@ -6381,37 +6409,23 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_214() {
-    if (jj_scan_token(STRING)) return true;
+  private boolean jj_3R_212() {
+    if (jj_scan_token(DIMEN)) return true;
     return false;
   }
 
-  private boolean jj_3R_213() {
-    if (jj_3R_237()) return true;
+  private boolean jj_3R_211() {
+    if (jj_scan_token(KHZ)) return true;
     return false;
   }
 
-  private boolean jj_3R_182() {
-    Token xsp;
-    xsp = jj_scanpos;
-    if (jj_3R_214()) {
-    jj_scanpos = xsp;
-    if (jj_3R_215()) {
-    jj_scanpos = xsp;
-    if (jj_3R_216()) {
-    jj_scanpos = xsp;
-    if (jj_3R_217()) {
-    jj_scanpos = xsp;
-    if (jj_3R_218()) return true;
-    }
-    }
-    }
-    }
+  private boolean jj_3R_210() {
+    if (jj_scan_token(HZ)) return true;
     return false;
   }
 
-  private boolean jj_3R_212() {
-    if (jj_scan_token(DIMEN)) return true;
+  private boolean jj_3R_209() {
+    if (jj_scan_token(MS)) return true;
     return false;
   }
 
@@ -6420,13 +6434,13 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_176() {
-    if (jj_3R_191()) return true;
+  private boolean jj_3R_208() {
+    if (jj_scan_token(SECOND)) return true;
     return false;
   }
 
-  private boolean jj_3R_211() {
-    if (jj_scan_token(KHZ)) return true;
+  private boolean jj_3R_176() {
+    if (jj_3R_191()) return true;
     return false;
   }
 
@@ -6435,8 +6449,8 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_210() {
-    if (jj_scan_token(HZ)) return true;
+  private boolean jj_3R_207() {
+    if (jj_scan_token(GRAD)) return true;
     return false;
   }
 
@@ -6450,18 +6464,18 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_209() {
-    if (jj_scan_token(MS)) return true;
+  private boolean jj_3R_206() {
+    if (jj_scan_token(RAD)) return true;
     return false;
   }
 
-  private boolean jj_3R_173() {
-    if (jj_3R_188()) return true;
+  private boolean jj_3R_205() {
+    if (jj_scan_token(DEG)) return true;
     return false;
   }
 
-  private boolean jj_3R_208() {
-    if (jj_scan_token(SECOND)) return true;
+  private boolean jj_3R_173() {
+    if (jj_3R_188()) return true;
     return false;
   }
 
@@ -6489,13 +6503,13 @@ LexicalUnitImpl result = null;
     return false;
   }
 
-  private boolean jj_3R_207() {
-    if (jj_scan_token(GRAD)) return true;
+  private boolean jj_3R_204() {
+    if (jj_scan_token(EXS)) return true;
     return false;
   }
 
-  private boolean jj_3R_206() {
-    if (jj_scan_token(RAD)) return true;
+  private boolean jj_3R_203() {
+    if (jj_scan_token(EMS)) return true;
     return false;
   }
 
@@ -6524,10 +6538,10 @@ LexicalUnitImpl result = null;
       jj_la1_0 = new int[] {0x0,0xc02,0xc02,0x0,0xc00,0x2,0x2,0x2,0x0,0xe8000000,0xc00,0x2,0xc00,0x2,0x0,0x2,0x0,0x2,0x2,0x2,0xe9f45400,0xe9f45400,0x2,0x400000,0x2,0x2,0x2,0x2,0x0,0x0,0x2,0x0,0x800000,0x2,0x0,0x2,0x2,0x2,0x2,0x0,0x800000,0x2,0x0,0x2,0x1f45400,0x2,0x2,0x1100000,0x2,0x1100000,0x1100002,0x2,0x80080002,0x80080002,0x2,0x2,0x2,0x2,0x2,0xe8000000,0x0,0x0,0x0,0xe8000000,0x2,0x400000,0x2,0x2,0x88000000,0x88000000,0x88000000,0x88000000,0x88000000,0x88000000,0x88000000,0x88000000,0x88000000,0x88000000,0xe8000000,0x0,0x0,0x0,0x0,0x60000000,0x2,0x2,0xfc000,0x2,0x0,0x2,0xfc000,0x0,0x2,0x2,0x0,0x2,0x0,0x2,0x800000,0x27380002,0x2,0xe8000000,0x0,0xe8000000,0x2,0x0,0x2,0x27380002,0x0,0x2,0xe8000000,0x0,0xe8000000,0x2,0x27380002,0x2,0x2,0x2,0x0,0x2,0xe8000000,0x0,0x0,0xe8000000,0x2,0x2,0x400000,0x2,0x2,0x2,0x2,0x0,0x2,0xe8000000,0x0,0x0,0xe8000000,0x2,0x400000,0x2,0x2,0x2,0x400000,0x0,0x0,0x80300000,0x2,0x0,0x400000,0x2,0x80300000,0x2,0x0,0x2,0x0,0x2,0x800000,0x2,0x2,0x2,0x0,0x2,0x2,0x2,0x400000,0x2,0x2,0x2,0x2,0x2,0x0,0x2,0x2,0x2,0x400000,0x2,0x2,0x2,0x2,0x2,0x0,0x2,0x2,0x2,0x400000,0x2,0x2,0x0,0x2,0x2,0x2,0x800000,0x2,0x2,0x0,0x800000,0x2,0x0,0x2,0x2,0x0,0x2,0x0,0x800000,0x2,0x0,0x2,0x80301000,0x2,0x0,0x2,0x2,0x2,0x2,0x4400000,0x4400000,0x300000,0x80300000,0x300000,0x0,0x80000000,0x80000000,0x80300000,0x2,0x2,0x80300000,0x2,0xe8000000,0x2,0x2,0x2,0x0,0x800000,0x2,0x0,0x2,};
    }
    private static void jj_la1_init_1() {
-      jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x283000c0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1c0,0x1c0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x100,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc2,0xc2,0x0,0x0,0x0,0x0,0x0,0xa82000c0,0x0,0x20000000,0x88200000,0xc0,0x0,0x0,0x0,0x0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xc0,0x80,0x80,0x80,0x80,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3f,0x0,0x802000c0,0x80200000,0xc0,0x0,0x40000000,0x0,0x3f,0x0,0x0,0x802000c0,0x80200000,0xc0,0x0,0x3f,0x0,0x0,0x0,0x0,0x0,0x802000c0,0x200000,0x80000000,0xc0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x882000c0,0x200000,0x88000000,0xc0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x40,0x40,0x0,0x40,0x0,0x0,0x40,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x60000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,};
+      jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x283000c0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1c0,0x1c0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x100,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc2,0xc2,0x0,0x0,0x0,0x0,0x0,0xa82000c0,0x0,0x20000000,0x88200000,0xc0,0x0,0x0,0x0,0x0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xc0,0x80,0x80,0x80,0x80,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3f,0x0,0x802000c0,0x80200000,0xc0,0x0,0x40000000,0x0,0x3f,0x0,0x0,0x802000c0,0x80200000,0xc0,0x0,0x3f,0x0,0x0,0x0,0x0,0x0,0x802000c0,0x200000,0x80000000,0xc0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x882000c0,0x200000,0x88000000,0xc0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x40,0x40,0x0,0x40,0x0,0x0,0x40,0x0,0x40,0x0,0x80,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x60000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,};
    }
    private static void jj_la1_init_2() {
-      jj_la1_2 = new int[] {0x80000000,0x0,0x0,0x20000000,0x0,0x0,0x0,0x0,0x400,0x50000440,0x0,0x0,0x0,0x0,0x220,0x0,0x40,0x0,0x0,0x0,0xf0000ae0,0xf0000ae0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0xe0000aa0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc0,0xc0,0x0,0x0,0x0,0x0,0x0,0x50000444,0x44,0x0,0x40000400,0x10000040,0x0,0x0,0x0,0x0,0x10000000,0x10000000,0x0,0x0,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000040,0x40,0x40,0x40,0x40,0x40,0x0,0x0,0x0,0x0,0x60,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x10,0x0,0x0,0x4c0,0x0,0x50000440,0x40000400,0x10000040,0x0,0x0,0x0,0x4c0,0x8,0x0,0x50000440,0x40000400,0x10000040,0x0,0x4c0,0x0,0x0,0x0,0x440,0x0,0x50000440,0x0,0x40000400,0x10000040,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x50000440,0x40000000,0x400,0x10000040,0x0,0x0,0x0,0x0,0x0,0x0,0x400,0x400,0x1ffffee0,0x0,0x0,0x0,0x0,0x1ffffee0,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x1ffffee0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1ffffee0,0x0,0xffff880,0x0,0x10000260,0x1ffffae0,0x0,0x0,0x1ffffee0,0x0,0x70000040,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,};
+      jj_la1_2 = new int[] {0x80000000,0x0,0x0,0x20000000,0x0,0x0,0x0,0x0,0x400,0x50000440,0x0,0x0,0x0,0x0,0x220,0x0,0x40,0x0,0x0,0x0,0xf0000ae0,0xf0000ae0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0xe0000aa0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc0,0xc0,0x0,0x0,0x0,0x0,0x0,0x50000444,0x44,0x0,0x40000400,0x10000040,0x0,0x0,0x0,0x0,0x10000000,0x10000000,0x0,0x0,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000000,0x10000040,0x40,0x40,0x40,0x40,0x40,0x0,0x0,0x0,0x0,0x60,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x10,0x0,0x0,0x4c0,0x0,0x50000440,0x40000400,0x10000040,0x0,0x0,0x0,0x4c0,0x8,0x0,0x50000440,0x40000400,0x10000040,0x0,0x4c0,0x0,0x0,0x0,0x440,0x0,0x50000440,0x0,0x40000400,0x10000040,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x50000440,0x40000000,0x400,0x10000040,0x0,0x0,0x0,0x0,0x0,0x0,0x400,0x400,0x1ffffee0,0x0,0x0,0x0,0x0,0x1ffffee0,0x0,0x0,0x0,0x440,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,0x1ffffee0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1ffffee0,0x0,0xffff880,0x0,0x10000260,0x1ffffae0,0x0,0x0,0x1ffffee0,0x0,0x70000040,0x0,0x0,0x0,0x40,0x0,0x0,0x40,0x0,};
    }
    private static void jj_la1_init_3() {
       jj_la1_3 = new int[] {0x0,0x4,0x4,0x0,0x4,0x0,0x0,0x0,0x0,0x3,0x4,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x6200f,0x6200f,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x6200f,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20000,0x20000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x22000,0x0,0x0,0x0,0x0,0x22000,0x0,0x0,0x0,0x20000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x22000,0x0,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x22000,0x0,0x20000,0x0,0x2000,0x22000,0x0,0x0,0x22000,0x0,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,};
index 92cb3e46c1f194c9414c38310af6ca1fc38b0b23..af53edb482c88c983272d42ca808f64fa82e9847 100644 (file)
@@ -1576,12 +1576,18 @@ void includeDirective() :
 {
     <INCLUDE_SYM>
     (<S>)*
-    (name = property()
+    (name = property()|name = variableName(){ name = "$"+name;}|name = interpolation()
          |(name = functionName() 
            args = argValuelist()) <RPARAN>)(";"(<S>)*)+
            {documentHandler.includeDirective(name, args);}
 }
 
+String interpolation() :
+{
+  Token n;\r}\r{
+  n = < INTERPOLATION >
+  {
+    return n.image;\r  }\r}
 
 void listModifyDirective() :\r{
 }
index 5a64a928db3675c0e6e0a575122d39b5c38b8a1c..07e4c69ed7220ccbf97ba1fbe3c9e1b28ed10e11 100644 (file)
@@ -18,7 +18,11 @@ package com.vaadin.sass.tree;
 
 import java.util.ArrayList;
 
-public class BlockNode extends Node implements IVariableNode, InterpolationNode {
+import com.vaadin.sass.ScssStylesheet;
+import com.vaadin.sass.visitor.BlockNodeHandler;
+import com.vaadin.sass.visitor.ParentSelectorHandler;
+
+public class BlockNode extends Node implements IVariableNode {
 
     private static final long serialVersionUID = 5742962631468325048L;
 
@@ -94,25 +98,20 @@ public class BlockNode extends Node implements IVariableNode, InterpolationNode
         return b.toString();
     }
 
-    @Override
-    public void replaceInterpolation(String variableName, String variable) {
-        if (selectorList == null || selectorList.isEmpty()) {
-            return;
-        }
-
-        for (final String selector : new ArrayList<String>(selectorList)) {
-            String interpolation = "#{" + variableName + "}";
-            if (selector.contains(interpolation)) {
-                String replace = selector.replace(interpolation, variable);
-                selectorList.add(selectorList.indexOf(selector), replace);
-                selectorList.remove(selector);
-            }
-        }
+    public void setParentNode(Node node) {
+        parentNode.removeChild(this);
+        node.appendChild(this);
     }
 
     @Override
-    public boolean containsInterpolationVariable(String variable) {
-        return getSelectors().contains(variable);
+    public void traverse() {
+        try {
+            ParentSelectorHandler.traverse(this);
+            BlockNodeHandler.traverse(this);
+            replaceVariables(ScssStylesheet.getVariables());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
 }
index 5fb438bb085c27d0270c32216eef259aa33c3ccb..b867c5384b8152dd338e14c04a6ce1f76a1e705e 100644 (file)
@@ -35,4 +35,9 @@ public class CommentNode extends Node {
     public String toString() {
         return comment;
     }
+
+    @Override
+    public void traverse() {
+        // Not used in CommentNode
+    }
 }
index 909e69e12f927a752c5b1d5dc55adce50b4de2a7..b9bf5869d17d0722a65adc24106f5555450f6e60 100644 (file)
@@ -18,6 +18,8 @@ package com.vaadin.sass.tree;
 
 import java.util.ArrayList;
 
+import com.vaadin.sass.visitor.ExtendNodeHandler;
+
 public class ExtendNode extends Node implements IVariableNode {
     private static final long serialVersionUID = 3301805078983796878L;
 
@@ -45,4 +47,14 @@ public class ExtendNode extends Node implements IVariableNode {
 
         return b.toString();
     }
+
+    @Override
+    public void traverse() {
+        try {
+            ExtendNodeHandler.traverse(this);
+            getParentNode().removeChild(this);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 }
index 3dab4df7731be54036cac888e129e779deecdb77..9e3b24f8def0faa6ef8528856c4aacda37e0c4e6 100644 (file)
@@ -15,4 +15,9 @@ public class FontFaceNode extends Node {
         return builder.toString();
     }
 
+    @Override
+    public void traverse() {
+        // Not in use for FontFaceNode
+    }
+
 }
index 7c0239aa60ffd3e3a1d7ccc89b2b17d3472094fe..da0d78422940f58896a2a2ddf2748aeb0b6add92 100644 (file)
@@ -41,4 +41,9 @@ public class ForNode extends Node {
                 + to + ", exclusive: " + exclusive + ", body" + body;
     }
 
+    @Override
+    public void traverse() {
+
+    }
+
 }
index 6263d557b8b3c1f4b1fab1bcffce601f86832bad..d81e4976e593f1a07b6008e42892629b33b6dc5d 100644 (file)
@@ -18,6 +18,8 @@ package com.vaadin.sass.tree;
 
 import java.util.ArrayList;
 
+import com.vaadin.sass.ScssStylesheet;
+
 public class FunctionNode extends Node implements IVariableNode {
     private static final long serialVersionUID = -5383104165955523923L;
 
@@ -50,4 +52,9 @@ public class FunctionNode extends Node implements IVariableNode {
             }
         }
     }
+
+    @Override
+    public void traverse() {
+        replaceVariables(ScssStylesheet.getVariables());
+    }
 }
index ac070d6ffc419c022f71b361df4b258173dccaf6..9dd9c1b0d861fa91f6e4cf8aefbeb4520d9f8de9 100644 (file)
@@ -18,6 +18,9 @@ package com.vaadin.sass.tree;
 
 import org.w3c.css.sac.SACMediaList;
 
+import com.vaadin.sass.ScssStylesheet;
+import com.vaadin.sass.visitor.ImportNodeHandler;
+
 public class ImportNode extends Node {
     private static final long serialVersionUID = 5671255892282668438L;
 
@@ -68,4 +71,10 @@ public class ImportNode extends Node {
     public SACMediaList getMl() {
         return ml;
     }
+
+    @Override
+    public void traverse() {
+        // TODO shouldn't be reached with current setup, try anyway?
+        ImportNodeHandler.traverse((ScssStylesheet) getParentNode());
+    }
 }
diff --git a/theme-compiler/src/com/vaadin/sass/tree/InterpolationNode.java b/theme-compiler/src/com/vaadin/sass/tree/InterpolationNode.java
deleted file mode 100644 (file)
index c998b60..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.vaadin.sass.tree;
-
-public interface InterpolationNode {
-    public void replaceInterpolation(String variableName, String variable);
-
-    public boolean containsInterpolationVariable(String variable);
-}
index d54f56f8a7dc4d1e91e5c8b050e8f6198ff8475d..c571fde08eded4444eff1a316f007686af8d01e7 100644 (file)
@@ -3,6 +3,7 @@ package com.vaadin.sass.tree;
 import java.util.ArrayList;
 import java.util.Arrays;
 
+import com.vaadin.sass.ScssStylesheet;
 import com.vaadin.sass.parser.LexicalUnitImpl;
 
 public abstract class ListModifyNode extends Node implements IVariableNode {
@@ -99,4 +100,11 @@ public abstract class ListModifyNode extends Node implements IVariableNode {
         }
     }
 
+    @Override
+    public void traverse() {
+        replaceVariables(ScssStylesheet.getVariables());
+        ScssStylesheet.addVariable(getModifiedList());
+        getParentNode().removeChild(this);
+    }
+
 }
index 22fb216c9e5a6ffca6d6fb7aa60678d082b9d7b5..a72be7bc02086e931c44b58f263504ea414ef692 100644 (file)
@@ -2,8 +2,6 @@ package com.vaadin.sass.tree;
 
 import java.util.ArrayList;
 
-import com.vaadin.sass.parser.LexicalUnitImpl;
-
 public class ListRemoveNode extends ListModifyNode {
 
     public ListRemoveNode(String variable, String list, String remove,
@@ -14,26 +12,9 @@ public class ListRemoveNode extends ListModifyNode {
 
     }
 
-    private boolean shouldInclude(LexicalUnitImpl current,
-            LexicalUnitImpl lastAccepted) {
-
-        if (lastAccepted != null
-                && lastAccepted.getLexicalUnitType() == LexicalUnitImpl.SAC_OPERATOR_COMMA
-                && current.getLexicalUnitType() == LexicalUnitImpl.SAC_OPERATOR_COMMA) {
-            return false;
-        }
-
-        String string = current.getValue().toString();
-        for (final String s : modify) {
-            if (s.equals(string)) {
-                return false;
-            }
-        }
-        return true;
-    }
-
     @Override
     protected void modifyList(ArrayList<String> newList) {
         newList.removeAll(modify);
     }
+
 }
index b312d53a00c24be1390b2357ae3b65f779e7f37a..e410e93e53ede6a1165e913f9e9caa8150c0eb4a 100644 (file)
@@ -57,4 +57,9 @@ public class MediaNode extends Node {
         return builder.toString();
     }
 
+    @Override
+    public void traverse() {
+
+    }
+
 }
index cbd3b142896bc21c7db1f0e74c3f84ff8f0ad982..ce2bdc8395a2f27a8ea834e63af3c5572177c69f 100644 (file)
@@ -2,6 +2,8 @@ package com.vaadin.sass.tree;
 
 import java.util.ArrayList;
 
+import com.vaadin.sass.ScssStylesheet;
+
 public class MicrosoftRuleNode extends Node implements IVariableNode {
 
     private final String name;
@@ -26,4 +28,9 @@ public class MicrosoftRuleNode extends Node implements IVariableNode {
     public String toString() {
         return name + ": " + value + ";";
     }
+
+    @Override
+    public void traverse() {
+        replaceVariables(ScssStylesheet.getVariables());
+    }
 }
index 0cffbc3203fba00a06316205c341b2633b2e0551..9f51a959b8f0e20787aa75f354f0742a765b4a2e 100644 (file)
@@ -19,6 +19,7 @@ package com.vaadin.sass.tree;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import com.vaadin.sass.ScssStylesheet;
 import com.vaadin.sass.util.DeepCopy;
 
 public class MixinDefNode extends Node implements IVariableNode {
@@ -73,4 +74,15 @@ public class MixinDefNode extends Node implements IVariableNode {
         }
     }
 
+    @Override
+    public void traverse() {
+        if (!arglist.isEmpty()) {
+            for (final VariableNode arg : arglist) {
+                if (arg.getExpr() != null) {
+                    ScssStylesheet.addVariable(arg);
+                }
+            }
+        }
+    }
+
 }
index 205f20b500240fa0be63af645fd5faeb397807cd..e43be0488aa9219e6d6cc8008e3c4d449a31743b 100644 (file)
@@ -19,7 +19,9 @@ package com.vaadin.sass.tree;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import com.vaadin.sass.ScssStylesheet;
 import com.vaadin.sass.parser.LexicalUnitImpl;
+import com.vaadin.sass.visitor.MixinNodeHandler;
 
 public class MixinNode extends Node implements IVariableNode {
     private static final long serialVersionUID = 4725008226813110658L;
@@ -67,6 +69,27 @@ public class MixinNode extends Node implements IVariableNode {
                     arg.replaceValue(var.getExpr());
                 }
             }
+
+            if (name.startsWith("$")) {
+                if (name.equals("$" + var.getName())) {
+                    name = var.getExpr().toString();
+                }
+            } else if (name.startsWith("#{") && name.endsWith("}")) {
+                if (name.equals("#{$" + var.getName() + "}")) {
+                    name = var.getExpr().toString();
+                }
+            }
+
+        }
+    }
+
+    @Override
+    public void traverse() {
+        try {
+            replaceVariables(ScssStylesheet.getVariables());
+            MixinNodeHandler.traverse(this);
+        } catch (Exception e) {
+            e.printStackTrace();
         }
     }
 
index 27d3f5b23f2a3b7a450056caba365fa4b780400e..0b0dd903344df708142fa4639adf03f4b013d36e 100644 (file)
@@ -20,6 +20,8 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import com.vaadin.sass.visitor.NestedNodeHandler;
+
 public class NestPropertiesNode extends Node implements IVariableNode {
     private static final long serialVersionUID = 3671253315690598308L;
 
@@ -41,7 +43,8 @@ public class NestPropertiesNode extends Node implements IVariableNode {
     public Collection<RuleNode> unNesting() {
         List<RuleNode> result = new ArrayList<RuleNode>();
         for (Node child : children) {
-            result.add(createNewRuleNodeFromChild((RuleNode) child));
+            RuleNode createNewRuleNodeFromChild = createNewRuleNodeFromChild((RuleNode) child);
+            result.add(createNewRuleNodeFromChild);
         }
         return result;
     }
@@ -63,4 +66,10 @@ public class NestPropertiesNode extends Node implements IVariableNode {
             }
         }
     }
+
+    @Override
+    public void traverse() {
+        NestedNodeHandler.traverse(this);
+    }
+
 }
index 6e871df2868a47cafe95f8cfc6f92a6c49bb6b88..ccbd6d64da8a5f19ad7db1a6740fc4beda4da2b7 100644 (file)
@@ -24,28 +24,34 @@ public abstract class Node implements Serializable {
     private static final long serialVersionUID = 5914711715839294816L;
 
     protected ArrayList<Node> children;
-    private String fileName;
 
-    protected String rawString;
+    protected Node parentNode;
 
     public Node() {
         children = new ArrayList<Node>();
     }
 
-    public Node(String raw) {
-        this();
-        rawString = raw;
-    }
-
     public void appendAll(Collection<Node> nodes) {
         if (nodes != null && !nodes.isEmpty()) {
             children.addAll(nodes);
+
+            for (final Node n : nodes) {
+                if (n.getParentNode() != null) {
+                    n.getParentNode().removeChild(n);
+                }
+                n.setParentNode(this);
+            }
+
         }
     }
 
     public void appendChild(Node node) {
         if (node != null) {
             children.add(node);
+            if (node.getParentNode() != null) {
+                node.getParentNode().removeChild(node);
+            }
+            node.setParentNode(this);
         }
     }
 
@@ -54,6 +60,10 @@ public abstract class Node implements Serializable {
             int index = children.indexOf(after);
             if (index != -1) {
                 children.add(index + 1, node);
+                if (node.getParentNode() != null) {
+                    node.getParentNode().removeChild(node);
+                }
+                node.setParentNode(this);
             } else {
                 throw new NullPointerException("after-node was not found");
             }
@@ -62,7 +72,10 @@ public abstract class Node implements Serializable {
 
     public void removeChild(Node node) {
         if (node != null) {
-            children.remove(node);
+            boolean removed = children.remove(node);
+            if (removed) {
+                node.setParentNode(null);
+            }
         }
     }
 
@@ -78,21 +91,22 @@ public abstract class Node implements Serializable {
         return !children.isEmpty();
     }
 
-    public void setFileName(String fileName) {
-        this.fileName = fileName;
-    }
-
-    public String getFileName() {
-        return fileName;
-    }
-
     @Override
     public String toString() {
         return "";
     }
 
-    public String getRawString() {
-        return rawString;
+    /**
+     * Method for manipulating the data contained within the {@link Node}.
+     */
+    public abstract void traverse();
+
+    public Node getParentNode() {
+        return parentNode;
+    }
+
+    private void setParentNode(Node parentNode) {
+        this.parentNode = parentNode;
     }
 
 }
index aad45096165e38fa276298b1b5f48d4c04904370..38c5b1cb4ee2585899bc788f0a1b03d7381dbdf0 100644 (file)
@@ -19,9 +19,10 @@ package com.vaadin.sass.tree;
 import java.util.ArrayList;
 import java.util.regex.Pattern;
 
+import com.vaadin.sass.ScssStylesheet;
 import com.vaadin.sass.parser.LexicalUnitImpl;
 
-public class RuleNode extends Node implements IVariableNode, InterpolationNode {
+public class RuleNode extends Node implements IVariableNode {
     private static final long serialVersionUID = 6653493127869037022L;
 
     String variable;
@@ -83,36 +84,51 @@ public class RuleNode extends Node implements IVariableNode, InterpolationNode {
     @Override
     public void replaceVariables(ArrayList<VariableNode> variables) {
         for (final VariableNode node : variables) {
+
+            String interpolation = "#{$" + node.getName() + "}";
+
             if (value.getLexicalUnitType() == LexicalUnitImpl.SAC_FUNCTION) {
-                if (value.getParameters().toString()
-                        .contains("$" + node.getName())) {
-                    if (value.getParameters() != null) {
-                        if (value.getParameters().toString()
-                                .contains(node.getName())) {
-
-                            LexicalUnitImpl param = value.getParameters();
-                            while (param != null) {
-                                if (param.getValue().toString()
-                                        .contains(node.getName())) {
-
-                                    LexicalUnitImpl expr = node.getExpr();
-
-                                    LexicalUnitImpl prev = param
-                                            .getPreviousLexicalUnit();
-                                    LexicalUnitImpl next = param
-                                            .getNextLexicalUnit();
-
-                                    if (param.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE) {
-                                        param.replaceValue(expr);
-                                        param.setPrevLexicalUnit(prev);
-                                        param.setNextLexicalUnit(next);
-                                    }
+
+                if (value.getParameters() != null) {
+                    if (value.getParameters().toString()
+                            .contains(node.getName())) {
+
+                        LexicalUnitImpl param = value.getParameters();
+                        while (param != null) {
+                            if (param.getValue().toString()
+                                    .contains(node.getName())) {
+
+                                LexicalUnitImpl expr = node.getExpr();
+
+                                LexicalUnitImpl prev = param
+                                        .getPreviousLexicalUnit();
+                                LexicalUnitImpl next = param
+                                        .getNextLexicalUnit();
+
+                                if (param.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE) {
+                                    param.replaceValue(expr);
+                                    param.setPrevLexicalUnit(prev);
+                                    param.setNextLexicalUnit(next);
                                 }
-                                param = param.getNextLexicalUnit();
                             }
+                            param = param.getNextLexicalUnit();
                         }
                     }
                 }
+            } else if (value.getStringValue() != null
+                    && value.getStringValue().contains(interpolation)) {
+                LexicalUnitImpl current = value;
+                while (current != null) {
+                    if (current.getValue().toString().contains(interpolation)) {
+
+                        current.setStringValue(current
+                                .getValue()
+                                .toString()
+                                .replaceAll(Pattern.quote(interpolation),
+                                        node.getExpr().toString()));
+                    }
+                    current = current.getNextLexicalUnit();
+                }
             } else {
                 LexicalUnitImpl current = value;
                 while (current != null) {
@@ -129,32 +145,7 @@ public class RuleNode extends Node implements IVariableNode, InterpolationNode {
     }
 
     @Override
-    public void replaceInterpolation(String variableName, String variable) {
-        if (this.variable.contains(variableName)) {
-            this.variable = this.variable.replaceAll(variableName, variable);
-        }
-
-        if (value.toString().contains(variableName)) {
-
-            LexicalUnitImpl current = value;
-            while (current != null) {
-                if (current.getValue().toString().contains(variableName)) {
-                    current.setStringValue(current
-                            .getValue()
-                            .toString()
-                            .replaceAll(
-                                    Pattern.quote("#{" + variableName + "}"),
-                                    variable));
-                }
-
-                current = value.getNextLexicalUnit();
-            }
-        }
-    }
-
-    @Override
-    public boolean containsInterpolationVariable(String variable) {
-        return value.toString().contains(variable)
-                || this.variable.contains(variable);
+    public void traverse() {
+        replaceVariables(ScssStylesheet.getVariables());
     }
 }
index 52329c1b14f594ba1506972a4b7ace8088375c4f..adf1a3d15df74a0300fe1829c573d969e9ef56b8 100644 (file)
@@ -2,6 +2,8 @@ package com.vaadin.sass.tree;
 
 import java.util.ArrayList;
 
+import com.vaadin.sass.ScssStylesheet;
+
 /**
  * A simple BlockNode where input text equals output. <b>Note : </b> ignores any
  * possible children so only use it when you are sure no child nodes will be
@@ -33,4 +35,9 @@ public class SimpleNode extends Node implements IVariableNode {
             }
         }
     }
+
+    @Override
+    public void traverse() {
+        replaceVariables(ScssStylesheet.getVariables());
+    }
 }
index 6ba27ebac5d63985aa5da6642f84fb309c64438d..3ea83798291a2bc8716b4b7bbb0bdcf66b1a3777 100644 (file)
@@ -18,7 +18,9 @@ package com.vaadin.sass.tree;
 
 import java.util.ArrayList;
 
+import com.vaadin.sass.ScssStylesheet;
 import com.vaadin.sass.parser.LexicalUnitImpl;
+import com.vaadin.sass.visitor.VariableNodeHandler;
 
 public class VariableNode extends Node implements IVariableNode {
     private static final long serialVersionUID = 7003372557547748734L;
@@ -92,4 +94,10 @@ public class VariableNode extends Node implements IVariableNode {
             unit = unit.getNextLexicalUnit();
         }
     }
+
+    @Override
+    public void traverse() {
+        replaceVariables(ScssStylesheet.getVariables());
+        VariableNodeHandler.traverse(this);
+    }
 }
index 465fec061da7f5c8abaddaada660fc0f4c6422d9..4cd85a97a4eec416ff716ee7c91dfc2929c70551 100644 (file)
@@ -32,4 +32,9 @@ public class WhileNode extends Node {
         return "While Node: { condition: " + condition + ", body:" + body + "}";
     }
 
+    @Override
+    public void traverse() {
+
+    }
+
 }
index cb209273cbb3e8ec4d32d6d18dfdb9a9d6885f4a..4ab8486add85b39f5f81344bb9505a109f43b38b 100644 (file)
@@ -19,10 +19,12 @@ package com.vaadin.sass.tree.controldirective;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.vaadin.sass.ScssStylesheet;
 import com.vaadin.sass.parser.LexicalUnitImpl;
 import com.vaadin.sass.tree.IVariableNode;
 import com.vaadin.sass.tree.Node;
 import com.vaadin.sass.tree.VariableNode;
+import com.vaadin.sass.visitor.EachNodeHandler;
 
 public class EachDefNode extends Node implements IVariableNode {
     private static final long serialVersionUID = 7943948981204906221L;
@@ -88,4 +90,10 @@ public class EachDefNode extends Node implements IVariableNode {
     public String getListVariable() {
         return listVariable;
     }
+
+    @Override
+    public void traverse() {
+        replaceVariables(ScssStylesheet.getVariables());
+        EachNodeHandler.traverse(this);
+    }
 }
index 529ce4d76ea6b173b7e86c54f70babc9628559cb..ecda69d60188c9a95d0e7d7e193e5e76ea607fe2 100644 (file)
@@ -9,4 +9,9 @@ public class ElseNode extends Node implements IfElseNode {
         return null;
     }
 
+    @Override
+    public void traverse() {
+
+    }
+
 }
index 5bd3ba526ce8b1d266ce103eb40da78f8f22e877..9a818f0a2080cab7bb861cf7807574faed803fe9 100644 (file)
@@ -1,6 +1,7 @@
 package com.vaadin.sass.tree.controldirective;
 
 import com.vaadin.sass.tree.Node;
+import com.vaadin.sass.visitor.IfElseNodeHandler;
 
 public class IfElseDefNode extends Node {
 
@@ -14,4 +15,17 @@ public class IfElseDefNode extends Node {
         return b.toString();
     }
 
+    public void traverse() {
+        try {
+
+            for (final Node child : children) {
+                child.traverse();
+            }
+
+            IfElseNodeHandler.traverse(this);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
 }
index 8de7ccf78a88116a83ca42a4db16bc9bde50b2e3..cdaf1b0552e64f838be2ced5136ce94117039206 100644 (file)
@@ -18,6 +18,7 @@ package com.vaadin.sass.tree.controldirective;
 import java.util.ArrayList;
 import java.util.regex.Pattern;
 
+import com.vaadin.sass.ScssStylesheet;
 import com.vaadin.sass.tree.IVariableNode;
 import com.vaadin.sass.tree.Node;
 import com.vaadin.sass.tree.VariableNode;
@@ -46,11 +47,17 @@ public class IfNode extends Node implements IfElseNode, IVariableNode {
     @Override
     public void replaceVariables(ArrayList<VariableNode> variables) {
         for (final VariableNode node : variables) {
-            if (expression.contains("$" + node.getName())) {
-                expression = expression.replaceAll(Pattern.quote("$"
-                        + node.getName()), node.getExpr().toString());
+            String variable = "$" + node.getName();
+            if (expression.contains(variable)) {
+                expression = expression.replaceAll(Pattern.quote(variable),
+                        node.getExpr().toString());
             }
         }
     }
 
+    @Override
+    public void traverse() {
+        replaceVariables(ScssStylesheet.getVariables());
+    }
+
 }
\ No newline at end of file
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/BlockNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/BlockNodeHandler.java
new file mode 100644 (file)
index 0000000..efbfc4b
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * 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 com.vaadin.sass.visitor;
+
+import java.util.ArrayList;
+
+import com.vaadin.sass.tree.BlockNode;
+import com.vaadin.sass.tree.Node;
+
+public class BlockNodeHandler {
+
+    public static void traverse(BlockNode node) {
+
+        Node parent = node.getParentNode();
+        if (node.getChildren().size() == 0) {
+            parent.removeChild(node);
+            while (parent != null && parent instanceof BlockNode
+                    && parent.getChildren().size() == 0) {
+                Node temp = parent;
+                parent = parent.getParentNode();
+                parent.removeChild(temp);
+            }
+
+            return;
+        }
+
+        if (parent instanceof BlockNode) {
+            combineParentSelectorListToChild(node);
+        }
+    }
+
+    private static void combineParentSelectorListToChild(BlockNode node) {
+        ArrayList<String> newList = new ArrayList<String>();
+        ArrayList<String> parentSelectors = ((BlockNode) node.getParentNode())
+                .getSelectorList();
+        ArrayList<String> childSelectors = ((BlockNode) node).getSelectorList();
+        for (int i = 0; i < parentSelectors.size(); i++) {
+            String parentSelector = parentSelectors.get(i);
+            for (int j = 0; j < childSelectors.size(); j++) {
+                String childSelector = childSelectors.get(j);
+                newList.add(parentSelector + " " + childSelector);
+            }
+
+        }
+        node.setSelectorList(newList);
+        node.getParentNode().getParentNode()
+                .appendChild(node, node.getParentNode());
+    }
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/BlockVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/BlockVisitor.java
deleted file mode 100644 (file)
index 3cbf7e1..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * 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 com.vaadin.sass.visitor;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Set;
-
-import com.vaadin.sass.tree.BlockNode;
-import com.vaadin.sass.tree.Node;
-
-public class BlockVisitor implements Visitor {
-
-    @Override
-    public void traverse(Node node) {
-        traverse(null, node);
-    }
-
-    private void traverse(Node parent, Node node) {
-        Node after = node;
-        Set<Node> toBeDeleted = new HashSet<Node>();
-        for (int pos = 0; pos < node.getChildren().size(); pos++) {
-            Node child = node.getChildren().get(pos);
-
-            traverse(node, child);
-
-            if (child instanceof BlockNode && node instanceof BlockNode
-                    && parent != null) {
-                combineParentSelectorListToChild(node, child);
-                toBeDeleted.add(child);
-                parent.appendChild(child, after);
-                after = child;
-            } else if (child instanceof BlockNode
-                    && child.getChildren().size() == 0) {
-                toBeDeleted.add(child);
-            }
-        }
-        for (Node child : toBeDeleted) {
-            node.removeChild(child);
-        }
-    }
-
-    private void combineParentSelectorListToChild(Node parent, Node child) {
-        if (parent instanceof BlockNode && child instanceof BlockNode) {
-            ArrayList<String> newList = new ArrayList<String>();
-            ArrayList<String> parentSelectors = ((BlockNode) parent)
-                    .getSelectorList();
-            ArrayList<String> childSelectors = ((BlockNode) child)
-                    .getSelectorList();
-            for (int i = 0; i < parentSelectors.size(); i++) {
-                String parentSelector = parentSelectors.get(i);
-                for (int j = 0; j < childSelectors.size(); j++) {
-                    String childSelector = childSelectors.get(j);
-                    newList.add(parentSelector + " " + childSelector);
-                }
-
-            }
-            ((BlockNode) child).setSelectorList(newList);
-        }
-    }
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/EachNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/EachNodeHandler.java
new file mode 100644 (file)
index 0000000..0eb86f3
--- /dev/null
@@ -0,0 +1,57 @@
+package com.vaadin.sass.visitor;
+
+import java.util.ArrayList;
+
+import com.vaadin.sass.ScssStylesheet;
+import com.vaadin.sass.parser.LexicalUnitImpl;
+import com.vaadin.sass.tree.IVariableNode;
+import com.vaadin.sass.tree.Node;
+import com.vaadin.sass.tree.VariableNode;
+import com.vaadin.sass.tree.controldirective.EachDefNode;
+import com.vaadin.sass.util.DeepCopy;
+
+public class EachNodeHandler {
+
+    public static void traverse(EachDefNode node) {
+        replaceEachDefNode(node);
+    }
+
+    private static void replaceEachDefNode(EachDefNode defNode) {
+        Node last = defNode;
+
+        for (final String var : defNode.getVariables()) {
+            VariableNode varNode = new VariableNode(defNode.getVariableName()
+                    .substring(1), LexicalUnitImpl.createIdent(var), false);
+            ArrayList<VariableNode> variables = new ArrayList<VariableNode>(
+                    ScssStylesheet.getVariables());
+            variables.add(varNode);
+
+            for (final Node child : defNode.getChildren()) {
+
+                Node copy = (Node) DeepCopy.copy(child);
+
+                replaceInterpolation(copy, variables);
+
+                defNode.getParentNode().appendChild(copy, last);
+                last = copy;
+            }
+
+        }
+        defNode.setChildren(new ArrayList<Node>());
+        defNode.getParentNode().removeChild(defNode);
+    }
+
+    private static void replaceInterpolation(Node copy,
+            ArrayList<VariableNode> variables) {
+        if (copy instanceof IVariableNode) {
+            IVariableNode n = (IVariableNode) copy;
+            n.replaceVariables(variables);
+        }
+
+        for (Node c : copy.getChildren()) {
+            replaceInterpolation(c, variables);
+        }
+
+    }
+
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/EachVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/EachVisitor.java
deleted file mode 100644 (file)
index de58947..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.vaadin.sass.visitor;
-
-import java.util.HashMap;
-import java.util.Map.Entry;
-
-import com.vaadin.sass.tree.BlockNode;
-import com.vaadin.sass.tree.Node;
-import com.vaadin.sass.tree.RuleNode;
-import com.vaadin.sass.tree.controldirective.EachDefNode;
-import com.vaadin.sass.util.DeepCopy;
-
-public class EachVisitor implements Visitor {
-
-    HashMap<EachDefNode, Node> controlDefs = new HashMap<EachDefNode, Node>();
-    private Node rootNode;
-
-    @Override
-    public void traverse(Node node) throws Exception {
-        this.rootNode = node;
-
-        findDefNodes(null, node);
-
-        replaceControlNodes();
-
-    }
-
-    private void findDefNodes(Node parent, Node node) {
-        for (Node child : node.getChildren()) {
-            findDefNodes(node, child);
-        }
-        if (node instanceof EachDefNode) {
-            controlDefs.put((EachDefNode) node, parent);
-        }
-    }
-
-    private void replaceControlNodes() {
-        for (final Entry<EachDefNode, Node> entry : controlDefs.entrySet()) {
-            replaceEachDefNode(entry.getKey(), entry.getValue());
-        }
-    }
-
-    private void replaceEachDefNode(EachDefNode defNode, Node parent) {
-        Node last = defNode;
-        for (final Node child : defNode.getChildren()) {
-            if (child instanceof BlockNode) {
-                BlockNode iNode = (BlockNode) child;
-                String interpolation = "#{" + defNode.getVariableName() + "}";
-                if (iNode.containsInterpolationVariable(interpolation)) {
-                    for (final String variable : defNode.getVariables()) {
-                        BlockNode copy = (BlockNode) DeepCopy.copy(child);
-                        copy.replaceInterpolation(defNode.getVariableName(),
-                                variable);
-
-                        for (final Node blockChild : copy.getChildren()) {
-                            if (blockChild instanceof RuleNode) {
-                                ((RuleNode) blockChild).replaceInterpolation(
-                                        defNode.getVariableName(), variable);
-                            }
-                        }
-
-                        parent.appendChild(copy, last);
-                        last = copy;
-                    }
-                }
-            }
-
-            last = child;
-        }
-        parent.removeChild(defNode);
-    }
-
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/ExtendNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/ExtendNodeHandler.java
new file mode 100644 (file)
index 0000000..0e05781
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * 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 com.vaadin.sass.visitor;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import com.vaadin.sass.ScssStylesheet;
+import com.vaadin.sass.tree.BlockNode;
+import com.vaadin.sass.tree.ExtendNode;
+import com.vaadin.sass.tree.Node;
+
+public class ExtendNodeHandler {
+    private static Map<String, List<ArrayList<String>>> extendsMap = new HashMap<String, List<ArrayList<String>>>();
+
+    public static void traverse(ExtendNode node) throws Exception {
+        buildExtendsMap(node);
+        modifyTree(ScssStylesheet.get());
+    }
+
+    private static void modifyTree(Node node) throws Exception {
+        for (Node child : node.getChildren()) {
+            if (child instanceof BlockNode) {
+                BlockNode blockNode = (BlockNode) child;
+                String selectorString = blockNode.getSelectors();
+                if (extendsMap.get(selectorString) != null) {
+                    for (ArrayList<String> sList : extendsMap
+                            .get(selectorString)) {
+                        ArrayList<String> clone = (ArrayList<String>) sList
+                                .clone();
+                        addAdditionalSelectorListToBlockNode(blockNode, clone,
+                                null);
+                    }
+                } else {
+                    for (Entry<String, List<ArrayList<String>>> entry : extendsMap
+                            .entrySet()) {
+                        if (selectorString.contains(entry.getKey())) {
+                            for (ArrayList<String> sList : entry.getValue()) {
+                                ArrayList<String> clone = (ArrayList<String>) sList
+                                        .clone();
+                                addAdditionalSelectorListToBlockNode(blockNode,
+                                        clone, entry.getKey());
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+    }
+
+    private static void buildExtendsMap(ExtendNode node) {
+        String extendedString = node.getListAsString();
+        if (extendsMap.get(extendedString) == null) {
+            extendsMap.put(extendedString, new ArrayList<ArrayList<String>>());
+        }
+        extendsMap.get(extendedString).add(
+                ((BlockNode) node.getParentNode()).getSelectorList());
+    }
+
+    private static void addAdditionalSelectorListToBlockNode(
+            BlockNode blockNode, ArrayList<String> list, String selectorString) {
+        if (list != null) {
+            for (int i = 0; i < list.size(); i++) {
+                if (selectorString == null) {
+                    blockNode.getSelectorList().add(list.get(i));
+                } else {
+                    ArrayList<String> newTags = new ArrayList<String>();
+                    for (final String existing : blockNode.getSelectorList()) {
+                        if (existing.contains(selectorString)) {
+                            newTags.add(existing.replace(selectorString,
+                                    list.get(i)));
+                        }
+                    }
+                    blockNode.getSelectorList().addAll(newTags);
+                }
+            }
+        }
+    }
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/ExtendVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/ExtendVisitor.java
deleted file mode 100644 (file)
index 23519b6..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * 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 com.vaadin.sass.visitor;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import com.vaadin.sass.tree.BlockNode;
-import com.vaadin.sass.tree.ExtendNode;
-import com.vaadin.sass.tree.Node;
-
-public class ExtendVisitor implements Visitor {
-    private Map<String, List<ArrayList<String>>> extendsMap = new HashMap<String, List<ArrayList<String>>>();
-
-    @Override
-    public void traverse(Node node) throws Exception {
-        buildExtendsMap(node);
-        modifyTree(node);
-    }
-
-    @SuppressWarnings("unchecked")
-    private void modifyTree(Node node) throws Exception {
-        for (Node child : node.getChildren()) {
-            if (child instanceof BlockNode) {
-                BlockNode blockNode = (BlockNode) child;
-                String selectorString = blockNode.getSelectors();
-                if (extendsMap.get(selectorString) != null) {
-                    for (ArrayList<String> sList : extendsMap
-                            .get(selectorString)) {
-                        ArrayList<String> clone = (ArrayList<String>) sList
-                                .clone();
-                        addAdditionalSelectorListToBlockNode(blockNode, clone,
-                                null);
-                    }
-                } else {
-                    for (Entry<String, List<ArrayList<String>>> entry : extendsMap
-                            .entrySet()) {
-                        if (selectorString.contains(entry.getKey())) {
-                            for (ArrayList<String> sList : entry.getValue()) {
-                                ArrayList<String> clone = (ArrayList<String>) sList
-                                        .clone();
-                                addAdditionalSelectorListToBlockNode(blockNode,
-                                        clone, entry.getKey());
-                            }
-                        }
-                    }
-                }
-            } else {
-                buildExtendsMap(child);
-            }
-        }
-
-    }
-
-    private void buildExtendsMap(Node node) {
-        if (node instanceof BlockNode) {
-            BlockNode blockNode = (BlockNode) node;
-            for (Node child : new ArrayList<Node>(node.getChildren())) {
-                if (child instanceof ExtendNode) {
-                    ExtendNode extendNode = (ExtendNode) child;
-
-                    String extendedString = extendNode.getListAsString();
-                    if (extendsMap.get(extendedString) == null) {
-                        extendsMap.put(extendedString,
-                                new ArrayList<ArrayList<String>>());
-                    }
-                    extendsMap.get(extendedString).add(
-                            blockNode.getSelectorList());
-                    node.removeChild(child);
-                } else {
-                    buildExtendsMap(child);
-                }
-            }
-        } else {
-            for (Node child : node.getChildren()) {
-                buildExtendsMap(child);
-            }
-        }
-
-    }
-
-    private void addAdditionalSelectorListToBlockNode(BlockNode blockNode,
-            ArrayList<String> list, String selectorString) {
-        if (list != null) {
-            for (int i = 0; i < list.size(); i++) {
-                if (selectorString == null) {
-                    blockNode.getSelectorList().add(list.get(i));
-                } else {
-                    ArrayList<String> newTags = new ArrayList<String>();
-                    for (final String existing : blockNode.getSelectorList()) {
-                        if (existing.contains(selectorString)) {
-                            newTags.add(existing.replace(selectorString,
-                                    list.get(i)));
-                        }
-                    }
-                    blockNode.getSelectorList().addAll(newTags);
-                }
-            }
-        }
-    }
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/IfElseNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/IfElseNodeHandler.java
new file mode 100644 (file)
index 0000000..593f22a
--- /dev/null
@@ -0,0 +1,102 @@
+package com.vaadin.sass.visitor;
+
+import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.jexl2.Expression;
+import org.apache.commons.jexl2.JexlEngine;
+import org.apache.commons.jexl2.JexlException;
+import org.w3c.flute.parser.ParseException;
+
+import com.vaadin.sass.tree.Node;
+import com.vaadin.sass.tree.controldirective.ElseNode;
+import com.vaadin.sass.tree.controldirective.IfElseDefNode;
+import com.vaadin.sass.tree.controldirective.IfElseNode;
+import com.vaadin.sass.tree.controldirective.IfNode;
+
+public class IfElseNodeHandler {
+
+    private static final JexlEngine evaluator = new JexlEngine();
+    private static final Pattern pattern = Pattern
+            .compile("[a-zA-Z0-9]*[a-zA-Z]+[a-zA-Z0-9]*");
+
+    public static void traverse(IfElseDefNode node) throws Exception {
+
+        for (final Node child : node.getChildren()) {
+            if (child instanceof IfNode) {
+                try {
+                    String expression = ((IfElseNode) child).getExpression();
+                    // We need to add ' ' for strings in the expression for
+                    // jexl to understand that is should do a string
+                    // comparison
+                    expression = replaceStrings(expression);
+                    Expression e = evaluator.createExpression(expression);
+                    try {
+                        Object eval = e.evaluate(null);
+
+                        Boolean result = false;
+                        if (eval instanceof Boolean) {
+                            result = (Boolean) eval;
+                        } else if (eval instanceof String) {
+                            result = Boolean.valueOf((String) eval);
+                        }
+
+                        if (result) {
+                            replaceDefNodeWithCorrectChild(node,
+                                    node.getParentNode(), child);
+                            break;
+                        }
+                    } catch (ClassCastException ex) {
+                        throw new ParseException(
+                                "Invalid @if/@else in scss file, not a boolean expression : "
+                                        + child.toString());
+                    } catch (NullPointerException ex) {
+                        throw new ParseException(
+                                "Invalid @if/@else in scss file, not a boolean expression : "
+                                        + child.toString());
+                    }
+                } catch (JexlException e) {
+                    throw new ParseException(
+                            "Invalid @if/@else in scss file for "
+                                    + child.toString());
+                }
+            } else {
+                if (!(child instanceof ElseNode)
+                        && node.getChildren().indexOf(child) == node
+                                .getChildren().size() - 1) {
+                    throw new ParseException(
+                            "Invalid @if/@else in scss file for " + node);
+                } else {
+                    replaceDefNodeWithCorrectChild(node, node.getParentNode(),
+                            child);
+                    break;
+                }
+            }
+        }
+
+        node.getParentNode().removeChild(node);
+    }
+
+    private static String replaceStrings(String expression) {
+        expression = expression.replaceAll("\"", "");
+        Matcher m = pattern.matcher(expression);
+        StringBuffer b = new StringBuffer();
+        while (m.find()) {
+            String group = m.group();
+            m.appendReplacement(b, "'" + group + "'");
+        }
+        m.appendTail(b);
+        if (b.length() != 0) {
+            return b.toString();
+        }
+        return expression;
+    }
+
+    private static void replaceDefNodeWithCorrectChild(IfElseDefNode defNode,
+            Node parent, final Node child) {
+        for (final Node n : new ArrayList<Node>(child.getChildren())) {
+            parent.appendChild(n, defNode);
+        }
+    }
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/IfElseVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/IfElseVisitor.java
deleted file mode 100644 (file)
index 2cffb89..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-package com.vaadin.sass.visitor;
-
-import java.util.HashMap;
-import java.util.Map.Entry;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.commons.jexl2.Expression;
-import org.apache.commons.jexl2.JexlEngine;
-import org.apache.commons.jexl2.JexlException;
-import org.w3c.flute.parser.ParseException;
-
-import com.vaadin.sass.tree.Node;
-import com.vaadin.sass.tree.controldirective.ElseNode;
-import com.vaadin.sass.tree.controldirective.IfElseDefNode;
-import com.vaadin.sass.tree.controldirective.IfElseNode;
-import com.vaadin.sass.tree.controldirective.IfNode;
-
-public class IfElseVisitor implements Visitor {
-
-    private HashMap<Node, IfElseDefNode> controlDefs = new HashMap<Node, IfElseDefNode>();
-
-    private static final JexlEngine evaluator = new JexlEngine();
-    private static final Pattern pattern = Pattern
-            .compile("[a-zA-Z0-9]*[a-zA-Z]+[a-zA-Z0-9]*");
-
-    @Override
-    public void traverse(Node node) throws Exception {
-        addControlDefs(node, node);
-
-        for (final Entry<Node, IfElseDefNode> entry : controlDefs.entrySet()) {
-            IfElseDefNode defNode = entry.getValue();
-            Node parent = entry.getKey();
-            for (final Node child : defNode.getChildren()) {
-                if (child instanceof IfNode) {
-                    try {
-                        String expression = ((IfElseNode) child)
-                                .getExpression();
-                        // We need to add ' ' for strings in the expression for
-                        // jexl to understand that is should do a string
-                        // comparison
-                        expression = replaceStrings(expression);
-                        Expression e = evaluator.createExpression(expression);
-                        try {
-                            Object eval = e.evaluate(null);
-
-                            Boolean result = false;
-                            if (eval instanceof Boolean) {
-                                result = (Boolean) eval;
-                            } else if (eval instanceof String) {
-                                result = Boolean.valueOf((String) eval);
-                            }
-
-                            if (result) {
-                                replaceDefNodeWithCorrectChild(defNode, parent,
-                                        child);
-                                break;
-                            }
-                            System.out.println();
-                        } catch (ClassCastException ex) {
-                            throw new ParseException(
-                                    "Invalid @if/@else in scss file, not a boolean expression : "
-                                            + child.toString());
-                        } catch (NullPointerException ex) {
-                            throw new ParseException(
-                                    "Invalid @if/@else in scss file, not a boolean expression : "
-                                            + child.toString());
-                        }
-                    } catch (JexlException e) {
-                        throw new ParseException(
-                                "Invalid @if/@else in scss file for "
-                                        + child.toString());
-                    }
-                } else {
-                    if (!(child instanceof ElseNode)
-                            && defNode.getChildren().indexOf(child) == defNode
-                                    .getChildren().size() - 1) {
-                        throw new ParseException(
-                                "Invalid @if/@else in scss file for " + defNode);
-                    } else {
-                        replaceDefNodeWithCorrectChild(defNode, parent, child);
-                        break;
-                    }
-                }
-            }
-
-            parent.removeChild(defNode);
-        }
-
-    }
-
-    private String replaceStrings(String expression) {
-        expression = expression.replaceAll("\"", "");
-        Matcher m = pattern.matcher(expression);
-        StringBuffer b = new StringBuffer();
-        while (m.find()) {
-            String group = m.group();
-            m.appendReplacement(b, "'" + group + "'");
-        }
-        m.appendTail(b);
-        if (b.length() != 0) {
-            return b.toString();
-        }
-        return expression;
-    }
-
-    private void replaceDefNodeWithCorrectChild(IfElseDefNode defNode,
-            Node parent, final Node child) {
-        for (final Node n : child.getChildren()) {
-            parent.appendChild(n, defNode);
-        }
-    }
-
-    private void addControlDefs(Node current, Node node) {
-        for (Node child : current.getChildren()) {
-            addControlDefs(node, child);
-            if (child instanceof IfElseDefNode) {
-                controlDefs.put(current, (IfElseDefNode) child);
-            }
-        }
-    }
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/ImportNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/ImportNodeHandler.java
new file mode 100644 (file)
index 0000000..f2fb128
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * 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 com.vaadin.sass.visitor;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.w3c.css.sac.CSSException;
+import org.w3c.css.sac.LexicalUnit;
+
+import com.vaadin.sass.ScssStylesheet;
+import com.vaadin.sass.parser.LexicalUnitImpl;
+import com.vaadin.sass.tree.ImportNode;
+import com.vaadin.sass.tree.Node;
+import com.vaadin.sass.tree.RuleNode;
+import com.vaadin.sass.util.StringUtil;
+
+public class ImportNodeHandler {
+
+    public static void traverse(ScssStylesheet node) {
+        ArrayList<Node> c = new ArrayList<Node>(node.getChildren());
+        for (Node n : c) {
+            if (n instanceof ImportNode) {
+                ImportNode importNode = (ImportNode) n;
+                if (!importNode.isPureCssImport()) {
+                    try {
+                        StringBuilder filePathBuilder = new StringBuilder(
+                                node.getFileName());
+                        filePathBuilder.append(File.separatorChar).append(
+                                importNode.getUri());
+                        if (!filePathBuilder.toString().endsWith(".scss")) {
+                            filePathBuilder.append(".scss");
+                        }
+
+                        ScssStylesheet imported = ScssStylesheet
+                                .get(filePathBuilder.toString());
+                        if (imported == null) {
+                            imported = ScssStylesheet.get(importNode.getUri());
+                        }
+                        if (imported == null) {
+                            throw new FileNotFoundException(importNode.getUri()
+                                    + " (parent: "
+                                    + ScssStylesheet.get().getFileName() + ")");
+                        }
+
+                        traverse(imported);
+
+                        String prefix = getUrlPrefix(importNode.getUri());
+                        if (prefix != null) {
+                            updateUrlInImportedSheet(imported, prefix);
+                        }
+
+                        Node pre = importNode;
+                        for (Node importedChild : new ArrayList<Node>(
+                                imported.getChildren())) {
+                            node.appendChild(importedChild, pre);
+                            pre = importedChild;
+                        }
+                        node.removeChild(importNode);
+                    } catch (CSSException e) {
+                        e.printStackTrace();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+    }
+
+    private static String getUrlPrefix(String url) {
+        if (url == null) {
+            return null;
+        }
+        int pos = url.lastIndexOf('/');
+        if (pos == -1) {
+            return null;
+        }
+        return url.substring(0, pos + 1);
+    }
+
+    private static void updateUrlInImportedSheet(Node node, String prefix) {
+        for (Node child : node.getChildren()) {
+            if (child instanceof RuleNode) {
+                LexicalUnit value = ((RuleNode) child).getValue();
+                while (value != null) {
+                    if (value.getLexicalUnitType() == LexicalUnit.SAC_URI) {
+                        String path = value.getStringValue();
+                        if (!path.startsWith("/") && !path.contains(":")) {
+                            path = prefix + path;
+                            path = StringUtil.cleanPath(path);
+                            ((LexicalUnitImpl) value).setStringValue(path);
+                        }
+                    }
+                    value = value.getNextLexicalUnit();
+                }
+
+            }
+            updateUrlInImportedSheet(child, prefix);
+        }
+    }
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/ImportVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/ImportVisitor.java
deleted file mode 100644 (file)
index bda040b..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * 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 com.vaadin.sass.visitor;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-
-import org.w3c.css.sac.CSSException;
-import org.w3c.css.sac.LexicalUnit;
-
-import com.vaadin.sass.ScssStylesheet;
-import com.vaadin.sass.parser.LexicalUnitImpl;
-import com.vaadin.sass.tree.ImportNode;
-import com.vaadin.sass.tree.Node;
-import com.vaadin.sass.tree.RuleNode;
-import com.vaadin.sass.util.StringUtil;
-
-public class ImportVisitor implements Visitor {
-
-    @Override
-    public void traverse(Node node) {
-        for (Node child : new ArrayList<Node>(node.getChildren())) {
-            if (child instanceof ImportNode) {
-                ImportNode importNode = (ImportNode) child;
-                if (!importNode.isPureCssImport()) {
-
-                    try {
-
-                        StringBuilder filePathBuilder = new StringBuilder(
-                                node.getFileName());
-                        filePathBuilder.append(File.separatorChar).append(
-                                importNode.getUri());
-                        if (!filePathBuilder.toString().endsWith(".scss")) {
-                            filePathBuilder.append(".scss");
-                        }
-
-                        ScssStylesheet imported = ScssStylesheet
-                                .get(filePathBuilder.toString());
-                        if (imported == null) {
-                            imported = ScssStylesheet.get(importNode.getUri());
-                        }
-                        if (imported == null) {
-                            throw new FileNotFoundException(importNode.getUri()
-                                    + " (parent: " + node.getFileName() + ")");
-                        }
-
-                        traverse(imported);
-                        String prefix = getUrlPrefix(importNode.getUri());
-                        if (prefix != null) {
-                            updateUrlInImportedSheet(imported, prefix);
-                        }
-                        Node pre = importNode;
-                        for (Node importedChild : imported.getChildren()) {
-                            node.appendChild(importedChild, pre);
-                            pre = importedChild;
-                        }
-                        node.removeChild(importNode);
-                    } catch (CSSException e) {
-                        e.printStackTrace();
-                    } catch (IOException e) {
-                        e.printStackTrace();
-                    }
-                }
-            }
-        }
-    }
-
-    private String getUrlPrefix(String url) {
-        if (url == null) {
-            return null;
-        }
-        int pos = url.lastIndexOf('/');
-        if (pos == -1) {
-            return null;
-        }
-        return url.substring(0, pos + 1);
-    }
-
-    private void updateUrlInImportedSheet(Node node, String prefix) {
-        for (Node child : node.getChildren()) {
-            if (child instanceof RuleNode) {
-                LexicalUnit value = ((RuleNode) child).getValue();
-                while (value != null) {
-                    if (value.getLexicalUnitType() == LexicalUnit.SAC_URI) {
-                        String path = value.getStringValue();
-                        if (!path.startsWith("/") && !path.contains(":")) {
-                            path = prefix + path;
-                            path = StringUtil.cleanPath(path);
-                            ((LexicalUnitImpl) value).setStringValue(path);
-                        }
-                    }
-                    value = value.getNextLexicalUnit();
-                }
-
-            }
-            updateUrlInImportedSheet(child, prefix);
-        }
-    }
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/ListModifyVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/ListModifyVisitor.java
deleted file mode 100644 (file)
index 3edb599..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.vaadin.sass.visitor;
-
-import java.util.ArrayList;
-
-import com.vaadin.sass.tree.ListModifyNode;
-import com.vaadin.sass.tree.Node;
-
-public class ListModifyVisitor implements Visitor {
-
-    @Override
-    public void traverse(Node node) throws Exception {
-        for (final Node child : new ArrayList<Node>(node.getChildren())) {
-            removeNodes(child, node);
-        }
-    }
-
-    private void removeNodes(Node child, Node parent) {
-        for (final Node c : new ArrayList<Node>(child.getChildren())) {
-            removeNodes(c, child);
-        }
-
-        if (child instanceof ListModifyNode) {
-            parent.removeChild(child);
-        }
-
-    }
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/MixinNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/MixinNodeHandler.java
new file mode 100644 (file)
index 0000000..3c31ee1
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * 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 com.vaadin.sass.visitor;
+
+import java.util.ArrayList;
+
+import com.vaadin.sass.ScssStylesheet;
+import com.vaadin.sass.parser.LexicalUnitImpl;
+import com.vaadin.sass.tree.IVariableNode;
+import com.vaadin.sass.tree.MixinDefNode;
+import com.vaadin.sass.tree.MixinNode;
+import com.vaadin.sass.tree.Node;
+import com.vaadin.sass.tree.VariableNode;
+import com.vaadin.sass.util.DeepCopy;
+
+public class MixinNodeHandler {
+
+    public static void traverse(MixinNode node) throws Exception {
+        replaceMixins(node);
+    }
+
+    private static void replaceMixins(MixinNode node) throws Exception {
+        MixinDefNode mixinDef = ScssStylesheet.getMixinDefinition(node
+                .getName());
+        if (mixinDef == null) {
+            throw new Exception("Mixin Definition: " + node.getName()
+                    + " not found");
+        }
+        replaceMixinNode(node, mixinDef);
+    }
+
+    private static void replaceMixinNode(MixinNode mixinNode,
+            MixinDefNode mixinDef) {
+        Node pre = mixinNode;
+
+        MixinDefNode defClone = (MixinDefNode) DeepCopy.copy(mixinDef);
+
+        if (mixinDef.getArglist().isEmpty()) {
+            for (Node child : new ArrayList<Node>(defClone.getChildren())) {
+                mixinNode.getParentNode().appendChild(child, pre);
+                pre = child;
+            }
+        } else {
+
+            replacePossibleArguments(mixinNode, defClone);
+
+            Node previous = mixinNode;
+            for (final Node child : defClone.getChildren()) {
+
+                Node clone = (Node) DeepCopy.copy(child);
+
+                replaceChildVariables(defClone, clone);
+
+                mixinNode.getParentNode().appendChild(clone, previous);
+
+                previous = clone;
+
+            }
+
+        }
+
+        mixinNode.getParentNode().removeChild(mixinNode);
+    }
+
+    /**
+     * We have to replace all the mixin parameters. This is done in two phases.
+     * First phase replaces all the named parameters while the second replaces
+     * in order of remaining unmodified parameters.
+     * 
+     * @param mixinNode
+     * @param def
+     */
+    private static void replacePossibleArguments(MixinNode mixinNode,
+            MixinDefNode def) {
+
+        if (mixinNode.getArglist().size() > 0) {
+            ArrayList<VariableNode> remainingNodes = new ArrayList<VariableNode>(
+                    def.getArglist());
+            ArrayList<LexicalUnitImpl> remainingUnits = new ArrayList<LexicalUnitImpl>(
+                    mixinNode.getArglist());
+
+            for (final LexicalUnitImpl unit : mixinNode.getArglist()) {
+                if (unit.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE
+                        && unit.getNextLexicalUnit() != null) {
+                    for (final VariableNode node : def.getArglist()) {
+                        if (node.getName().equals(unit.getValue().toString())) {
+                            node.setExpr((LexicalUnitImpl) DeepCopy.copy(unit
+                                    .getNextLexicalUnit()));
+                            remainingNodes.remove(node);
+                            remainingUnits.remove(unit);
+                            break;
+                        }
+                    }
+                }
+            }
+
+            int i = 0;
+            for (final LexicalUnitImpl unit : remainingUnits) {
+                remainingNodes.get(i).setExpr(
+                        (LexicalUnitImpl) DeepCopy.copy(unit));
+                i++;
+            }
+
+        }
+
+    }
+
+    private static void replaceChildVariables(MixinDefNode mixinDef, Node node) {
+        for (final Node child : node.getChildren()) {
+            replaceChildVariables(mixinDef, child);
+        }
+        if (node instanceof IVariableNode) {
+            ((IVariableNode) node).replaceVariables(mixinDef.getArglist());
+        }
+    }
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/MixinVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/MixinVisitor.java
deleted file mode 100644 (file)
index fecc717..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * 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 com.vaadin.sass.visitor;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
-import com.vaadin.sass.parser.LexicalUnitImpl;
-import com.vaadin.sass.tree.IVariableNode;
-import com.vaadin.sass.tree.MixinDefNode;
-import com.vaadin.sass.tree.MixinNode;
-import com.vaadin.sass.tree.Node;
-import com.vaadin.sass.tree.VariableNode;
-import com.vaadin.sass.util.DeepCopy;
-
-public class MixinVisitor implements Visitor {
-    Map<String, MixinDefNode> mixinDefs = new HashMap<String, MixinDefNode>();
-
-    @Override
-    public void traverse(Node node) throws Exception {
-        // create mixin map.
-        for (Node child : node.getChildren()) {
-            if (child instanceof MixinDefNode) {
-                mixinDefs.put(((MixinDefNode) child).getName(),
-                        (MixinDefNode) child);
-            }
-        }
-
-        replaceMixins(node);
-
-        // delete MixinDefNode
-        for (Node child : new ArrayList<Node>(node.getChildren())) {
-            if (child instanceof MixinDefNode) {
-                node.removeChild(child);
-            }
-        }
-
-    }
-
-    private void replaceMixins(Node node) throws Exception {
-        for (Node child : new ArrayList<Node>(node.getChildren())) {
-            replaceMixins(child);
-            if (child instanceof MixinNode) {
-                MixinNode mixinNode = (MixinNode) child;
-                MixinDefNode mixinDef = mixinDefs.get(mixinNode.getName());
-                if (mixinDef == null) {
-                    throw new Exception("Mixin Definition: "
-                            + mixinNode.getName() + " not found");
-                }
-                replaceMixinNode(node, mixinNode, mixinDef);
-            }
-        }
-    }
-
-    private void replaceMixinNode(Node current, MixinNode mixinNode,
-            MixinDefNode mixinDef) {
-        Node pre = mixinNode;
-        if (mixinDef.getArglist().isEmpty()) {
-            for (Node child : mixinDef.getChildren()) {
-                current.appendChild(child, pre);
-                pre = child;
-            }
-        } else {
-
-            MixinDefNode defClone = (MixinDefNode) DeepCopy.copy(mixinDef);
-
-            replacePossibleArguments(mixinNode, defClone);
-
-            Node previous = mixinNode;
-            for (final Node child : defClone.getChildren()) {
-
-                Node clone = (Node) DeepCopy.copy(child);
-
-                replaceChildVariables(defClone, clone);
-
-                current.appendChild(clone, previous);
-
-                previous = clone;
-
-            }
-
-        }
-        current.removeChild(mixinNode);
-    }
-
-    /**
-     * We have to replace all the mixin parameters. This is done in two phases.
-     * First phase replaces all the named parameters while the second replaces
-     * in order of remaining unmodified parameters.
-     * 
-     * @param mixinNode
-     * @param def
-     */
-    private void replacePossibleArguments(MixinNode mixinNode, MixinDefNode def) {
-
-        if (mixinNode.getArglist().size() > 0) {
-            ArrayList<VariableNode> remainingNodes = new ArrayList<VariableNode>(
-                    def.getArglist());
-            ArrayList<LexicalUnitImpl> remainingUnits = new ArrayList<LexicalUnitImpl>(
-                    mixinNode.getArglist());
-
-            for (final LexicalUnitImpl unit : mixinNode.getArglist()) {
-                if (unit.getLexicalUnitType() == LexicalUnitImpl.SCSS_VARIABLE
-                        && unit.getNextLexicalUnit() != null) {
-                    for (final VariableNode node : def.getArglist()) {
-                        if (node.getName().equals(unit.getValue().toString())) {
-                            node.setExpr((LexicalUnitImpl) DeepCopy.copy(unit
-                                    .getNextLexicalUnit()));
-                            remainingNodes.remove(node);
-                            remainingUnits.remove(unit);
-                            break;
-                        }
-                    }
-                }
-            }
-
-            int i = 0;
-            for (final LexicalUnitImpl unit : remainingUnits) {
-                remainingNodes.get(i).setExpr(
-                        (LexicalUnitImpl) DeepCopy.copy(unit));
-                i++;
-            }
-
-        }
-
-    }
-
-    private void replaceChildVariables(MixinDefNode mixinDef, Node node) {
-        for (final Node child : node.getChildren()) {
-            replaceChildVariables(mixinDef, child);
-        }
-        if (node instanceof IVariableNode) {
-            ((IVariableNode) node).replaceVariables(mixinDef.getArglist());
-        }
-    }
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/NestPropertiesVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/NestPropertiesVisitor.java
deleted file mode 100644 (file)
index 82fbef4..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * 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 com.vaadin.sass.visitor;
-
-import java.util.ArrayList;
-
-import com.vaadin.sass.tree.NestPropertiesNode;
-import com.vaadin.sass.tree.Node;
-import com.vaadin.sass.tree.RuleNode;
-
-public class NestPropertiesVisitor implements Visitor {
-
-    @Override
-    public void traverse(Node node) {
-        for (Node child : new ArrayList<Node>(node.getChildren())) {
-            if (child instanceof NestPropertiesNode) {
-                Node previous = child;
-                for (RuleNode unNested : ((NestPropertiesNode) child)
-                        .unNesting()) {
-                    node.appendChild(unNested, previous);
-                    previous = unNested;
-                    node.removeChild(child);
-                }
-            } else {
-                traverse(child);
-            }
-        }
-    }
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/NestedNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/NestedNodeHandler.java
new file mode 100644 (file)
index 0000000..bb09488
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * 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 com.vaadin.sass.visitor;
+
+import com.vaadin.sass.tree.NestPropertiesNode;
+import com.vaadin.sass.tree.Node;
+import com.vaadin.sass.tree.RuleNode;
+
+public class NestedNodeHandler {
+
+    public static void traverse(NestPropertiesNode node) {
+        Node previous = node;
+        for (RuleNode unNested : node.unNesting()) {
+            node.getParentNode().appendChild(unNested, previous);
+            previous = unNested;
+        }
+        node.getParentNode().removeChild(node);
+    }
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorHandler.java
new file mode 100644 (file)
index 0000000..77e0bba
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * 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 com.vaadin.sass.visitor;
+
+import java.util.ArrayList;
+
+import com.google.gwt.dev.util.collect.HashMap;
+import com.vaadin.sass.tree.BlockNode;
+import com.vaadin.sass.tree.Node;
+
+public class ParentSelectorHandler {
+
+    private static HashMap<Node, Node> parentSelectors = new HashMap<Node, Node>();
+
+    public static void traverse(BlockNode block) throws Exception {
+        Node parentNode = block.getParentNode();
+        if (parentNode instanceof BlockNode) {
+            boolean isParentSelector = false;
+            ArrayList<String> newList = new ArrayList<String>(block
+                    .getSelectorList().size());
+            BlockNode parentBlock = (BlockNode) parentNode;
+            for (final String s : block.getSelectorList()) {
+
+                if (s.startsWith("&") || s.endsWith("&")) {
+                    for (final String parentSelector : parentBlock
+                            .getSelectorList()) {
+                        newList.add(s.replace("&", parentSelector));
+                        isParentSelector = true;
+                    }
+
+                }
+            }
+
+            if (isParentSelector) {
+                block.setSelectorList(newList);
+                Node oldparent = block.getParentNode();
+                if (parentSelectors.containsKey(block.getParentNode())) {
+                    block.getParentNode()
+                            .getParentNode()
+                            .appendChild(block,
+                                    parentSelectors.get(block.getParentNode()));
+                } else {
+                    block.getParentNode().getParentNode()
+                            .appendChild(block, block.getParentNode());
+                }
+
+                parentSelectors.put(oldparent, block);
+            }
+        }
+    }
+
+    public static void clear() {
+        parentSelectors.clear();
+    }
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/ParentSelectorVisitor.java
deleted file mode 100644 (file)
index f515d63..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * 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 com.vaadin.sass.visitor;
-
-import java.util.ArrayList;
-
-import com.vaadin.sass.tree.BlockNode;
-import com.vaadin.sass.tree.Node;
-
-public class ParentSelectorVisitor implements Visitor {
-
-    @Override
-    public void traverse(Node node) throws Exception {
-        for (Node child : new ArrayList<Node>(node.getChildren())) {
-            if (child instanceof BlockNode) {
-                traverse(node, (BlockNode) child);
-            }
-        }
-    }
-
-    private void traverse(Node parent, BlockNode block) throws Exception {
-        Node pre = block;
-        for (Node child : new ArrayList<Node>(block.getChildren())) {
-            if (child instanceof BlockNode) {
-                BlockNode blockChild = (BlockNode) child;
-                traverse(block, blockChild);
-                for (final String s : blockChild.getSelectorList()) {
-
-                    if (s.contains("&")) {
-                        parent.appendChild(child, pre);
-                        pre = child;
-                        block.removeChild(child);
-
-                        ArrayList<String> newList = new ArrayList<String>(block
-                                .getSelectorList().size());
-                        for (final String parentSelector : block
-                                .getSelectorList()) {
-                            newList.add(s.replace("&", parentSelector));
-                        }
-                        blockChild.setSelectorList(newList);
-                    }
-                }
-            }
-        }
-    }
-}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/VariableNodeHandler.java b/theme-compiler/src/com/vaadin/sass/visitor/VariableNodeHandler.java
new file mode 100644 (file)
index 0000000..3ea2643
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * 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 com.vaadin.sass.visitor;
+
+import com.vaadin.sass.ScssStylesheet;
+import com.vaadin.sass.tree.VariableNode;
+
+public class VariableNodeHandler {
+
+    public static void traverse(VariableNode node) {
+        if (ScssStylesheet.getVariable(node.getName()) == null
+                || !node.isGuarded()) {
+            ScssStylesheet.addVariable(node);
+        }
+        node.getParentNode().removeChild(node);
+    }
+
+}
diff --git a/theme-compiler/src/com/vaadin/sass/visitor/VariableVisitor.java b/theme-compiler/src/com/vaadin/sass/visitor/VariableVisitor.java
deleted file mode 100644 (file)
index c8e28cd..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * 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 com.vaadin.sass.visitor;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import com.vaadin.sass.tree.IVariableNode;
-import com.vaadin.sass.tree.ListModifyNode;
-import com.vaadin.sass.tree.Node;
-import com.vaadin.sass.tree.VariableNode;
-
-public class VariableVisitor implements Visitor {
-
-    private final HashMap<String, VariableNode> variables = new HashMap<String, VariableNode>();
-
-    @Override
-    public void traverse(Node node) {
-
-        replaceVariables(node, node.getChildren());
-
-        removeVariableNodes(node, node);
-    }
-
-    private void removeVariableNodes(Node parent, Node node) {
-        for (final Node child : new ArrayList<Node>(node.getChildren())) {
-            removeVariableNodes(node, child);
-        }
-        if (node instanceof VariableNode) {
-            for (final Node child : node.getChildren()) {
-                parent.appendChild(child, node);
-            }
-            parent.removeChild(node);
-        }
-    }
-
-    private void replaceVariables(Node n, ArrayList<Node> children) {
-
-        ArrayList<VariableNode> variables = new ArrayList<VariableNode>(
-                this.variables.values());
-
-        for (Node node : children) {
-
-            if (node instanceof IVariableNode) {
-                ((IVariableNode) node)
-                        .replaceVariables(new ArrayList<VariableNode>(
-                                this.variables.values()));
-            }
-
-            if (node instanceof VariableNode) {
-                VariableNode variableNode = (VariableNode) node;
-                if (this.variables.containsKey(variableNode.getName())
-                        && variableNode.isGuarded()) {
-                    continue;
-                }
-                this.variables.put(variableNode.getName(), variableNode);
-            } else if (node instanceof ListModifyNode) {
-
-                ListModifyNode modify = (ListModifyNode) node;
-
-                String variable = modify.getNewVariable().substring(1);
-
-                try {
-                    VariableNode modifiedList = modify.getModifiedList();
-
-                    this.variables.put(variable, modifiedList);
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-
-            replaceVariables(node, node.getChildren());
-        }
-
-        for (final VariableNode v : variables) {
-            this.variables.put(v.getName(), v);
-        }
-    }
-
-}
index 32f8484457aba1f6a64c3485075535fa97923361..0330782fbfcb7b1829b610443e63821c7da71df5 100644 (file)
@@ -25,4 +25,8 @@ body.firefox a {
 
 .mixin-parent:hover {
        color: blue;
+}
+
+.part.one, .part.two {
+       color: blue;
 }
\ No newline at end of file
index 32c3149a5bb96ab1a9d3e570a857ad7f8607ac66..96af1c78ff8aca886e6e08be371a3cc76618a8ab 100644 (file)
@@ -1,9 +1,13 @@
 $foo : red;
 
-.caption {
-       $side: right;
-       border: 1px solid black;
-       background: #ff0000;
-       padding: 10px;
-       margin: 10px;
-}
\ No newline at end of file
+@mixin caption {
+       .caption {
+               $side: right;
+               border: 1px solid black;
+               background: #ff0000;
+               padding: 10px;
+               margin: 10px;
+       }
+}
+
+@include caption;
\ No newline at end of file
index e1fa80f357dba101d8acea1ea75bb0d505ff0dba..61078971319cf5698a451b545479674327595af5 100644 (file)
@@ -71,7 +71,9 @@ $mixinVar : 1px;
        }
 }
 
-@include layout;
+$layoutVariable : layout;
+
+@include $layoutVariable;
 
 @mixin parent($color : green, $name : default) {
        .#{$name}-inner {
index 60e7608c079f3ae42807e8a21e4dca2245bc56c8..ee02f8bf769bc5522257563db2532d819856be49 100644 (file)
@@ -21,4 +21,10 @@ a {
 
 .mixin-parent {
        @include parent;
+}
+
+.part {
+       &.one, &.two {
+               color: blue;
+       }
 }
\ No newline at end of file
index 7f3b3d65515d2d7e63e5fff315f445c4f4dee337..e1e1fee3b4919eabfdc60f71fc0e462e8e295087 100644 (file)
@@ -18,8 +18,7 @@ package com.vaadin.sass.testcases.scss;
 
 import java.io.IOException;
 
-import junit.framework.Assert;
-
+import org.junit.Assert;
 import org.junit.Test;
 import org.w3c.css.sac.CSSException;
 
diff --git a/theme-compiler/tests/src/com/vaadin/sass/testcases/visitor/ImportVisitorTest.java b/theme-compiler/tests/src/com/vaadin/sass/testcases/visitor/ImportVisitorTest.java
deleted file mode 100644 (file)
index 8459139..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * 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 com.vaadin.sass.testcases.visitor;
-
-import org.junit.Test;
-
-public class ImportVisitorTest {
-    @Test
-    public void canHandleNestedImports() {
-    }
-}
diff --git a/theme-compiler/tests/src/com/vaadin/sass/testcases/visitor/MixinVisitorTest.java b/theme-compiler/tests/src/com/vaadin/sass/testcases/visitor/MixinVisitorTest.java
deleted file mode 100644 (file)
index 56a3580..0000000
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * 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 com.vaadin.sass.testcases.visitor;
-
-import java.util.ArrayList;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.vaadin.sass.ScssStylesheet;
-import com.vaadin.sass.parser.LexicalUnitImpl;
-import com.vaadin.sass.parser.SCSSLexicalUnit;
-import com.vaadin.sass.tree.BlockNode;
-import com.vaadin.sass.tree.MixinDefNode;
-import com.vaadin.sass.tree.MixinNode;
-import com.vaadin.sass.tree.RuleNode;
-import com.vaadin.sass.tree.VariableNode;
-import com.vaadin.sass.visitor.MixinVisitor;
-
-public class MixinVisitorTest {
-    private MixinVisitor mixinVisitor = new MixinVisitor();
-
-    @Test
-    public void testTraversMixinWithoutArgs() {
-        ScssStylesheet root = new ScssStylesheet();
-        MixinDefNode mixinDefNoArgs = new MixinDefNode("no-args", null);
-        BlockNode blockNode = new BlockNode(null);
-        mixinDefNoArgs.appendChild(blockNode);
-        root.appendChild(mixinDefNoArgs);
-
-        BlockNode blockWithMixin = new BlockNode(null);
-        MixinNode mixin = new MixinNode("no-args", null);
-        blockWithMixin.appendChild(mixin);
-        root.appendChild(blockWithMixin);
-
-        try {
-            mixinVisitor.traverse(root);
-        } catch (Exception e) {
-            Assert.fail(e.getMessage());
-        }
-
-        Assert.assertEquals(1, root.getChildren().size());
-        BlockNode child = (BlockNode) root.getChildren().get(0);
-        BlockNode fromMixin = (BlockNode) child.getChildren().get(0);
-        Assert.assertFalse(fromMixin.hasChildren());
-    }
-
-    @Test
-    public void testTraverseMixinWithNonDefaultArgs() {
-        ScssStylesheet root = new ScssStylesheet();
-        ArrayList<VariableNode> args = new ArrayList<VariableNode>();
-        args.add(new VariableNode("arg", null, false));
-        MixinDefNode mixinDefWithNonDefaultArg = new MixinDefNode(
-                "non-default-arg", args);
-        BlockNode blockNode = new BlockNode(null);
-        mixinDefWithNonDefaultArg.appendChild(blockNode);
-        root.appendChild(mixinDefWithNonDefaultArg);
-
-        BlockNode blockWithMixin = new BlockNode(null);
-        ArrayList<LexicalUnitImpl> includeArgs = new ArrayList<LexicalUnitImpl>();
-        LexicalUnitImpl includeArg = LexicalUnitImpl.createPixel(1f);
-        includeArg.setLexicalUnitType(LexicalUnitImpl.SAC_PIXEL);
-        includeArg.setFloatValue(1);
-        includeArgs.add(includeArg);
-        MixinNode mixin = new MixinNode("non-default-arg", includeArgs);
-        blockWithMixin.appendChild(mixin);
-        root.appendChild(blockWithMixin);
-
-        try {
-            mixinVisitor.traverse(root);
-        } catch (Exception e) {
-            Assert.fail(e.getMessage());
-        }
-
-        Assert.assertEquals(1, root.getChildren().size());
-        BlockNode child = (BlockNode) root.getChildren().get(0);
-        BlockNode fromMixin = (BlockNode) child.getChildren().get(0);
-        Assert.assertFalse(fromMixin.hasChildren());
-
-    }
-
-    @Test
-    public void testTraverseMixinWithDefaultArgs() {
-        ScssStylesheet root = new ScssStylesheet();
-        ArrayList<VariableNode> args = new ArrayList<VariableNode>();
-        LexicalUnitImpl includeArg = LexicalUnitImpl.createPixel(1f);
-        args.add(new VariableNode("arg", includeArg, false));
-        MixinDefNode mixinDefWithNonDefaultArg = new MixinDefNode(
-                "default-arg", args);
-        BlockNode blockNode = new BlockNode(null);
-        mixinDefWithNonDefaultArg.appendChild(blockNode);
-        root.appendChild(mixinDefWithNonDefaultArg);
-
-        BlockNode blockWithMixin = new BlockNode(null);
-        MixinNode mixin = new MixinNode("default-arg", null);
-        blockWithMixin.appendChild(mixin);
-        root.appendChild(blockWithMixin);
-
-        try {
-            mixinVisitor.traverse(root);
-        } catch (Exception e) {
-            Assert.fail(e.getMessage());
-        }
-
-        Assert.assertEquals(1, root.getChildren().size());
-        BlockNode child = (BlockNode) root.getChildren().get(0);
-        BlockNode fromMixin = (BlockNode) child.getChildren().get(0);
-        Assert.assertFalse(fromMixin.hasChildren());
-
-    }
-
-    @Test
-    public void testMixinWithoutArgument() {
-        /*
-         * ArrayList<String> args = new ArrayList<String>(); args.add("arg");
-         * MixinDefNode mixinDefWithArgs = new MixinDefNode("with-args", args);
-         * RuleNode ruleNode = new RuleNode("var",
-         * com.vaadin.sass.parser.LexicalUnitImpl.createVariable(0, 0, null,
-         * "arg"), false); mixinDefWithArgs.appendChild(ruleNode);
-         */
-        ScssStylesheet root = new ScssStylesheet();
-        MixinDefNode mixinDefNoArgs = new MixinDefNode("table-base", null);
-        BlockNode thBlockNode = new BlockNode(null);
-        RuleNode textAlignRuleNode = new RuleNode("text-align",
-                LexicalUnitImpl.createString("center"), false, null);
-        thBlockNode.appendChild(textAlignRuleNode);
-        RuleNode fontWeightRuleNode = new RuleNode("font-weight",
-                LexicalUnitImpl.createString("bold"), false, null);
-        thBlockNode.appendChild(fontWeightRuleNode);
-        mixinDefNoArgs.appendChild(thBlockNode);
-
-        BlockNode tdthBlockNode = new BlockNode(null);
-        RuleNode paddingRuleNode = new RuleNode("padding",
-                LexicalUnitImpl.createPixel(2f), false, null);
-        tdthBlockNode.appendChild(paddingRuleNode);
-        mixinDefNoArgs.appendChild(tdthBlockNode);
-        root.appendChild(mixinDefNoArgs);
-
-        BlockNode dataBlock = new BlockNode(null);
-        MixinNode mixinNode = new MixinNode("table-base", null);
-        dataBlock.appendChild(mixinNode);
-        root.appendChild(dataBlock);
-
-        try {
-            mixinVisitor.traverse(root);
-        } catch (Exception e) {
-            Assert.fail(e.getMessage());
-        }
-
-        Assert.assertEquals(1, root.getChildren().size());
-        dataBlock = (BlockNode) root.getChildren().get(0);
-        BlockNode thBlock = (BlockNode) dataBlock.getChildren().get(0);
-        Assert.assertEquals(2, thBlock.getChildren().size());
-        BlockNode thtdBlock = (BlockNode) dataBlock.getChildren().get(1);
-        Assert.assertEquals(1, thtdBlock.getChildren().size());
-
-        /*
-         * Assert.assertEquals(2, root.getChildren().size()); BlockNode
-         * datathBlockNode = (BlockNode) root.getChildren().get(0);
-         * Assert.assertEquals(LexicalUnit.SAC_IDENT, datathBlockNode
-         * .getSelectorList().item(0).getSelectorType());
-         * Assert.assertEquals("text-align", ((RuleNode) datathBlockNode
-         * .getChildren().get(0)).getVariable()); Assert.assertEquals("center",
-         * ((RuleNode) datathBlockNode.getChildren()
-         * .get(0)).getValue().getStringValue());
-         * Assert.assertEquals("font-weight", ((RuleNode) datathBlockNode
-         * .getChildren().get(1)).getVariable()); Assert.assertEquals("bold",
-         * ((RuleNode) datathBlockNode.getChildren()
-         * .get(1)).getValue().getStringValue());
-         * 
-         * BlockNode datathdatatdBlockNode = (BlockNode)
-         * root.getChildren().get(1); Assert.assertEquals(LexicalUnit.SAC_IDENT,
-         * datathdatatdBlockNode .getSelectorList().item(0).getSelectorType());
-         * Assert.assertEquals(LexicalUnit.SAC_IDENT, datathdatatdBlockNode
-         * .getSelectorList().item(1).getSelectorType());
-         * Assert.assertEquals("padding", ((RuleNode) datathdatatdBlockNode
-         * .getChildren().get(0)).getVariable()); Assert.assertEquals(2.0f,
-         * ((RuleNode) datathdatatdBlockNode
-         * .getChildren().get(0)).getValue().getFloatValue(), 0);
-         * Assert.assertEquals(LexicalUnit.SAC_PIXEL, ((RuleNode)
-         * datathdatatdBlockNode.getChildren().get(0))
-         * .getValue().getLexicalUnitType());
-         */
-
-    }
-
-    @Test
-    public void testMixinWithArgument() {
-        ScssStylesheet root = new ScssStylesheet();
-        ArrayList<VariableNode> argNameList = new ArrayList<VariableNode>();
-        argNameList.add(new VariableNode("dist", null, false));
-        MixinDefNode mixinDef = new MixinDefNode("left", argNameList);
-
-        RuleNode floatRuleNode = new RuleNode("float",
-                LexicalUnitImpl.createString("left"), false, null);
-        mixinDef.appendChild(floatRuleNode);
-        RuleNode marginLeftRuleNode = new RuleNode("margin-left",
-                com.vaadin.sass.parser.LexicalUnitImpl.createVariable(0, 0,
-                        null, "dist"), false, null);
-        mixinDef.appendChild(marginLeftRuleNode);
-        root.appendChild(mixinDef);
-
-        BlockNode dataBlock = new BlockNode(null);
-        ArrayList<LexicalUnitImpl> argValueList = new ArrayList<LexicalUnitImpl>();
-        LexicalUnitImpl arg = LexicalUnitImpl.createPixel(10f);
-        argValueList.add(arg);
-        MixinNode mixinNode = new MixinNode("left", argValueList);
-        dataBlock.appendChild(mixinNode);
-        root.appendChild(dataBlock);
-
-        try {
-            mixinVisitor.traverse(root);
-        } catch (Exception e) {
-            Assert.fail(e.getMessage());
-        }
-
-        Assert.assertEquals(1, root.getChildren().size());
-        BlockNode dataBlockNode = (BlockNode) root.getChildren().get(0);
-        Assert.assertEquals("float", ((RuleNode) dataBlockNode.getChildren()
-                .get(0)).getVariable());
-        Assert.assertEquals("left", ((RuleNode) dataBlockNode.getChildren()
-                .get(0)).getValue().getStringValue());
-        Assert.assertEquals("margin-left", ((RuleNode) dataBlockNode
-                .getChildren().get(1)).getVariable());
-        Assert.assertEquals(SCSSLexicalUnit.SAC_PIXEL,
-                ((RuleNode) dataBlockNode.getChildren().get(1)).getValue()
-                        .getLexicalUnitType());
-    }
-
-    @Test
-    public void testTopLevelInclude() {
-        ScssStylesheet root = new ScssStylesheet();
-
-        MixinDefNode defNode = new MixinDefNode("mixin", null);
-        defNode.appendChild(new RuleNode("var", null, false, null));
-        root.appendChild(defNode);
-
-        MixinNode mixinNode = new MixinNode("mixin", null);
-        root.appendChild(mixinNode);
-
-        try {
-            mixinVisitor.traverse(root);
-        } catch (Exception e) {
-            Assert.fail(e.getMessage());
-        }
-
-        Assert.assertEquals(1, root.getChildren().size());
-        RuleNode varRule = (RuleNode) root.getChildren().get(0);
-        Assert.assertEquals("var", varRule.getVariable());
-
-    }
-
-}
diff --git a/theme-compiler/tests/src/com/vaadin/sass/testcases/visitor/NestedPropertiesVisitorTest.java b/theme-compiler/tests/src/com/vaadin/sass/testcases/visitor/NestedPropertiesVisitorTest.java
deleted file mode 100644 (file)
index eafdb49..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- * 
- * 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 com.vaadin.sass.testcases.visitor;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.vaadin.sass.ScssStylesheet;
-import com.vaadin.sass.tree.NestPropertiesNode;
-import com.vaadin.sass.tree.RuleNode;
-import com.vaadin.sass.visitor.NestPropertiesVisitor;
-
-public class NestedPropertiesVisitorTest {
-    private NestPropertiesVisitor visitor = new NestPropertiesVisitor();
-
-    @Test
-    public void testEmptyTreeNoChange() {
-        ScssStylesheet root = new ScssStylesheet();
-        Assert.assertFalse(root.hasChildren());
-        visitor.traverse(root);
-        Assert.assertFalse(root.hasChildren());
-    }
-
-    @Test
-    public void testNestedPropertiesCanBeUnnested() {
-        ScssStylesheet root = new ScssStylesheet();
-        NestPropertiesNode nested = new NestPropertiesNode("nested");
-        RuleNode child0 = new RuleNode("child0", null, false, null);
-        RuleNode child1 = new RuleNode("child1", null, true, null);
-        nested.appendChild(child0);
-        nested.appendChild(child1);
-        root.appendChild(nested);
-
-        Assert.assertEquals(1, root.getChildren().size());
-        visitor.traverse(root);
-        Assert.assertEquals(2, root.getChildren().size());
-
-        for (int i = 0; i < root.getChildren().size(); i++) {
-            RuleNode node = (RuleNode) root.getChildren().get(i);
-            Assert.assertEquals("nested-child" + i, node.getVariable());
-        }
-    }
-}