Skip to content

Commit

Permalink
support a more flexible syntax for "!importan" of mixins. fix #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Horcrux7 committed Oct 25, 2015
1 parent 0b6f7d9 commit d28a21a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/com/inet/lib/less/Mixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,21 @@ class Mixin extends LessObject implements Formattable {
*/
Mixin( LessObject obj, String name, Operation paramValues, HashMultimap<String,Rule> mixins ) {
super( obj );
if( name.endsWith( "!important" ) ) {
important = true;
name = name.substring( 0, name.length() - 10 ).trim();
if( name.endsWith( "important" ) ) { // it can be "!importan" or "! important"
boolean importantTemp = false;
LOOP: for( int i = name.length() - 10; i >= 0; i-- ) {
switch( name.charAt( i ) ) {
case ' ':
break;
case '!':
importantTemp = true;
name = name.substring( 0, i ).trim();
break LOOP;
default:
break LOOP;
}
}
important = importantTemp;
} else {
important = false;
}
Expand Down
12 changes: 12 additions & 0 deletions test/com/inet/lib/less/samples/general/important.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@
color3: #777777 !important;
color4: #343434 !important;
}
.imp0 {
a: 0 !important;
}
.imp1 {
a: 1 !important;
}
.imp2 {
a: 2 !important;
}
.imp3 {
a: 3 !important;
}
24 changes: 24 additions & 0 deletions test/com/inet/lib/less/samples/general/important.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,27 @@
color3: #777777 ! important;
color4: #333 + 1 !important;
}

// import for mixins with different syntax

.imp0 {
.mixin! important;
}
.imp1 {
.mixin (1) !important;
}
.imp2 {
.mixin (2) ! important;
}

// ignore important in mixin name
.imp3 {
.mixin_important(3);
}

.mixin (@a:0) {
a:@a;
}
.mixin_important (@a) {
a:@a !important;
}

0 comments on commit d28a21a

Please sign in to comment.