public abstract class BoonTemplate extends Object
{{this.name}}
Any of the above would cause the name field on the current context to be used rather than a helper of the same name.TODO If you find a "function" (Provider or Function), call it instead of evaluating it and converting it toString. Function gets passed context as argument to apply. TODO Need ability to add Function<> interface implementations as well. TODO loading templates by name jstl.setPrefix("/templates"); jstl.setSuffix(".html"); always search classpath first TODO https://github.com/jknack/handlebars.java block and partial Block and partial helpers work together to provide you Template Inheritance. Usage: {{#block "title"}} ... {{/block}} context: A string literal which define the region's name. Usage: {{#partial "title"}} ... {{/partial}} context: A string literal which define the region's name. NOTE need a way to invoke templates from a jstl // TODO implement include he uses embedded for include {{embedded "user"}} I think I will stick with include but support embedded //https://github.com/jknack/handlebars.java/blob/master/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java I have some too. :) //lower, upper, rpad, etc. https://github.com/jknack/handlebars.java/blob/master/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java TODO implement all standard JSTL functions
fn:contains() Tests if an input string contains the specified substring. fn:containsIgnoreCase() Tests if an input string contains the specified substring in a case insensitive way. fn:endsWith() Tests if an input string ends with the specified suffix. fn:escapeXml() Escapes characters that could be interpreted as XML markup. fn:atIndex() Returns the index withing a string of the first occurrence of a specified substring. fn:join() Joins all elements of an array into a string. fn:length() Returns the number of items in a collection, or the number of characters in a string. fn:replace() Returns a string resulting from replacing in an input string all occurrences with a given string. fn:split() Splits a string into an array of substrings. fn:startsWith() Tests if an input string starts with the specified prefix. fn:substring() Returns a subset of a string. fn:substringAfter() Returns a subset of a string following a specific substring. fn:substringBefore() Returns a subset of a string before a specific substring. fn:toLowerCase() Converts all of the characters of a string to lower case. fn:toUpperCase() Converts all of the characters of a string to upper case. fn:trim() Removes white spaces from both ends of a string.TODO look at functions here https://github.com/elving/swag
Modifier and Type | Field and Description |
---|---|
protected Map<String,Command> |
commandMap
Commands that we support.
|
protected String |
commandMarker
Command marker.
|
protected Object |
context
Context object that we are getting expressions from.
|
protected String |
elseBlock
I was not sure how to handle this so I punted.
|
protected String |
endBlockEnd
The end of an end block.
|
protected String |
endBlockStart
Sets how the beginning of the end block start should look .
|
protected char[] |
expressionEnd
The end of an end expression.
|
protected char[] |
expressionStart
Set the start of expression demarcation.
|
protected char |
expressionStart1stChar
First char used to search strings quickly for expressions or commands.
|
protected Map<String,Function> |
functionMap
Functions can be used anywhere where expressions can be used.
|
protected int |
lineIndex
Current line number.
|
protected char[][] |
lines
List of lines we are processing.
|
protected Map<String,MethodAccess> |
methodMap
Functions can be used anywhere where expressions can be used.
|
protected boolean |
sameStart
It detects if the escaped and unescaped start with the same char.
|
protected boolean |
strictChecking |
protected char[] |
unescapedExpressionEnd |
protected char[] |
unescapedExpressionStart
Three {{{Text in here will not get escaped so you can have
|
protected char |
unescapedExpressionStartChar
First char used to search strings quickly for expressions or commands.
|
Constructor and Description |
---|
BoonTemplate()
Constructor
|
BoonTemplate(char[] expressionStart,
char[] expressionEnd,
Object functions) |
Modifier and Type | Method and Description |
---|---|
BoonTemplate |
addCommandHandlers(Object object)
Adds commandHandlers from class (static methods) or instance (regular methods)).
|
BoonTemplate |
addFunction(String name,
Function function)
Adds function with a give name.
|
BoonTemplate |
addFunction(String methodName,
Object functions)
Adds function with a give name.
|
BoonTemplate |
addFunctions(Object object)
Adds functions from class (static methods) or instance (regular methods)).
|
BoonTemplate |
addTemplateAsFunctions()
Adds functions from class (static methods) or instance (regular methods)).
|
protected Command |
command(String cmdStr)
Lookup a command.
|
Map<String,Command> |
commandMap()
returns the current command map.
|
String |
commandMarker()
Sets the '#' of {{#if}}
|
Object |
context()
Returns the current context.
|
protected void |
eachListItem(CharBuf output,
CharSequence block,
Object object)
Handles the for each case in the case of collections and arrays.
|
String |
elseBlock()
Sets else block marker in total.
|
String |
endBlockEnd()
returns the '}}' or {{/if}}
|
BoonTemplate |
endBlockEnd(String v)
returns the '}}' or {{/if}}
|
String |
endBlockStart() |
BoonTemplate |
endBlockStart(String v)
/**
sets the end of the block start, i.e., the '}}' of {{#if}}
|
protected String |
escape(String charSequence)
Handles string escaping.
|
String |
expressionEnd()
returns the '}}' of {{value}}
|
BoonTemplate |
expressionEnd(String v)
Sets the '}}' of {{value}}
|
String |
expressionStart() |
BoonTemplate |
expressionStart(String v) |
Map<String,MethodAccess> |
functionMap()
returns the current function map.
|
protected Object |
getObjectFromArguments(String arguments)
This method parses the arguments for {{with}}, {{line}}, and {{each}}.
|
Object |
getThis()
Returns the current context.
|
protected void |
handleExpression(CharBuf output,
String command)
Handle an expression
|
protected void |
handleExpressionOrFunction(CharBuf output,
String command)
Handles an expression like {{name}} or function call like {{doIt( 1, 2, ${name} ) }}.
|
protected void |
initContext(Object context)
Initialize the context object.
|
static BoonTemplate |
jstl()
Creates a new JSTL jstl.
|
String |
line()
Returns the current line.
|
protected abstract boolean |
lineHasCommand()
These two are here so I can add JSTL style support later for |
int |
lineIndex()
Returns the current line index
|
Object |
lookup(String objectName)
Lookup an object and use its name as the default value if not found.
|
Object |
lookup(String objectName,
String defaultValue)
Lookup an object and supply a default value.
|
BoonTemplate |
parentTemplate() |
protected void |
processEach(CharBuf output,
String arguments,
CharSequence block)
Handles the for each operation, i.e., handles the {{#each}} command.
|
protected void |
processIf(CharBuf output,
String arguments,
CharSequence[] blocks)
Handles the {{#if}} command.
|
protected abstract boolean |
processLineCommand(CharBuf output,
char[] line)
These two are here so I can add JSTL style support later for |
protected void |
processWith(CharBuf output,
String arguments,
CharSequence block)
Handles the {{#with}}.
|
protected CharSequence |
readBlock(int startIndexOfFirstLine,
String endBlock)
Reads the guts of a block so
Given this if block:
{{#if}}
THIS TEXT WILL BE PART OF THE BLOCK
EVERYTHING IN THE IF, INCLUDING SPACES and \n
{{/if}}
|
protected CharSequence[] |
readBlocks(int startLine,
String elseBlock,
String endBlock)
reads a block that has an else and an if.
|
CharSequence |
replace(CharSequence template,
Object context)
Replace jstl with properties from context.
|
BoonTemplate |
setStringEscaper(Function<String,String> stringEscaper) |
boolean |
strictChecking() |
BoonTemplate |
strictChecking(boolean strictChecking) |
Function<String,String> |
stringEscaper()
Pluggable String escaper
|
static BoonTemplate |
template()
Creates a new jstl.
|
static BoonTemplate |
template(char[] expStart,
char[] expEnd,
Object functions)
Creates a new jstl and allows you to define the start expression and the end expression.
|
static BoonTemplate |
template(String expStart,
String expEnd)
Creates a new jstl and allows you to define the start expression and the end expression.
|
static BoonTemplate |
templateWithCommandHandlers(Object functions)
BoonTemplate with functions
|
static BoonTemplate |
templateWithFunctions(Object functions)
Template with functions
|
String |
unescapedExpressionEnd()
Returns the end of an unescaped expression, i.e., the "}}}" of value.
|
BoonTemplate |
unescapedExpressionEnd(String v)
Sets the end of an unescaped expression, i.e., the "}}}" of value.
|
String |
unescapedExpressionStart()
Returns the start of an unescaped expression, i.e., "{{{"
|
BoonTemplate |
unescapedExpressionStart(String v)
Sets the start of an unescaped expression, i.e., "{{{"
|
protected boolean strictChecking
protected char[] expressionStart
protected String endBlockStart
protected char[] unescapedExpressionStart
protected char[] unescapedExpressionEnd
protected final boolean sameStart
protected String endBlockEnd
protected char[] expressionEnd
protected char expressionStart1stChar
protected char unescapedExpressionStartChar
protected String commandMarker
protected String elseBlock
protected int lineIndex
protected char[][] lines
protected Object context
protected Map<String,Command> commandMap
protected Map<String,MethodAccess> methodMap
public BoonTemplate(char[] expressionStart, char[] expressionEnd, Object functions)
public BoonTemplate()
protected abstract boolean lineHasCommand()
protected abstract boolean processLineCommand(CharBuf output, char[] line)
protected Command command(String cmdStr)
public boolean strictChecking()
public BoonTemplate strictChecking(boolean strictChecking)
public BoonTemplate addFunctions(Object object)
public BoonTemplate addFunction(String name, Function function)
public BoonTemplate addFunction(String methodName, Object functions)
public BoonTemplate addTemplateAsFunctions()
public BoonTemplate addCommandHandlers(Object object)
public String expressionStart()
public BoonTemplate expressionStart(String v)
v
- sets the '{{' of {{name}} and the '{{' of '{{#if}}public String endBlockStart()
public BoonTemplate endBlockStart(String v)
v
- public String unescapedExpressionStart()
public BoonTemplate unescapedExpressionStart(String v)
v
- public String unescapedExpressionEnd()
public BoonTemplate unescapedExpressionEnd(String v)
public String endBlockEnd()
public BoonTemplate endBlockEnd(String v)
public String expressionEnd()
public BoonTemplate expressionEnd(String v)
public String commandMarker()
public String elseBlock()
public int lineIndex()
public String line()
public Object context()
public Object getThis()
public Map<String,MethodAccess> functionMap()
public BoonTemplate parentTemplate()
public static BoonTemplate template()
public static BoonTemplate jstl()
public static BoonTemplate template(String expStart, String expEnd)
expStart
- expEnd
- public static BoonTemplate template(char[] expStart, char[] expEnd, Object functions)
expStart
- expEnd
- public static BoonTemplate templateWithCommandHandlers(Object functions)
functions
- public static BoonTemplate templateWithFunctions(Object functions)
functions
- public CharSequence replace(CharSequence template, Object context)
template
- the jstl (a string or char sequence that constitutes the jstl)context
- instance, map or list of maps/instances or a JSON string which can be a list or a list of objects(maps)protected void initContext(Object context)
context
- public BoonTemplate setStringEscaper(Function<String,String> stringEscaper)
protected void handleExpressionOrFunction(CharBuf output, String command)
output
- output char buffercommand
- name of the command.protected void handleExpression(CharBuf output, String command)
output
- command
- public Object lookup(String objectName)
objectName
- public Object lookup(String objectName, String defaultValue)
objectName
- defaultValue
- protected void processEach(CharBuf output, String arguments, CharSequence block)
output
- arguments
- block
- protected void eachListItem(CharBuf output, CharSequence block, Object object)
output
- the output bufferblock
- the jstl block for the eachobject
- the actual List or Array like objectprotected void processWith(CharBuf output, String arguments, CharSequence block)
output
- the output bufferarguments
- arguments to the with handlerblock
- the actual jstl blockprotected void processIf(CharBuf output, String arguments, CharSequence[] blocks)
output
- the output bufferarguments
- arguments to the with handlerblocks
- the actual jstl blocks, the first item is the if, the second item is the else if presentprotected CharSequence[] readBlocks(int startLine, String elseBlock, String endBlock)
startLine
- elseBlock
- endBlock
- protected CharSequence readBlock(int startIndexOfFirstLine, String endBlock)
startIndexOfFirstLine
- endBlock
- protected Object getObjectFromArguments(String arguments)
Copyright © 2014. All rights reserved.