Skip to content

Commit cb11777

Browse files
committed
implements function isDefined. see #84
1 parent ea384a4 commit cb11777

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public String unit( CssFormatter formatter ) {
137137
case "cos":
138138
case "tan":
139139
case "length":
140+
case "isdefined":
140141
return "";
141142
case "acos":
142143
case "asin":
@@ -288,6 +289,10 @@ public void appendTo( CssFormatter formatter ) {
288289
case "if":
289290
get( get( 0 ).booleanValue( formatter ) ? 1 : 2 ).appendTo( formatter );
290291
return;
292+
case "isdefined":
293+
Expression param = get( 0 );
294+
formatter.append( Boolean.toString( param instanceof VariableExpression ? formatter.getVariable( param.toString() ) != null : true ) );
295+
return;
291296
default:
292297
CustomLessFunction customLessFunction = Less.CUSTOM_FUNKTIONS.get( super.toString() );
293298
if( customLessFunction != null ) {
@@ -690,6 +695,11 @@ private void eval( CssFormatter formatter ) {
690695
booleanValue = false;
691696
}
692697
return;
698+
case "isdefined":
699+
type = BOOLEAN;
700+
param = get( 0 );
701+
booleanValue = param instanceof VariableExpression ? formatter.getVariable( param.toString() ) != null : true;
702+
return;
693703
case "ispixel":
694704
type = BOOLEAN;
695705
param = get( 0 );

test/com/inet/lib/less/samples/less_org_tests/less/functions.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@
137137
percent: true;
138138
em: true;
139139
cat: true;
140+
a: true;
141+
b: false;
142+
c: red;
143+
d: blue;
144+
f: true;
145+
g: red;
140146
}
141147
#alpha {
142148
alpha: rgba(153, 94, 51, 0.6);

test/com/inet/lib/less/samples/less_org_tests/less/functions.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@
147147
percent: ispercentage(32%);
148148
em: isem(32em);
149149
cat: isunit(32cat, cat);
150+
151+
@foo: 1;
152+
a:isdefined(@foo);
153+
b:isdefined(@bar);
154+
c:if(isdefined(@foo), red, blue);
155+
d:if(isdefined(@bar), red, blue);
156+
f:isdefined("hello");
157+
g:if(isdefined("hello"), red, blue);
150158
}
151159
}
152160

0 commit comments

Comments
 (0)