aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordenisanisimov <denis@vaadin.com>2014-02-10 11:33:55 +0200
committerDenis Anisimov <denis@vaadin.com>2014-02-13 16:00:16 +0200
commit853d42a08bfdbad030eb728b296c930176bbe2bd (patch)
tree67d11cfe0dd212a93d3a744724c55212c23eb885
parent675d387348e90c525dec1eaeb7fee288728af9f0 (diff)
downloadvaadin-framework-853d42a08bfdbad030eb728b296c930176bbe2bd.tar.gz
vaadin-framework-853d42a08bfdbad030eb728b296c930176bbe2bd.zip
Function "percentage" is implemented (#12771).
Change-Id: I0a2e3d31f60bd085d619b603bd229dba902ff001
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/parser/LexicalUnitImpl.java40
-rw-r--r--theme-compiler/tests/resources/css/functions.css4
-rw-r--r--theme-compiler/tests/resources/scss/functions.scss4
-rw-r--r--theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Functions.java2
4 files changed, 47 insertions, 3 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/internal/parser/LexicalUnitImpl.java b/theme-compiler/src/com/vaadin/sass/internal/parser/LexicalUnitImpl.java
index 96f841de0b..09fcdee7c0 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/parser/LexicalUnitImpl.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/parser/LexicalUnitImpl.java
@@ -52,6 +52,9 @@ public class LexicalUnitImpl implements LexicalUnit, SCSSLexicalUnit,
Serializable {
private static final long serialVersionUID = -6649833716809789399L;
+ private static int PRECISION = 100000;
+ private static int PERC_PRECISION_FACTOR = 100 * PRECISION;
+
LexicalUnitImpl prev;
LexicalUnitImpl next;
@@ -788,9 +791,46 @@ public class LexicalUnitImpl implements LexicalUnit, SCSSLexicalUnit,
list.add(new FloorFunctionGenerator());
list.add(new LightenFunctionGenerator());
list.add(new RoundFunctionGenerator());
+ list.add(new PercentageFunctionGenerator());
return list;
}
+ private static class PercentageFunctionGenerator implements
+ SCSSFunctionGenerator {
+
+ @Override
+ public String getFunctionName() {
+ return "percentage";
+ }
+
+ @Override
+ public String printState(LexicalUnitImpl function) {
+ StringBuilder builder = new StringBuilder();
+ LexicalUnitImpl firstParam = function.getParameters();
+ float value = firstParam.getFloatValue();
+ value *= PERC_PRECISION_FACTOR;
+ int intValue = Math.round(value);
+ value = ((float) intValue) / PRECISION;
+
+ int resultIntValue = (int) value;
+
+ firstParam.type = SAC_PERCENTAGE;
+
+ if (intValue == resultIntValue * PRECISION) {
+ builder.append(resultIntValue);
+ firstParam.setIntegerValue(resultIntValue);
+ } else {
+ builder.append(value);
+ firstParam.setFloatValue(value);
+ }
+
+ firstParam.setStringValue(builder.append('%').toString());
+
+ return firstParam.toString();
+ }
+
+ }
+
private static final Map<String, SCSSFunctionGenerator> SERIALIZERS = new HashMap<String, SCSSFunctionGenerator>();
private static final SCSSFunctionGenerator DEFAULT_SERIALIZER = new DefaultFunctionGenerator();
diff --git a/theme-compiler/tests/resources/css/functions.css b/theme-compiler/tests/resources/css/functions.css
index 45d42b34de..0a8fcbf5a8 100644
--- a/theme-compiler/tests/resources/css/functions.css
+++ b/theme-compiler/tests/resources/css/functions.css
@@ -14,4 +14,6 @@
color: hsl(33, 7%, 89%);
color: hsl(33, 7%, 95%);
color: rgb(1, 2, 3);
-} \ No newline at end of file
+ percents: -20%;
+ percents: 33.33%;
+}
diff --git a/theme-compiler/tests/resources/scss/functions.scss b/theme-compiler/tests/resources/scss/functions.scss
index 4230850b2a..8638d0afaa 100644
--- a/theme-compiler/tests/resources/scss/functions.scss
+++ b/theme-compiler/tests/resources/scss/functions.scss
@@ -19,4 +19,6 @@ $blue:3;
color : $base-color;
color : $app-bg-color;
color: rgb($red, $green, $blue);
-} \ No newline at end of file
+ percents: percentage(-0.2);
+ percents: percentage(0.3333);
+}
diff --git a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Functions.java b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Functions.java
index b50172ac2f..bd214986c0 100644
--- a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Functions.java
+++ b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Functions.java
@@ -43,7 +43,7 @@ public class Functions extends AbstractTestBase {
ScssStylesheet root = handler.getStyleSheet();
Assert.assertEquals(6, root.getChildren().size());
BlockNode blockNode = (BlockNode) root.getChildren().get(5);
- Assert.assertEquals(15, blockNode.getChildren().size());
+ Assert.assertEquals(17, blockNode.getChildren().size());
}
@Test