Skip to content

Commit d28a21a

Browse files
committed
support a more flexible syntax for "!importan" of mixins. fix #18
1 parent 0b6f7d9 commit d28a21a

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

src/com/inet/lib/less/Mixin.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,21 @@ class Mixin extends LessObject implements Formattable {
5252
*/
5353
Mixin( LessObject obj, String name, Operation paramValues, HashMultimap<String,Rule> mixins ) {
5454
super( obj );
55-
if( name.endsWith( "!important" ) ) {
56-
important = true;
57-
name = name.substring( 0, name.length() - 10 ).trim();
55+
if( name.endsWith( "important" ) ) { // it can be "!importan" or "! important"
56+
boolean importantTemp = false;
57+
LOOP: for( int i = name.length() - 10; i >= 0; i-- ) {
58+
switch( name.charAt( i ) ) {
59+
case ' ':
60+
break;
61+
case '!':
62+
importantTemp = true;
63+
name = name.substring( 0, i ).trim();
64+
break LOOP;
65+
default:
66+
break LOOP;
67+
}
68+
}
69+
important = importantTemp;
5870
} else {
5971
important = false;
6072
}

test/com/inet/lib/less/samples/general/important.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,15 @@
44
color3: #777777 !important;
55
color4: #343434 !important;
66
}
7+
.imp0 {
8+
a: 0 !important;
9+
}
10+
.imp1 {
11+
a: 1 !important;
12+
}
13+
.imp2 {
14+
a: 2 !important;
15+
}
16+
.imp3 {
17+
a: 3 !important;
18+
}

test/com/inet/lib/less/samples/general/important.less

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,27 @@
44
color3: #777777 ! important;
55
color4: #333 + 1 !important;
66
}
7+
8+
// import for mixins with different syntax
9+
10+
.imp0 {
11+
.mixin! important;
12+
}
13+
.imp1 {
14+
.mixin (1) !important;
15+
}
16+
.imp2 {
17+
.mixin (2) ! important;
18+
}
19+
20+
// ignore important in mixin name
21+
.imp3 {
22+
.mixin_important(3);
23+
}
24+
25+
.mixin (@a:0) {
26+
a:@a;
27+
}
28+
.mixin_important (@a) {
29+
a:@a !important;
30+
}

0 commit comments

Comments
 (0)