Questions tagged [stringtemplate]

A templating language which strictly enforces model/view separation

StringTemplate is a Java based templating language (with ports in Python, C#, Ruby, Scala) that strictly enforces model/view separation. See the whitepaper for more details.

264 questions
4
votes
1 answer

StringTemplate4 and anonymous templates

I have a problem with the recently released beta version of Stringtemplate 4. In StringTemplate 3, I used to have templates like () { return null; }}> i.e. anonymous templates containing a literal closing brace ("}"),…
pmf
  • 7,619
  • 4
  • 47
  • 77
4
votes
3 answers

Why StringTemplate could be slow?

I'm using StringTemplate as view layer for my web application. Recently I've measured how much time is spent rendering pages and it's around 50ms for simple pages and 500ms for complex pages. This is too much for my needs, so I'm looking for a way…
Fixpoint
  • 9,619
  • 17
  • 59
  • 78
4
votes
0 answers

Line wrapping with white space padding using stringtemplate

How can I pad a sentence with white space so that it is printed in a 'block'. I want to print a receipt. for a given item I want to print the quantity, item name, and price. 12 x Example short name £2.00 1 x This is an example of a long…
4
votes
1 answer

Antlr4 language translation - separating template logic from visitor class?

I’m looking at pragmatically translating huge amounts of relatively simple TSQL code to Groovy code. There are a number of reasons sure, but the driving reason is just to see if it can be done and in the process learn about compilers/grammers/ etc. …
vicsz
  • 9,552
  • 16
  • 69
  • 101
4
votes
0 answers

NoIndentWriter not respecting whitespace in template

I am trying to use the NoIndentWriter class to get around a problem I am facing related to the inserting of whitespace in multiline Strings. However, it appears that NoIndentWriter does a lot more than just not auto-indenting. In particular it trims…
Marcus Junius Brutus
  • 26,087
  • 41
  • 189
  • 331
4
votes
2 answers

StringTemplate bad performance

I'm using StringTemplate to generate some xml files from datasets. Sometimes I have more than 100,000 records in the dataset that is enumerated by a loop in a template. It goes very slow (15-20 secs per operation) so performance is not good for…
Genius
  • 1,784
  • 14
  • 12
4
votes
2 answers

curly braclet in a StringTemplate

The following StringTemplate gives me an "invalid character '}'" exception because of the closing curly brace after return null;: $StatementList:{statement | public T $statement$(X x) { return null; } }$ I want to have an output like: public T…
Klaus Schulz
  • 527
  • 1
  • 5
  • 20
4
votes
2 answers

How to escape HTML by default in StringTemplate?

It is very good practice in HTML template engines to HTML-escape by default placeholder text to help prevent XSS (cross-site scripting) attacks. Is it possible to achieve this behavior in StringTemplate? I have tried to register custom…
dened
  • 4,253
  • 18
  • 34
4
votes
1 answer

StringTemplate render string as uppercase

In StringTemplate, is there a built-in way to render a string as uppercase, e.g. something like this: my_template(component) ::= << >> ... or do I have to use a custom renderer for this purpose?
geschema
  • 2,464
  • 4
  • 30
  • 41
4
votes
1 answer

How do you iterate over a map of lists using StringTemplate?

I need to produce HTML output that will look like this: - 2010 - Item 1 - Item 2 - 2011 - Item 9 - 2012 - item 6 Ive tried a map, ie Map> but I cant work out how you would iterate over it, ie this doesnt…
Jay
  • 19,649
  • 38
  • 121
  • 184
4
votes
0 answers

How to get the list of available variables from a StringTemplate template

I'd like to obtain the list of variables from a template to request them from a UI application. Let's say I have a template like This is some template called $templateName$ with the description $templateDescription$ I was wondering if there is any…
ghm1014
  • 675
  • 6
  • 12
4
votes
2 answers

How do I use an IF statement in a loop with StringTemplate

This displays nothing: $Articles:{ $if(i!=1)$ display in between articles $endif$ $it.Text } This displays as expected $Articles:{ display in between articles …
Stephen Lacy
4
votes
1 answer

C# StringTemplate - how to set eol character

I'm using the C# version of the StringTemplate library (http://www.stringtemplate.org/) to generate C++ code. My templates work fine, until I started using the syntax to apply templates to multiple values in a…
Roel
  • 19,338
  • 6
  • 61
  • 90
4
votes
1 answer

How to write to an OutputStream directly using Stringtemplate 4.x?

I don't want to call .render() and build extremely large Strings from some of my templates. In previous versions you could write to an OutputStream directly instead of having to render the entire template to a String and then write that out. I tried…
user177800
4
votes
2 answers

What is the best way to ensure HTML entities are escaped in StringTemplate

Assuming the following string template, is being given a list of Java Bean objects:
    $people:{p|
  • $p.name$ $p.email
  • }$
ie the list of people might contain Person objects which you may or may not have the ability to…
Jay
  • 19,649
  • 38
  • 121
  • 184
1 2
3
17 18