public class ScriptletsParser extends MixedParser
In addition to regular scriptlets, Scripturian supports a few shorthand scriptlets for common tasks:
The "comment scriptlet" (with a pound sign) is ignored.
The "expression scriptlet" (with an equals sign) causes the expression to be sent to standard output. It allows for more readable templates.
The "include scriptlet" (with an ampersand) invokes the
executable.container.include(name)
command as appropriate for
the language. Again, it allows for more readable templates.
Finally, the "in-flow scriptlet" (with a colon) works like a combination of
regular scriptlets with include scriptlets. "In-flow" scriptlets require the
use of a DocumentSource
. Read the FAQ for more information.
If the pound sign appears before the end delimiter, then the rest of the line -- after the end delimiter, outside of the scriptlet -- is ignored, including the newline character. This is useful if you do not want a newline character to appear after the scriplet.
Examples:
<% print('Hello World'); %>
<? document.cacheDuration.set 5000
?>
<%groovy print myVariable %> <?php $executable->container->include(lib_name); ?>
<?= 15 * 6 ?>
<?=js sqrt(myVariable) ?>
<%& 'library.js' %> <?& 'language-' + myObject.getLang + '-support.py' ?>
<%# This is ignored. %>
<%js if(isDebug) { %> <%:python dumpStack(); %> <% } %>
<% print('hi!') #%> This is ignored.
ScriptletPlugin
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_DELIMITER_COMMENT
The default addition to the start delimiter to specify a comment
scriptlet, or to end delimiter to specify that the rest of the line
should be ignored: #
|
static String |
DEFAULT_DELIMITER_EXPRESSION
The default addition to the start delimiter to specify an expression
scriptlet: =
|
static String |
DEFAULT_DELIMITER_IN_FLOW
The default addition to the start delimiter to specify an in-flow
scriptlet: :
|
static String |
DEFAULT_DELIMITER_INCLUDE
The default addition to the start delimiter to specify an include
scriptlet: &
|
static String[][] |
DEFAULT_DELIMITERS
The default delimiters.
|
static String |
DELIMITER_COMMENT_ATTRIBUTE
The delimiter comment attribute for
ParsingContext . |
static String |
DELIMITER_EXPRESSION_ATTRIBUTE
The delimiter expression attribute for
ParsingContext . |
static String |
DELIMITER_IN_FLOW_ATTRIBUTE
The delimiter in-flow attribute for
ParsingContext . |
static String |
DELIMITER_INCLUDE_ATTRIBUTE
The delimiter include attribute for
ParsingContext . |
static String |
DELIMITERS_ATTRIBUTE
The delimiters attribute for
ParsingContext . |
static String |
NAME |
static String |
PLUGINS_ATTRIBUTE
The plugins attribute for
ParsingContext . |
Constructor and Description |
---|
ScriptletsParser() |
Modifier and Type | Method and Description |
---|---|
String |
getName()
The parser name.
|
static boolean |
isScriptlet(String sourceCode)
Checks if the source code is an entire scriptlet, according to the
DEFAULT_DELIMITERS . |
static boolean |
isScriptlet(String sourceCode,
ParsingContext parsingContext)
Checks if the source code is an entire scriptlet, according to the
parsing context.
|
static boolean |
isScriptlet(String sourceCode,
String[][] delimiters)
Checks if the source code is an entire scriptlet, according to the
provided delimiters.
|
Collection<ExecutableSegment> |
parse(String sourceCode,
ParsingContext parsingContext,
Executable executable)
Parses source code, turning it into executable segments.
|
optimize
public static final String NAME
public static final String DELIMITERS_ATTRIBUTE
ParsingContext
.public static final String DELIMITER_COMMENT_ATTRIBUTE
ParsingContext
.public static final String DELIMITER_EXPRESSION_ATTRIBUTE
ParsingContext
.public static final String DELIMITER_INCLUDE_ATTRIBUTE
ParsingContext
.public static final String DELIMITER_IN_FLOW_ATTRIBUTE
ParsingContext
.public static final String PLUGINS_ATTRIBUTE
ParsingContext
.public static final String[][] DEFAULT_DELIMITERS
public static final String DEFAULT_DELIMITER_COMMENT
public static final String DEFAULT_DELIMITER_EXPRESSION
public static final String DEFAULT_DELIMITER_INCLUDE
public static final String DEFAULT_DELIMITER_IN_FLOW
public static boolean isScriptlet(String sourceCode)
DEFAULT_DELIMITERS
.sourceCode
- The source codepublic static boolean isScriptlet(String sourceCode, ParsingContext parsingContext)
sourceCode
- The source codeparsingContext
- The parsing contextpublic static boolean isScriptlet(String sourceCode, String[][] delimiters)
sourceCode
- The source codedelimiters
- The delimiterspublic String getName()
Parser
public Collection<ExecutableSegment> parse(String sourceCode, ParsingContext parsingContext, Executable executable) throws ParsingException, DocumentException
Parser
sourceCode
- The source codeparsingContext
- The parsing contextexecutable
- The executableParsingException
- In case of a parsing errorDocumentException
- In case of a document retrieval errorCopyright © 2009-2015 Three Crickets LLC.