Browse Source

Support non-trivial SASS media selectors (#11455)

This change adds support for media selectors with a query that consist
of more than just a single word.

Change-Id: Id6a09de8e88984ad052321ae93ffa2e7c2ba1c04
tags/7.0.6
Henri Sara 11 years ago
parent
commit
a52ceb9659

+ 1005
- 1025
theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java
File diff suppressed because it is too large
View File


+ 28
- 6
theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj View File

@@ -823,7 +823,7 @@ void importDeclaration() :
}
}
)
( <S> )* ( mediaStatement(ml) )? ";"
( <S> )* mediaStatement(ml) ";"
( <S> )*
{
if (ml.getLength() == 0) {
@@ -903,6 +903,7 @@ void keyframeSelector():
/**
* @exception ParseException exception during the parse
*/
/* see http://www.w3.org/TR/css3-mediaqueries/ */
void media() :
{
boolean start = false;
@@ -927,12 +928,33 @@ void media() :
}

void mediaStatement(MediaListImpl ml) :
{
String m;
{
Token t;
}
{
m=medium() ( <COMMA> ( <S> )* { ml.addItem(m); } m=medium() )*
{ ml.addItem(m); }
{
t = getToken(1);
// loop over comma separated parts, add each to ml
while ((t.kind != LBRACE) && (t.kind != EOF) && (t.kind != SEMICOLON)) {
StringBuffer s = new StringBuffer();
s.append(getToken(0).image);
while ((t.kind != COMMA) && (t.kind != LBRACE) && (t.kind != EOF) && (t.kind != SEMICOLON)) {
s.append(t.image);
getNextToken();
t = getToken(1);
}
if (t.kind == COMMA) {
// skip the comma and the token before it that is still the active token
getNextToken();
getNextToken();
t = getToken(1);
}
String str = s.toString().trim();
if (str.length() > 0) {
ml.addItem(str);
}
}
}
}

/**
@@ -941,7 +963,7 @@ void mediaStatement(MediaListImpl ml) :
String medium() : /* tv, projection, screen, ... */
{Token n;}
{
n=<IDENT> ( <S> )* { return convertIdent(n.image); }
n=<IDENT> { return convertIdent(n.image); }
}

/**

+ 3
- 0
theme-compiler/src/com/vaadin/sass/internal/tree/MediaNode.java View File

@@ -41,6 +41,9 @@ public class MediaNode extends Node {
StringBuilder builder = new StringBuilder("@media ");
if (media != null) {
for (int i = 0; i < media.getLength(); i++) {
if (i > 0) {
builder.append(", ");
}
builder.append(media.item(i));
}
}

+ 1
- 0
theme-compiler/tests/resources/automatic/css/media-import.css View File

@@ -0,0 +1 @@
@import url(color.css) screen and (color);

+ 10
- 0
theme-compiler/tests/resources/automatic/css/media-multiple.css View File

@@ -0,0 +1,10 @@
@media print, screen {
a {
b: c;
}
}
@media all and (max-width: 699px) and (min-width: 520px), (min-width: 1151px) {
body {
background: #ccc;
}
}

+ 5
- 0
theme-compiler/tests/resources/automatic/css/media.css View File

@@ -0,0 +1,5 @@
@media screen and (max-width: 480px) {
.abc {
background: red;
}
}

+ 1
- 0
theme-compiler/tests/resources/automatic/scss/media-import.scss View File

@@ -0,0 +1 @@
@import url(color.css) screen and (color);

+ 10
- 0
theme-compiler/tests/resources/automatic/scss/media-multiple.scss View File

@@ -0,0 +1,10 @@
@media print, screen {
a {
b: c;
}
}
@media all and (max-width: 699px) and (min-width: 520px), (min-width: 1151px) {
body {
background: #ccc;
}
}

+ 5
- 0
theme-compiler/tests/resources/automatic/scss/media.scss View File

@@ -0,0 +1,5 @@
@media screen and (max-width: 480px) {
.abc {
background: red;
}
}

Loading…
Cancel
Save