public class LessCompiler extends Object implements AutoCloseable
The compiler uses Rhino (JavaScript implementation written in Java), Envjs
(simulated browser environment written in JavaScript), and the official LESS
JavaScript compiler.
Note that the compiler is not a Java implementation of LESS itself, but rather
integrates the LESS JavaScript compiler within a Java/JavaScript browser
environment provided by Rhino and Envjs.
The compiler comes bundled with the Envjs and LESS JavaScript, so there is no need to include them yourself. But if needed they can be overridden.
Basic code example:LessCompiler lessCompiler = new LessCompiler(); String css = lessCompiler.compile("@color: #4D926F; #header { color: @color; }");
Constructor and Description |
---|
LessCompiler()
Constructs a new
LessCompiler . |
Modifier and Type | Method and Description |
---|---|
void |
close() |
String |
compile(File input)
Compiles the LESS input
File to CSS. |
void |
compile(File input,
File output)
Compiles the LESS input
File to CSS and writes it to the specified output File . |
void |
compile(File input,
File output,
boolean force)
Compiles the LESS input
File to CSS and writes it to the specified output File . |
String |
compile(LessSource input)
Compiles the input
LessSource to CSS. |
void |
compile(LessSource input,
File output)
Compiles the input
LessSource to CSS and writes it to the specified output File . |
void |
compile(LessSource input,
File output,
boolean force)
Compiles the input
LessSource to CSS and writes it to the specified output File . |
String |
compile(String input)
Compiles the LESS input
String to CSS. |
List<URL> |
getCustomJs()
Returns the custom JavaScript files used by the compiler.
|
String |
getEncoding()
Returns the character encoding used by the compiler when writing the output
File . |
URL |
getEnvJs()
Returns the Envjs JavaScript file used by the compiler.
|
URL |
getLessJs()
Returns the LESS JavaScript file used by the compiler.
|
boolean |
isCompress()
Returns whether the compiler will compress the CSS.
|
void |
setCompress(boolean compress)
Sets the compiler to compress the CSS.
|
void |
setCustomJs(List<URL> customJs)
Sets the custom JavaScript files used by the compiler.
|
void |
setCustomJs(URL customJs)
Sets a single custom JavaScript file used by the compiler.
|
void |
setEncoding(String encoding)
Sets the character encoding used by the compiler when writing the output
File . |
void |
setEnvJs(URL envJs)
Sets the Envjs JavaScript file used by the compiler.
|
void |
setLessJs(URL lessJs)
Sets the LESS JavaScript file used by the compiler.
|
public URL getEnvJs()
public void setEnvJs(URL envJs)
init()
is called.envJs
- The Envjs JavaScript file used by the compiler.public URL getLessJs()
public void setLessJs(URL lessJs)
init()
is called.lessJs
- The LESS JavaScript file used by the compiler.public List<URL> getCustomJs()
public void setCustomJs(URL customJs)
init()
is called.customJs
- A single custom JavaScript file used by the compiler.public void setCustomJs(List<URL> customJs)
init()
is called.customJs
- The custom JavaScript files used by the compiler.public boolean isCompress()
public void setCompress(boolean compress)
compress
- If true
, sets the compiler to compress the CSS.public String getEncoding()
File
.File
.public void setEncoding(String encoding)
File
.
If not set the platform default will be used.encoding
- The character encoding used by the compiler when writing the output File
.public void close()
close
in interface AutoCloseable
public String compile(String input) throws LessException
String
to CSS.input
- The LESS input String
to compile.LessException
public String compile(File input) throws IOException, LessException
File
to CSS.input
- The LESS input File
to compile.IOException
- If the LESS file cannot be read.LessException
public void compile(File input, File output) throws IOException, LessException
File
to CSS and writes it to the specified output File
.input
- The LESS input File
to compile.output
- The output File
to write the CSS to.IOException
- If the LESS file cannot be read or the output file cannot be written.LessException
public void compile(File input, File output, boolean force) throws IOException, LessException
File
to CSS and writes it to the specified output File
.input
- The LESS input File
to compile.output
- The output File
to write the CSS to.force
- 'false' to only compile the LESS input file in case the LESS source has been modified (including imports) or the output file does not exists.IOException
- If the LESS file cannot be read or the output file cannot be written.LessException
public String compile(LessSource input) throws LessException
LessSource
to CSS.input
- The input LessSource
to compile.LessException
public void compile(LessSource input, File output) throws IOException, LessException
LessSource
to CSS and writes it to the specified output File
.input
- The input LessSource
to compile.output
- The output File
to write the CSS to.IOException
- If the LESS file cannot be read or the output file cannot be written.LessException
public void compile(LessSource input, File output, boolean force) throws IOException, LessException
LessSource
to CSS and writes it to the specified output File
.input
- The input LessSource
to compile.output
- The output File
to write the CSS to.force
- 'false' to only compile the input LessSource
in case the LESS source has been modified (including imports) or the output file does not exists.IOException
- If the LESS file cannot be read or the output file cannot be written.LessException
Copyright © 2019. All rights reserved.