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;
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
*
* @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);
}
+
}
/**
}
}
+ 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;
+ }
+
}
*/
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;
case IDENT:
name = property();
break;
+ case VARIABLE:
+ name = variableName();
+ name = "$"+name;
+ break;
+ case INTERPOLATION:
+ name = interpolation();
+ break;
case FUNCTION:
name = functionName();
args = argValuelist();
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();
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
}
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;
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;
}
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;
}
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;
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;
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;
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;
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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,};
{
<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{
}
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;
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();
+ }
}
}
public String toString() {
return comment;
}
+
+ @Override
+ public void traverse() {
+ // Not used in CommentNode
+ }
}
import java.util.ArrayList;
+import com.vaadin.sass.visitor.ExtendNodeHandler;
+
public class ExtendNode extends Node implements IVariableNode {
private static final long serialVersionUID = 3301805078983796878L;
return b.toString();
}
+
+ @Override
+ public void traverse() {
+ try {
+ ExtendNodeHandler.traverse(this);
+ getParentNode().removeChild(this);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
return builder.toString();
}
+ @Override
+ public void traverse() {
+ // Not in use for FontFaceNode
+ }
+
}
+ to + ", exclusive: " + exclusive + ", body" + body;
}
+ @Override
+ public void traverse() {
+
+ }
+
}
import java.util.ArrayList;
+import com.vaadin.sass.ScssStylesheet;
+
public class FunctionNode extends Node implements IVariableNode {
private static final long serialVersionUID = -5383104165955523923L;
}
}
}
+
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ }
}
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;
public SACMediaList getMl() {
return ml;
}
+
+ @Override
+ public void traverse() {
+ // TODO shouldn't be reached with current setup, try anyway?
+ ImportNodeHandler.traverse((ScssStylesheet) getParentNode());
+ }
}
+++ /dev/null
-package com.vaadin.sass.tree;
-
-public interface InterpolationNode {
- public void replaceInterpolation(String variableName, String variable);
-
- public boolean containsInterpolationVariable(String variable);
-}
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 {
}
}
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ ScssStylesheet.addVariable(getModifiedList());
+ getParentNode().removeChild(this);
+ }
+
}
import java.util.ArrayList;
-import com.vaadin.sass.parser.LexicalUnitImpl;
-
public class ListRemoveNode extends ListModifyNode {
public ListRemoveNode(String variable, String list, String remove,
}
- 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);
}
+
}
return builder.toString();
}
+ @Override
+ public void traverse() {
+
+ }
+
}
import java.util.ArrayList;
+import com.vaadin.sass.ScssStylesheet;
+
public class MicrosoftRuleNode extends Node implements IVariableNode {
private final String name;
public String toString() {
return name + ": " + value + ";";
}
+
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ }
}
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 {
}
}
+ @Override
+ public void traverse() {
+ if (!arglist.isEmpty()) {
+ for (final VariableNode arg : arglist) {
+ if (arg.getExpr() != null) {
+ ScssStylesheet.addVariable(arg);
+ }
+ }
+ }
+ }
+
}
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;
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();
}
}
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;
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;
}
}
}
}
+
+ @Override
+ public void traverse() {
+ NestedNodeHandler.traverse(this);
+ }
+
}
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);
}
}
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");
}
public void removeChild(Node node) {
if (node != null) {
- children.remove(node);
+ boolean removed = children.remove(node);
+ if (removed) {
+ node.setParentNode(null);
+ }
}
}
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;
}
}
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;
@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) {
}
@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());
}
}
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
}
}
}
+
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ }
}
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;
unit = unit.getNextLexicalUnit();
}
}
+
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ VariableNodeHandler.traverse(this);
+ }
}
return "While Node: { condition: " + condition + ", body:" + body + "}";
}
+ @Override
+ public void traverse() {
+
+ }
+
}
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;
public String getListVariable() {
return listVariable;
}
+
+ @Override
+ public void traverse() {
+ replaceVariables(ScssStylesheet.getVariables());
+ EachNodeHandler.traverse(this);
+ }
}
return null;
}
+ @Override
+ public void traverse() {
+
+ }
+
}
package com.vaadin.sass.tree.controldirective;
import com.vaadin.sass.tree.Node;
+import com.vaadin.sass.visitor.IfElseNodeHandler;
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();
+ }
+ }
+
}
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;
@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
--- /dev/null
+/*
+ * 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());
+ }
+}
+++ /dev/null
-/*
- * 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);
- }
- }
-}
--- /dev/null
+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);
+ }
+
+ }
+
+}
+++ /dev/null
-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);
- }
-
-}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+ }
+ }
+}
+++ /dev/null
-/*
- * 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);
- }
- }
- }
- }
-}
--- /dev/null
+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);
+ }
+ }
+}
+++ /dev/null
-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);
- }
- }
- }
-}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
+++ /dev/null
-/*
- * 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);
- }
- }
-}
+++ /dev/null
-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);
- }
-
- }
-}
--- /dev/null
+/*
+ * 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());
+ }
+ }
+}
+++ /dev/null
-/*
- * 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());
- }
- }
-}
+++ /dev/null
-/*
- * 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);
- }
- }
- }
-}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
+++ /dev/null
-/*
- * 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);
- }
- }
- }
- }
- }
-}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
+++ /dev/null
-/*
- * 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);
- }
- }
-
-}
.mixin-parent:hover {
color: blue;
+}
+
+.part.one, .part.two {
+ color: blue;
}
\ No newline at end of file
$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
}
}
-@include layout;
+$layoutVariable : layout;
+
+@include $layoutVariable;
@mixin parent($color : green, $name : default) {
.#{$name}-inner {
.mixin-parent {
@include parent;
+}
+
+.part {
+ &.one, &.two {
+ color: blue;
+ }
}
\ No newline at end of file
import java.io.IOException;
-import junit.framework.Assert;
-
+import org.junit.Assert;
import org.junit.Test;
import org.w3c.css.sac.CSSException;
+++ /dev/null
-/*
- * 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() {
- }
-}
+++ /dev/null
-/*
- * 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());
-
- }
-
-}
+++ /dev/null
-/*
- * 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());
- }
- }
-}