public class JsCode extends Object
This is open source software released under the Apache 2.0 License
| Modifier and Type | Field and Description |
|---|---|
private StringBuilder |
code |
private String |
indent |
| Constructor and Description |
|---|
JsCode()
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
JsCode |
clear()
Deletes the entire code buffer
|
static String |
create(Consumer<JsCode> consumer)
Returns a Javascript string generated by the consumer logic
|
JsCode |
indent(int count)
Increases the indentation for the current line by a certain number of spaces
|
static void |
main(String[] args) |
JsCode |
newArray(boolean inline,
Consumer<JsArray> consumer)
Writes a new array, optionally in one line, based ont he consuner specified
|
JsCode |
newArray(Consumer<JsArray> consumer)
Writes a new array to the code buffer based on the consumer
|
JsCode |
newFunction(String name,
Consumer<JsCode> consumer) |
JsCode |
newFunction(String name,
String args,
Consumer<JsCode> consumer) |
JsCode |
newLine()
Starts a new line and indents the new line based on current indentation
|
JsCode |
newLine(int count)
Starts a new line and indents the new line based on current indentation
|
JsCode |
newObject(boolean inline,
Consumer<JsObject> consumer)
Writes a new object, optionally on one line, based on the consumer
|
JsCode |
newObject(Consumer<JsObject> consumer)
Writes a new object to the code buffer based on the consumer
|
String |
toString() |
JsCode |
unident(int count)
Removes spaces from the current indentation
|
JsCode |
write(String code,
Object... args)
Writes formatted code string to the output buffer
|
private String indent
private StringBuilder code
public static String create(Consumer<JsCode> consumer)
consumer - the consumer to write Javascript programmaticallypublic JsCode clear()
public JsCode write(String code, Object... args)
code - the formatted code String (see String.format() for details)args - the arguments for the formatted code stringpublic JsCode newLine()
public JsCode newLine(int count)
public JsCode indent(int count)
count - the number of spaces to indent bypublic JsCode unident(int count)
count - the number of spaces to removepublic JsCode newObject(Consumer<JsObject> consumer)
consumer - the consumer with the object write instructionspublic JsCode newObject(boolean inline, Consumer<JsObject> consumer)
inline - if true, write the object definition in one lineconsumer - the consumer with the object write instructionspublic JsCode newArray(Consumer<JsArray> consumer)
consumer - the consumer with array element instructionspublic JsCode newArray(boolean inline, Consumer<JsArray> consumer)
inline - if true, write the array definition in one lineconsumer - the consumer with the array write instructionspublic static void main(String[] args)
Copyright 2014-2017, Xavier Witdouck