summaryrefslogtreecommitdiffstats
path: root/theme-compiler
diff options
context:
space:
mode:
authorMarc Englund <marc@vaadin.com>2012-11-27 09:37:19 +0000
committerVaadin Code Review <review@vaadin.com>2012-11-27 09:37:19 +0000
commit4436e3f3a565474723f8450fdd3ab285ae12040d (patch)
tree7a892939623993ce6a438ff277bcbb56efee7acd /theme-compiler
parent5df5c65fb412b9b94e2f8b8f465ec27d81ee7d8a (diff)
parent78bfb5cb1cc72164e73cf7919501fa22ba05445d (diff)
downloadvaadin-framework-4436e3f3a565474723f8450fdd3ab285ae12040d.tar.gz
vaadin-framework-4436e3f3a565474723f8450fdd3ab285ae12040d.zip
Merge "Keep block order when unnesting (#10309)"
Diffstat (limited to 'theme-compiler')
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java7
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/visitor/BlockNodeHandler.java13
-rw-r--r--theme-compiler/tests/resources/css/nesting.css8
-rw-r--r--theme-compiler/tests/resources/scss/nesting.scss12
-rw-r--r--theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Nesting.java4
5 files changed, 36 insertions, 8 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
index af061d8e95..2a5d617a6b 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
@@ -235,9 +235,14 @@ public class ScssStylesheet extends Node {
variables.clear();
variables.putAll(variableScope);
+ // clean up insert point so that processing of the next block will
+ // insert after that block
+ lastNodeAdded.remove(originalParent);
+
// has the node been removed from its parent?
if (originalParent != null) {
- return !originalParent.getChildren().contains(node);
+ boolean removed = !originalParent.getChildren().contains(node);
+ return removed;
} else {
return false;
}
diff --git a/theme-compiler/src/com/vaadin/sass/internal/visitor/BlockNodeHandler.java b/theme-compiler/src/com/vaadin/sass/internal/visitor/BlockNodeHandler.java
index cb736ba558..fc34e32f7a 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/visitor/BlockNodeHandler.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/visitor/BlockNodeHandler.java
@@ -98,14 +98,15 @@ public class BlockNodeHandler {
}
node.setSelectorList(newList);
Node oldParent = node.getParentNode();
+
HashMap<Node, Node> lastNodeAdded = ScssStylesheet.getLastNodeAdded();
- if (lastNodeAdded.get(oldParent) != null) {
- oldParent.getParentNode().appendChild(node,
- lastNodeAdded.get(oldParent));
- } else {
- oldParent.getParentNode().appendChild(node, oldParent);
+ Node lastAdded = lastNodeAdded.get(oldParent.getParentNode());
+ if (lastAdded == null) {
+ lastAdded = oldParent;
}
- lastNodeAdded.put(oldParent, node);
+ oldParent.getParentNode().appendChild(node, lastAdded);
+
+ lastNodeAdded.put(oldParent.getParentNode(), node);
}
}
diff --git a/theme-compiler/tests/resources/css/nesting.css b/theme-compiler/tests/resources/css/nesting.css
index b3861a0131..e1cdf3a579 100644
--- a/theme-compiler/tests/resources/css/nesting.css
+++ b/theme-compiler/tests/resources/css/nesting.css
@@ -44,4 +44,12 @@
.main .second.third .fourth {
color: black;
+}
+
+.root .first-block .nested {
+ order: first;
+}
+
+.root .last-block {
+ order: last;
} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/scss/nesting.scss b/theme-compiler/tests/resources/scss/nesting.scss
index 0336c9e86d..1fefe0dde0 100644
--- a/theme-compiler/tests/resources/scss/nesting.scss
+++ b/theme-compiler/tests/resources/scss/nesting.scss
@@ -37,4 +37,16 @@
color: black;
}
}
+}
+
+.root {
+ .first-block {
+ .nested {
+ order: first;
+ }
+ }
+
+ .last-block {
+ order: last;
+ }
} \ No newline at end of file
diff --git a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Nesting.java b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Nesting.java
index 109182f608..bdc6e63391 100644
--- a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Nesting.java
+++ b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Nesting.java
@@ -42,7 +42,7 @@ public class Nesting extends AbstractTestBase {
parser.setDocumentHandler(handler);
parser.parseStyleSheet(getClass().getResource(scss).getPath());
ScssStylesheet root = handler.getStyleSheet();
- Assert.assertEquals(5, root.getChildren().size());
+ Assert.assertEquals(6, root.getChildren().size());
BlockNode blockNode0 = (BlockNode) root.getChildren().get(0);
Assert.assertEquals(2, blockNode0.getChildren().size());
@@ -78,6 +78,8 @@ public class Nesting extends AbstractTestBase {
BlockNode nestednestedBlockInBlock4 = (BlockNode) nestedBlockInBlock3
.getChildren().get(1);
Assert.assertEquals(1, nestednestedBlockInBlock4.getChildren().size());
+
+ // the parsing of the last block is not checked in detail
}
@Test