From e781da64604db322e3c766413d6649fbf88af3cd Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Fri, 10 Aug 2012 15:10:08 +0300 Subject: Copy README file to SASS source tree (#9223) --- sass/README | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 sass/README (limited to 'sass') diff --git a/sass/README b/sass/README new file mode 100644 index 0000000000..4d9482763f --- /dev/null +++ b/sass/README @@ -0,0 +1,11 @@ +This project compiles SCSS into CSS. +It parses the SCSS into a tree. + +Classes +======= +SassCompiler: This is the main class that can be run from command line. First parameter is for a scss file to be compiled. Second parameter is optional and is a reference to a file where you want the compiled css. If file doesn't exist, it will be deleted. If file exists, it will be deleted and recreated. If second argument is left out, the css will be printed into standard out. +ScssStylesheet: When Scss/Css is parsed in, it will be represented in memory as this file. Reference is got through static get(File file) where file is input. +Parser: A JavaCC compiled java class that parses the input and notifies the DocumentHandler on what nodes it encounters. +Parser.jj: Source for the Parser class. +SCSSDocumentHandlerImpl: Class that takes in calls from parser and creates nodes into ScssStylesheet based on those calls. +Node package: All the nodes representing the Scss/Css in tree format \ No newline at end of file -- cgit v1.2.3 From cc13349d7c0526cfda81fb846b4565a2e7af5d76 Mon Sep 17 00:00:00 2001 From: Haijian Wang Date: Wed, 15 Aug 2012 12:42:08 +0300 Subject: Fix the File.separatorChar bug in ImportVisitor, replace it with '/' --- sass/src/com/vaadin/sass/visitor/ImportVisitor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sass') diff --git a/sass/src/com/vaadin/sass/visitor/ImportVisitor.java b/sass/src/com/vaadin/sass/visitor/ImportVisitor.java index 4dee49bc5c..2204ac7d71 100644 --- a/sass/src/com/vaadin/sass/visitor/ImportVisitor.java +++ b/sass/src/com/vaadin/sass/visitor/ImportVisitor.java @@ -61,7 +61,7 @@ public class ImportVisitor implements Visitor { if (url == null) { return null; } - int pos = url.lastIndexOf(File.separatorChar); + int pos = url.lastIndexOf('/'); if (pos == -1) { return null; } -- cgit v1.2.3 From 3d757bddfc2a07a77879fb3310e6dbbc49a1a079 Mon Sep 17 00:00:00 2001 From: Haijian Wang Date: Tue, 21 Aug 2012 12:41:52 +0300 Subject: fixed the hsl bug reported by Jouni, it is caused by the LexicalUnitImpl replace function and the updateVaule function in VariableVisitor --- .../com/vaadin/sass/parser/LexicalUnitImpl.java | 2 +- .../com/vaadin/sass/visitor/VariableVisitor.java | 31 +++++++++++++------ tests/sass/resources/css/var-guarded.css | 4 +++ tests/sass/resources/scss/var-guarded.scss | 8 +++++ .../sass/testcases/scss/VariableGuarded.java | 36 ++++++++++++++++++++++ 5 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 tests/sass/resources/css/var-guarded.css create mode 100644 tests/sass/resources/scss/var-guarded.scss create mode 100644 tests/sass/src/com/vaadin/sass/testcases/scss/VariableGuarded.java (limited to 'sass') diff --git a/sass/src/com/vaadin/sass/parser/LexicalUnitImpl.java b/sass/src/com/vaadin/sass/parser/LexicalUnitImpl.java index e268da8ed5..a6b03a864c 100644 --- a/sass/src/com/vaadin/sass/parser/LexicalUnitImpl.java +++ b/sass/src/com/vaadin/sass/parser/LexicalUnitImpl.java @@ -357,7 +357,7 @@ public class LexicalUnitImpl implements LexicalUnit, SCSSLexicalUnit, dimension = another.getDimension(); sdimension = another.getSdimension(); s = another.getStringValue(); - fname = getFunctionName(); + fname = another.getFunctionName(); params = another.getParameters(); prev = another.getPreviousLexicalUnit(); LexicalUnit finalNextInAnother = another; diff --git a/sass/src/com/vaadin/sass/visitor/VariableVisitor.java b/sass/src/com/vaadin/sass/visitor/VariableVisitor.java index bb790a0aee..eb2e6a0b83 100644 --- a/sass/src/com/vaadin/sass/visitor/VariableVisitor.java +++ b/sass/src/com/vaadin/sass/visitor/VariableVisitor.java @@ -28,13 +28,20 @@ public class VariableVisitor implements Visitor { private void traverse(Node node, Map variables) { if (node instanceof RuleNode) { LexicalUnit value = ((RuleNode) node).getValue(); - updateValue(value, variables); + while (updateValue(value, variables)) { + ; + } } else { Set toBeDeleted = new HashSet(); for (Node child : node.getChildren()) { if (child instanceof VariableNode) { - variables.put(((VariableNode) child).getName(), - (LexicalUnitImpl) ((VariableNode) child).getExpr()); + VariableNode varChild = (VariableNode) child; + if (!varChild.isGuarded() || varChild.isGuarded() + && variables.get(varChild.getName()) == null) { + variables.put(((VariableNode) child).getName(), + (LexicalUnitImpl) ((VariableNode) child) + .getExpr()); + } toBeDeleted.add(child); } else { traverse(child, new HashMap( @@ -47,17 +54,22 @@ public class VariableVisitor implements Visitor { } } - private void updateValue(LexicalUnit value, + private boolean updateValue(LexicalUnit value, Map variables) { + boolean onceMore = false; if (value == null) { - return; + return false; } if (value.getLexicalUnitType() == SCSSLexicalUnit.SCSS_VARIABLE) { - LexicalUnitImpl variableValue = variables.get( - value.getStringValue()).clone(); + LexicalUnitImpl variableValue = variables.get(value + .getStringValue()); if (variableValue != null) { - LexicalUnitImpl lexVal = (LexicalUnitImpl) value; - lexVal.replaceValue(variableValue); + LexicalUnitImpl variableValueCloned = variableValue.clone(); + if (variableValueCloned != null) { + LexicalUnitImpl lexVal = (LexicalUnitImpl) value; + lexVal.replaceValue(variableValueCloned); + onceMore = true; + } } } else if (value.getLexicalUnitType() == SCSSLexicalUnit.SAC_FUNCTION) { LexicalUnit params = value.getParameters(); @@ -65,5 +77,6 @@ public class VariableVisitor implements Visitor { } LexicalUnit next = value.getNextLexicalUnit(); updateValue(next, variables); + return onceMore; } } diff --git a/tests/sass/resources/css/var-guarded.css b/tests/sass/resources/css/var-guarded.css new file mode 100644 index 0000000000..c4a8c49d12 --- /dev/null +++ b/tests/sass/resources/css/var-guarded.css @@ -0,0 +1,4 @@ +#main { + content: "First content"; + new-content: "First time reference"; +} \ No newline at end of file diff --git a/tests/sass/resources/scss/var-guarded.scss b/tests/sass/resources/scss/var-guarded.scss new file mode 100644 index 0000000000..8f7aab8fa9 --- /dev/null +++ b/tests/sass/resources/scss/var-guarded.scss @@ -0,0 +1,8 @@ +$content: "First content"; +$content: "Second content?" !default; +$new_content: "First time reference" !default; + +#main { + content: $content; + new-content: $new_content; +} \ No newline at end of file diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/VariableGuarded.java b/tests/sass/src/com/vaadin/sass/testcases/scss/VariableGuarded.java new file mode 100644 index 0000000000..2c37737e69 --- /dev/null +++ b/tests/sass/src/com/vaadin/sass/testcases/scss/VariableGuarded.java @@ -0,0 +1,36 @@ +package com.vaadin.sass.testcases.scss; + +import java.io.IOException; + +import junit.framework.Assert; + +import org.junit.Test; +import org.w3c.css.sac.CSSException; + +import com.vaadin.sass.AbstractTestBase; +import com.vaadin.sass.ScssStylesheet; +import com.vaadin.sass.handler.SCSSDocumentHandler; +import com.vaadin.sass.handler.SCSSDocumentHandlerImpl; +import com.vaadin.sass.parser.Parser; + +public class VariableGuarded extends AbstractTestBase { + String scss = "/scss/var-guarded.scss"; + String css = "/css/var-guarded.css"; + + @Test + public void testParser() throws CSSException, IOException { + Parser parser = new Parser(); + SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl(); + parser.setDocumentHandler(handler); + parser.parseStyleSheet(getClass().getResource(scss).getPath()); + ScssStylesheet root = handler.getStyleSheet(); + Assert.assertEquals(4, root.getChildren().size()); + } + + @Test + public void testCompiler() throws Exception { + testCompiler(scss, css); + Assert.assertEquals("Original CSS and parsed CSS doesn't match", + comparisonCss, parsedScss); + } +} -- cgit v1.2.3