summaryrefslogtreecommitdiffstats
path: root/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java
diff options
context:
space:
mode:
authorSebastian Nyholm <sebastian@vaadin.com>2012-10-22 11:11:04 +0300
committerSebastian Nyholm <sebastian@vaadin.com>2012-11-08 17:16:10 +0200
commita0da163fd5c23f1d961fc5c686efd6ffc50ecd61 (patch)
tree093e40a12de854d48920335b67b08144b98556bf /theme-compiler/src/com/vaadin/sass/ScssStylesheet.java
parente8ae9f7d6427f7f6daae300dee7931a6e8394bdb (diff)
downloadvaadin-framework-a0da163fd5c23f1d961fc5c686efd6ffc50ecd61.tar.gz
vaadin-framework-a0da163fd5c23f1d961fc5c686efd6ffc50ecd61.zip
Fixes #9546, #9974, #10100, #10105
Change-Id: I1baccb5604899707960b1cf06887ada0fe217d08
Diffstat (limited to 'theme-compiler/src/com/vaadin/sass/ScssStylesheet.java')
-rw-r--r--theme-compiler/src/com/vaadin/sass/ScssStylesheet.java126
1 files changed, 101 insertions, 25 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java b/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java
index d0b4b732ea..45578deb19 100644
--- a/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java
+++ b/theme-compiler/src/com/vaadin/sass/ScssStylesheet.java
@@ -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;
+ }
+
}