cn.dreampie
类 LessCompiler

java.lang.Object
  继承者 cn.dreampie.LessCompiler

public class LessCompiler
extends Object

The LESS compiler to compile LESS sources to CSS stylesheets.

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; }");
 

作者:
Marcel Overdijk
另请参见:
LESS - The Dynamic Stylesheet language, Rhino - JavaScript for Java, Envjs - Bringing the Browser

构造方法摘要
LessCompiler()
          Constructs a new LessCompiler.
LessCompiler(List<String> options)
          Constructs a new LessCompiler.
 
方法摘要
 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(File input, String name)
          Compiles the LESS input String to CSS, but specifies the source name String.
 String compile(LessSource input)
           
 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.
 String compile(String input, String name)
          Compiles the LESS input String to CSS, but specifies the source name String.
 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 getLesscJs()
          Returns the LESSC JavaScript file used by the compiler.
 URL getLessJs()
          Returns the LESS JavaScript file used by the compiler.
 List<String> getOptions()
           
 void init()
          Initializes this LessCompiler.
 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 setLesscJs(URL lesscJs)
          Sets the LESSC JavaScript file used by the compiler.
 void setLessJs(URL lessJs)
          Sets the LESS JavaScript file used by the compiler.
 void setOptions(List<String> options)
           
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

LessCompiler

public LessCompiler()
Constructs a new LessCompiler.


LessCompiler

public LessCompiler(List<String> options)
Constructs a new LessCompiler.

方法详细信息

getOptions

public List<String> getOptions()

setOptions

public void setOptions(List<String> options)

getEnvJs

public URL getEnvJs()
Returns the Envjs JavaScript file used by the compiler.

返回:
The Envjs JavaScript file used by the compiler.

setEnvJs

public void setEnvJs(URL envJs)
Sets the Envjs JavaScript file used by the compiler. Must be set before init() is called.

参数:
envJs - The Envjs JavaScript file used by the compiler.

getLessJs

public URL getLessJs()
Returns the LESS JavaScript file used by the compiler. COMPILE_STRING

返回:
The LESS JavaScript file used by the compiler.

setLessJs

public void setLessJs(URL lessJs)
Sets the LESS JavaScript file used by the compiler. Must be set before init() is called.

参数:
lessJs - LESS JavaScript file used by the compiler.

getLesscJs

public URL getLesscJs()
Returns the LESSC JavaScript file used by the compiler. COMPILE_STRING

返回:
The LESSC JavaScript file used by the compiler.

setLesscJs

public void setLesscJs(URL lesscJs)
Sets the LESSC JavaScript file used by the compiler. Must be set before init() is called.

参数:
lesscJs - LESSC JavaScript file used by the compiler.

getCustomJs

public List<URL> getCustomJs()
Returns the custom JavaScript files used by the compiler.

返回:
The custom JavaScript files used by the compiler.

setCustomJs

public void setCustomJs(URL customJs)
Sets a single custom JavaScript file used by the compiler. Must be set before init() is called.

参数:
customJs - A single custom JavaScript file used by the compiler.

setCustomJs

public void setCustomJs(List<URL> customJs)
Sets the custom JavaScript files used by the compiler. Must be set before init() is called.

参数:
customJs - The custom JavaScript files used by the compiler.

isCompress

public boolean isCompress()
Returns whether the compiler will compress the CSS.

返回:
Whether the compiler will compress the CSS.

setCompress

public void setCompress(boolean compress)
Sets the compiler to compress the CSS. Must be set before init() is called.

参数:
compress - If true, sets the compiler to compress the CSS.

getEncoding

public String getEncoding()
Returns the character encoding used by the compiler when writing the output File.

返回:
The character encoding used by the compiler when writing the output File.

setEncoding

public void setEncoding(String encoding)
Sets the character encoding used by the compiler when writing the output File. If not set the platform default will be used. Must be set before init() is called.

参数:
encoding - character encoding used by the compiler when writing the output File.

init

public void init()
Initializes this LessCompiler.

It is not needed to call this method manually, as it is called implicitly by the compile methods if needed.


compile

public String compile(String input)
               throws LessException
Compiles the LESS input String to CSS.

参数:
input - The LESS input String to compile.
返回:
The CSS.
抛出:
LessException

compile

public String compile(String input,
                      String name)
               throws LessException
Compiles the LESS input String to CSS, but specifies the source name String.

参数:
input - The LESS input String to compile
name - The source's name String to provide better error messages.
返回:
the CSS.
抛出:
LessException - any error encountered by the compiler

compile

public String compile(File input,
                      String name)
               throws LessException
Compiles the LESS input String to CSS, but specifies the source name String. The entire method is synchronized so that two threads don't read the output at the same time.

参数:
input - The LESS input String to compile
name - The source's name String to provide better error messages.
返回:
the CSS.
抛出:
LessException - any error encountered by the compiler

compile

public String compile(File input)
               throws IOException,
                      LessException
Compiles the LESS input File to CSS.

参数:
input - The LESS input File to compile.
返回:
The CSS.
抛出:
IOException - If the LESS file cannot be read.
LessException

compile

public void compile(File input,
                    File output)
             throws IOException,
                    LessException
Compiles the LESS input 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

compile

public void compile(File input,
                    File output,
                    boolean force)
             throws IOException,
                    LessException
Compiles the LESS input 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

compile

public String compile(LessSource input)
               throws LessException
抛出:
LessException

compile

public void compile(LessSource input,
                    File output)
             throws IOException,
                    LessException
Compiles the input 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

compile

public void compile(LessSource input,
                    File output,
                    boolean force)
             throws IOException,
                    LessException
Compiles the input 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 © 2014. All rights reserved.