mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-16 16:34:47 -04:00
Allows variable names containing a blank in the template engine.
This commit is contained in:
parent
409bb3cac9
commit
13f2e6aec3
@ -183,6 +183,12 @@ public class Tokenizer {
|
||||
while ((c = readChar()) != '"')
|
||||
builder.append((char) c);
|
||||
break;
|
||||
case '\'':
|
||||
token = Token.IDENT;
|
||||
builder.setLength(0);
|
||||
while ((c = readChar()) != '\'')
|
||||
builder.append((char) c);
|
||||
break;
|
||||
case '?':
|
||||
if (isNextChar('>'))
|
||||
token = Token.CODEEND;
|
||||
@ -326,11 +332,12 @@ public class Tokenizer {
|
||||
int c;
|
||||
while ((c = in.read()) > 0) {
|
||||
if (c == '<') {
|
||||
c = in.read();
|
||||
if (c == '?') {
|
||||
int cc = in.read();
|
||||
if (cc == '?') {
|
||||
return sb.toString();
|
||||
} else {
|
||||
sb.append((char) c);
|
||||
sb.append((char) cc);
|
||||
}
|
||||
} else {
|
||||
if (c == '\n')
|
||||
|
@ -104,11 +104,21 @@ public class ParserTest extends TestCase {
|
||||
return c;
|
||||
}
|
||||
|
||||
public void testParseTemplateTextOnly() throws IOException, ParserException, EvalException {
|
||||
assertEquals("Hello World!", exec("Hello World!").toString());
|
||||
assertEquals("Hello < < World!", exec("Hello < < World!").toString());
|
||||
}
|
||||
|
||||
public void testParseTemplateVariable() throws IOException, ParserException, EvalException {
|
||||
Context c = exec("Hello <? =a ?> World!", new Context().setVar("a", "My"));
|
||||
assertEquals("Hello My World!", c.toString());
|
||||
}
|
||||
|
||||
public void testParseTemplateVariableEscape() throws IOException, ParserException, EvalException {
|
||||
Context c = exec("Hello <? ='a a' ?> World!", new Context().setVar("a a", "My"));
|
||||
assertEquals("Hello My World!", c.toString());
|
||||
}
|
||||
|
||||
public void testParseTemplateCodeOnly() throws IOException, ParserException, EvalException {
|
||||
Context c = exec("<? =a ?>", new Context().setVar("a", "My"));
|
||||
assertEquals("My", c.toString());
|
||||
|
Loading…
x
Reference in New Issue
Block a user