summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sass/src/com/vaadin/sass/util/ColorUtil.java33
-rw-r--r--sass/src/com/vaadin/sass/visitor/VariableVisitor.java29
-rw-r--r--tests/sass/resources/css/functions.css4
-rw-r--r--tests/sass/resources/css/variables.css1
-rw-r--r--tests/sass/resources/scss/variables.scss1
-rw-r--r--tests/sass/src/com/vaadin/sass/testcases/scss/Variables.java2
6 files changed, 47 insertions, 23 deletions
diff --git a/sass/src/com/vaadin/sass/util/ColorUtil.java b/sass/src/com/vaadin/sass/util/ColorUtil.java
index e65b3a80fa..9abcf57310 100644
--- a/sass/src/com/vaadin/sass/util/ColorUtil.java
+++ b/sass/src/com/vaadin/sass/util/ColorUtil.java
@@ -41,12 +41,12 @@ public class ColorUtil {
StringBuilder builder = new StringBuilder("#");
for (int i = 0; i < 3; i++) {
String color = Integer.toHexString(rgb[i]);
- if (lengh == 3) {
+ if (lengh == 6) {
if (color.length() == 1) {
color = "0" + color;
}
}
- if (lengh == 6) {
+ if (lengh == 3) {
color = color.substring(0, 1);
}
builder.append(color);
@@ -233,7 +233,7 @@ public class ColorUtil {
public static LexicalUnitImpl darken(LexicalUnitImpl darkenFunc) {
LexicalUnitImpl color = darkenFunc.getParameters();
- LexicalUnit amount = color.getNextLexicalUnit().getNextLexicalUnit();
+ float amount = getAmountValue(color);
LexicalUnitImpl pre = (LexicalUnitImpl) darkenFunc
.getPreviousLexicalUnit();
@@ -241,7 +241,7 @@ public class ColorUtil {
}
private static LexicalUnitImpl adjust(LexicalUnitImpl color,
- LexicalUnit amount, ColorOperation op, LexicalUnitImpl pre) {
+ float amountByPercent, ColorOperation op, LexicalUnitImpl pre) {
if (color.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION) {
LexicalUnit funcParam = color.getParameters();
if ("hsl".equals(color.getFunctionName())) {
@@ -251,12 +251,10 @@ public class ColorUtil {
}
float newValue = 0f;
if (op == ColorOperation.Darken) {
- newValue = lightness.getFloatValue()
- - amount.getFloatValue();
+ newValue = lightness.getFloatValue() - amountByPercent;
newValue = newValue < 0 ? 0 : newValue;
} else if (op == ColorOperation.Lighten) {
- newValue = lightness.getFloatValue()
- + amount.getFloatValue();
+ newValue = lightness.getFloatValue() + amountByPercent;
newValue = newValue > 100 ? 100 : newValue;
}
((LexicalUnitImpl) lightness).setFloatValue(newValue);
@@ -268,12 +266,13 @@ public class ColorUtil {
} else if (color.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
if (color.getStringValue().startsWith("#")) {
return hslToHexColor(
- adjust(hexColorToHsl(color), amount, op, pre), color
- .getStringValue().substring(1).length());
+ adjust(hexColorToHsl(color), amountByPercent, op, pre),
+ color.getStringValue().substring(1).length());
}
} else if (color.getLexicalUnitType() == LexicalUnit.SAC_RGBCOLOR) {
LexicalUnitImpl hsl = rgbToHsl(color);
- LexicalUnitImpl hslAfterDarken = adjust(hsl, amount, op, pre);
+ LexicalUnitImpl hslAfterDarken = adjust(hsl, amountByPercent, op,
+ pre);
return hslToRgb(hslAfterDarken);
}
return color;
@@ -281,13 +280,23 @@ public class ColorUtil {
public static LexicalUnitImpl lighten(LexicalUnitImpl lightenFunc) {
LexicalUnitImpl color = lightenFunc.getParameters();
- LexicalUnit amount = color.getNextLexicalUnit().getNextLexicalUnit();
+ float amount = getAmountValue(color);
LexicalUnitImpl pre = (LexicalUnitImpl) lightenFunc
.getPreviousLexicalUnit();
return adjust(color, amount, ColorOperation.Lighten, pre);
}
+ private static float getAmountValue(LexicalUnitImpl color) {
+ LexicalUnit next = color.getNextLexicalUnit();
+ float amount = 10f;
+ if (next != null && next.getNextLexicalUnit() != null) {
+ next = next.getNextLexicalUnit();
+ amount = next.getFloatValue();
+ }
+ return amount;
+ }
+
enum ColorOperation {
Darken, Lighten
}
diff --git a/sass/src/com/vaadin/sass/visitor/VariableVisitor.java b/sass/src/com/vaadin/sass/visitor/VariableVisitor.java
index 104b849780..8a567dacae 100644
--- a/sass/src/com/vaadin/sass/visitor/VariableVisitor.java
+++ b/sass/src/com/vaadin/sass/visitor/VariableVisitor.java
@@ -28,14 +28,7 @@ public class VariableVisitor implements Visitor {
private void traverse(Node node, Map<String, LexicalUnitImpl> variables) {
if (node instanceof RuleNode) {
LexicalUnit value = ((RuleNode) node).getValue();
- for (String variable : variables.keySet()) {
- if (value.getLexicalUnitType() == SCSSLexicalUnit.SCSS_VARIABLE) {
- if (value.getStringValue().contains(variable)) {
- LexicalUnitImpl lexVal = (LexicalUnitImpl) value;
- lexVal.replaceValue(variables.get(variable));
- }
- }
- }
+ updateValue(value, variables);
} else {
Set<Node> toBeDeleted = new HashSet<Node>();
for (Node child : node.getChildren()) {
@@ -53,4 +46,24 @@ public class VariableVisitor implements Visitor {
}
}
}
+
+ private void updateValue(LexicalUnit value,
+ Map<String, LexicalUnitImpl> variables) {
+ if (value == null) {
+ return;
+ }
+ for (String variable : variables.keySet()) {
+ if (value.getLexicalUnitType() == SCSSLexicalUnit.SCSS_VARIABLE) {
+ if (value.getStringValue().contains(variable)) {
+ LexicalUnitImpl lexVal = (LexicalUnitImpl) value;
+ lexVal.replaceValue(variables.get(variable));
+ }
+ } else if (value.getLexicalUnitType() == SCSSLexicalUnit.SAC_FUNCTION) {
+ LexicalUnit params = value.getParameters();
+ updateValue(params, variables);
+ }
+ }
+ LexicalUnit next = value.getNextLexicalUnit();
+ updateValue(next, variables);
+ }
}
diff --git a/tests/sass/resources/css/functions.css b/tests/sass/resources/css/functions.css
index 3757096667..de87462b46 100644
--- a/tests/sass/resources/css/functions.css
+++ b/tests/sass/resources/css/functions.css
@@ -7,8 +7,8 @@
color: hsl(25, 100%, 50%);
color: rgb(36, 0, 0);
color: rgb(240, 0, 0);
- color: #200;
color: #240000;
- color: #f00;
+ color: #200;
color: #f00000;
+ color: #f00;
}
diff --git a/tests/sass/resources/css/variables.css b/tests/sass/resources/css/variables.css
index 67ca5fdb7a..7c56a24c90 100644
--- a/tests/sass/resources/css/variables.css
+++ b/tests/sass/resources/css/variables.css
@@ -1,6 +1,7 @@
.content-navigation {
border-color: #3bbfce;
color: #0000ff;
+ color1: #cc0000;
font-family: Arial, Helvetica, "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana, sans-serif;
}
diff --git a/tests/sass/resources/scss/variables.scss b/tests/sass/resources/scss/variables.scss
index 2b39ef4a8d..3d9dada294 100644
--- a/tests/sass/resources/scss/variables.scss
+++ b/tests/sass/resources/scss/variables.scss
@@ -6,6 +6,7 @@ $chameleon-font-family: Arial, Helvetica, "Lucida Grande", "Lucida Sans Unicode"
border-color: $blue;
$blue: #0000ff;
color: $blue;
+ color1: darken($blue);
font-family: $chameleon-font-family;
}
diff --git a/tests/sass/src/com/vaadin/sass/testcases/scss/Variables.java b/tests/sass/src/com/vaadin/sass/testcases/scss/Variables.java
index 9b6a506890..61208229cf 100644
--- a/tests/sass/src/com/vaadin/sass/testcases/scss/Variables.java
+++ b/tests/sass/src/com/vaadin/sass/testcases/scss/Variables.java
@@ -48,7 +48,7 @@ public class Variables extends AbstractTestBase {
Assert.assertEquals("chameleon-font-family", varNode3.getName());
BlockNode blockNode1 = (BlockNode) root.getChildren().get(3);
- Assert.assertEquals(4, blockNode1.getChildren().size());
+ Assert.assertEquals(5, blockNode1.getChildren().size());
RuleNode ruleNode1Block1 = (RuleNode) blockNode1.getChildren().get(0);
Assert.assertEquals("border-color", ruleNode1Block1.getVariable());
Assert.assertEquals(SCSSLexicalUnit.SCSS_VARIABLE, ruleNode1Block1