diff options
author | Artur Signell <artur@vaadin.com> | 2013-10-15 22:50:47 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-10-16 09:32:54 +0000 |
commit | 39fdf66c3a2fb4033306ace1b7cbdaff0b63d882 (patch) | |
tree | b0f8a6966224fa0abde32d7a897567d1123e50b0 | |
parent | 7c12694e047c42bf5f2ab189512e3346541e9c51 (diff) | |
download | vaadin-framework-39fdf66c3a2fb4033306ace1b7cbdaff0b63d882.tar.gz vaadin-framework-39fdf66c3a2fb4033306ace1b7cbdaff0b63d882.zip |
Handle numbers in the same way if they do not have a unit (#12732)
Change-Id: Ic9dba337ffb209bf73ab427fa3a39e542e645c08
9 files changed, 106 insertions, 8 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 498e1a941b..af94de0f46 100644 --- a/theme-compiler/src/com/vaadin/sass/internal/parser/LexicalUnitImpl.java +++ b/theme-compiler/src/com/vaadin/sass/internal/parser/LexicalUnitImpl.java @@ -148,6 +148,22 @@ public class LexicalUnitImpl implements LexicalUnit, SCSSLexicalUnit, return f; } + /** + * Returns the float value as a string unless the value is an integer. In + * that case returns the integer value as a string. + * + * @return a string representing the value, either with or without decimals + */ + public String getFloatOrInteger() { + float f = getFloatValue(); + int i = (int) f; + if ((i) == f) { + return i + ""; + } else { + return f + ""; + } + } + public void setFloatValue(float f) { this.f = f; i = (int) f; @@ -274,7 +290,7 @@ public class LexicalUnitImpl implements LexicalUnit, SCSSLexicalUnit, text = Integer.toString(getIntegerValue(), 10); break; case LexicalUnit.SAC_REAL: - text = getFloatValue() + ""; + text = getFloatOrInteger(); break; case LexicalUnit.SAC_EM: case SCSSLexicalUnit.SAC_LEM: @@ -295,13 +311,7 @@ public class LexicalUnitImpl implements LexicalUnit, SCSSLexicalUnit, case LexicalUnit.SAC_HERTZ: case LexicalUnit.SAC_KILOHERTZ: case LexicalUnit.SAC_DIMENSION: - float f = getFloatValue(); - int i = (int) f; - if ((i) == f) { - text = i + getDimensionUnitText(); - } else { - text = f + getDimensionUnitText(); - } + text = getFloatOrInteger() + getDimensionUnitText(); break; case LexicalUnit.SAC_URI: text = "url(" + getStringValue() + ")"; diff --git a/theme-compiler/tests/resources/automatic/css/functions/abs.css b/theme-compiler/tests/resources/automatic/css/functions/abs.css new file mode 100644 index 0000000000..3c43804a13 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/css/functions/abs.css @@ -0,0 +1,11 @@ +.foo { + a: 0; + b: 12.51; + c: 1.1px; + d: 12; + e: 12px; + f: 12.9999; + g: 12.9999em; + h: 13.0001; + i: 13.0001%; +}
\ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/css/functions/ceil.css b/theme-compiler/tests/resources/automatic/css/functions/ceil.css new file mode 100644 index 0000000000..9956ff3612 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/css/functions/ceil.css @@ -0,0 +1,11 @@ +.foo { + a: 0; + b: -12; + c: -1px; + d: 12; + e: 12px; + f: 13; + g: 13em; + h: 14; + i: 14%; +}
\ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/css/functions/floor.css b/theme-compiler/tests/resources/automatic/css/functions/floor.css new file mode 100644 index 0000000000..f96e99d809 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/css/functions/floor.css @@ -0,0 +1,11 @@ +.foo { + a: 0; + b: -13; + c: -2px; + d: 12; + e: 12px; + f: 12; + g: 12em; + h: 13; + i: 13%; +}
\ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/css/functions/round.css b/theme-compiler/tests/resources/automatic/css/functions/round.css new file mode 100644 index 0000000000..72d9a8596d --- /dev/null +++ b/theme-compiler/tests/resources/automatic/css/functions/round.css @@ -0,0 +1,11 @@ +.foo { + a: 0; + b: -13; + c: -1px; + d: 12; + e: 12px; + f: 13; + g: 13em; + h: 13; + i: 13%; +}
\ No newline at end of file diff --git a/theme-compiler/tests/resources/automatic/scss/functions/abs.scss b/theme-compiler/tests/resources/automatic/scss/functions/abs.scss new file mode 100644 index 0000000000..91946f0556 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/scss/functions/abs.scss @@ -0,0 +1,11 @@ +.foo { +a: abs(0); +b: abs(-12.51); +c: abs(-1.1px); +d: abs(12); +e: abs(12px); +f: abs(12.9999); +g: abs(12.9999em); +h: abs(-13.0001); +i: abs(-13.0001%); +} diff --git a/theme-compiler/tests/resources/automatic/scss/functions/ceil.scss b/theme-compiler/tests/resources/automatic/scss/functions/ceil.scss new file mode 100644 index 0000000000..ad7ceed4b4 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/scss/functions/ceil.scss @@ -0,0 +1,11 @@ +.foo { +a: ceil(0); +b: ceil(-12.51); +c: ceil(-1.1px); +d: ceil(12); +e: ceil(12px); +f: ceil(12.9999); +g: ceil(12.9999em); +h: ceil(13.000001); +i: ceil(13.000001%); +} diff --git a/theme-compiler/tests/resources/automatic/scss/functions/floor.scss b/theme-compiler/tests/resources/automatic/scss/functions/floor.scss new file mode 100644 index 0000000000..a10f1b4fc1 --- /dev/null +++ b/theme-compiler/tests/resources/automatic/scss/functions/floor.scss @@ -0,0 +1,11 @@ +.foo { +a: floor(0); +b: floor(-12.51); +c: floor(-1.1px); +d: floor(12); +e: floor(12px); +f: floor(12.9999); +g: floor(12.9999em); +h: floor(13.000001); +i: floor(13.000001%); +} diff --git a/theme-compiler/tests/resources/automatic/scss/functions/round.scss b/theme-compiler/tests/resources/automatic/scss/functions/round.scss new file mode 100644 index 0000000000..3f1fa06aec --- /dev/null +++ b/theme-compiler/tests/resources/automatic/scss/functions/round.scss @@ -0,0 +1,11 @@ +.foo { +a: round(0); +b: round(-12.51); +c: round(-1.1px); +d: round(12); +e: round(12px); +f: round(12.9999); +g: round(12.9999em); +h: round(13.000001); +i: round(13.000001%); +} |