我正在尝试在less4j中使用自定义函数,这会返回用于css的常用路径:
com.github.sommeri.less4j.Less4jException: Could not compile less.
ERROR style.less 94:27 Unable to evaluate expression
details summary {
94: background-image: url(common()/img/ic_g_down.png);
95: background-position: left center;
功能是:
public class ConstantLessFunction implements LessFunction {
private static String fs[] = {
"common",
...
};
@Override
public boolean canEvaluate(
FunctionExpression call, List<Expression> parameters) {
return ArrayUtils.contains(fs, call.getName());
}
@Override
public Expression evaluate(
FunctionExpression call, List<Expression> parameters,
Expression evaluatedParameter, LessProblems problems) {
String name = call.getName();
switch (name) {
case "common":
return new IdentifierExpression(call.getUnderlyingStructure(), "/common/images/");
break;
...
}
}
由于wiki上的示例,我使用了IdentifierExpression。
也许是另一种方法,比如在java中将变量添加到编译器或类似的东西。
谢谢,Phaedra。