You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Less4j-javascript adds embedded/escaped JavaScript support to less4j. Embedded/escaped javascript is javascript placed inside less file and allows otherwise impossible calculations and logic. Embedded javascript is closed inside ticks `JavaScript` and escaped JavaScript is the same preceded by tilde ~ e.g. ~`JavaScript`.
Example less:
@number: 100;
@content: "less symbol is < and more symbol is >";
.logaritmic-thing {
// escaped JavaScript - calculate logarithm
margin: ~`Math.round(Math.log(@{number})*100)/100`;
// embedded JavaScript - escape < and > characters
content: `@{content}.replace(/</g, '<').replace(/>/g, '>')`;
}
compiles into:
.logaritmic-thing {
margin: 4.61;
content: "less symbol is < and more symbol is >";
}
The configure method of Less4jJavascript configures less4j to use embedded JavaScript:
//create new less4j configuration objectConfigurationconfiguration = newConfiguration()
//add embedded javascript support into itLess4jJavascript.configure(configuration);
//compile files with embedded javascriptLessCompilercompiler = newDefaultLessCompiler();
CompilationResultresult = compiler.compile(newFile(less), configuration);
Compatibility
Less4j-javascript is supposed to be close enough to less.js to compile LessHat the same way. However, it does not have to behave exactly the same way in all circumstances. Most important differences are:
environment,
less scope accessibility.
Environment: Less.js runs either on node.js or inside a browser while less4j JavaScript runs in Rhino. Global variables and functions available only in node.js or browser are not available in Rhino. Following will not work:
title: `typeof process.title`; // accessing node.js global variable
Scope: Less.js allows access to local scope using this.variablename trick. Less4j JavaScript does not support the same. Following will NOT work: