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
6
votes
1 answer

Generate source code from AST with Antlr4 and StringTemplates

If I have an AST and modify it, can I use StringTemplates to generate the source code for the modified AST? I have successfully implemented my grammar for Antlr4. It generates the AST of a source code and I use the Visitor Class to perform the…
50k4
  • 241
  • 2
  • 11
5
votes
1 answer

Stringtemplate low performance in comparison to Velocity and Mvel

I am trying to do some evaluation of template frameworks. For a simple performance test I'm using these templates private static String mvelTemplate = "Hello, my name is @{name}," + " @foreach{user :…
Roman K
  • 3,309
  • 1
  • 33
  • 49
5
votes
1 answer

Where can I download full example java project that uses stringtemplate?

http://www.antlr.org/wiki/display/ST4/StringTemplate+4+Wiki+Home, http://www.stringtemplate.org/ I looked on the wiki and I may be missing the forest through all the trees, but I need to see a fully working java project not a bunch of snips. …
JStark
  • 2,788
  • 2
  • 29
  • 37
5
votes
4 answers

Generic Template String like in Python in Dart

In python, I often use strings as templates, e.g. templateUrl = '{host}/api/v3/{container}/{resourceid}' params = {'host': 'www.api.com', 'container': 'books', 'resourceid': 10} api.get(templateUrl.format(**params)) This allows for easy base…
The Tahaan
  • 6,915
  • 4
  • 34
  • 54
5
votes
1 answer

ValueError: Invalid placeholder in string

I tried to make my own template for mutate_model.py script (http://salilab.org/modeller/wiki/Mutate%20model) by using python string template where I substituted values for these five variables Model,resType,resPos,pdb,chain to replce and write a new…
user3805057
  • 195
  • 1
  • 13
5
votes
8 answers

Any lightweight templating solutions in Java with support for conditional formatting?

I'm using MessageFormat to format some addresses with a template like this: "{0}\n{1}\n{2}\n{3}, {4} {5}" where 0 = street 1 1 = street 2 2 = street 3 3 = city 4 = state 5 = zip Most of these fields are optional when captured. How do I avoid…
s_t_e_v_e
  • 2,496
  • 3
  • 31
  • 35
5
votes
2 answers

subclass string.Formatter

Following a remark here: How to define a new string formatter, I tried subclassing string.Formatter. Here is what I've done. Unfortunately I seem to have broken it in the process import string from math import floor, log10 class…
Cambium
  • 169
  • 7
5
votes
1 answer

How do you show list length in StringTemplate

I want to show the number of search results that are going to appear in the table, is there a way to show the number of elements or do you have to compute it, ie I want to show something like this: Found $results.size$…
Jay
  • 19,649
  • 38
  • 121
  • 184
5
votes
1 answer

StringTemplate for runtime code gen?

I am working on a project that generates code at runtime based on meta-model. I've used vb.net xml literals for this, but today I ran across StringTemplate project. Has anybody successfully used this library in C# project.
epitka
  • 17,275
  • 20
  • 88
  • 141
4
votes
1 answer

How to force StringTemplate to evaluate attribute within attribute?

I have the following code: StringTemplate st = new StringTemplate("$msg$"); st.SetAttribute("msg", "Hello $usr$"); st.SetAttribute("usr", "Jakub"); Console.WriteLine(st); // current output: "Hello $usr$" // expected output: "Hello Jakub" Do…
Jakub Šturc
  • 35,201
  • 25
  • 90
  • 110
4
votes
2 answers

Can I use string delimiters in StringTemplate? If not, what's a good template engine?

I need a simple template engine, that only does variable names replacement (I don't need other features), and can be configured to use delimiters that are strings, not characters. E.g. new Template("Hello {{topic}}") .add("topic", "world") …
ripper234
  • 222,824
  • 274
  • 634
  • 905
4
votes
1 answer

ANTLR parser for PL/SQL with target language as Java

Do we have a PL/SQL grammer for Java target yet? I got the one for C#, but need for Java target. I would like to use this with ANTLR to generate Java using StringTemplates. I've gone through the documentation and have a decent understanding of how…
Abhay Chaware
  • 333
  • 4
  • 14
4
votes
2 answers

Using string templates for making a quine in python?

I'm basically trying to make a quine in python and first tried with f-strings, but I quickly realized that I first have to define the variables I want to format inside the string. I then learned about string templates and figured that would be the…
Goby
  • 57
  • 4
4
votes
1 answer

StringTemplate violate separation?

I noticed the following in the introduction for StringTemplate: StringTemplate interprets o.p by looking for property p within object o. The lookup rules differ slightly between language ports, but in general they follow the old JavaBeans…
Kricket
  • 4,049
  • 8
  • 33
  • 46
4
votes
1 answer

Callbacks or simple arithmetic in StringTemplate

I'd like to use something like this in StringTemplate - to call a function defined in the application that does the rendering, is that possible?
$renderArticle(article,width,padding)$
I could use a custom type/class just for this field…
possan
  • 475
  • 3
  • 15
1
2
3
17 18