stringtemplate

Calling Java function with arguments from StringTemplate?

你离开我真会死。 提交于 2019-12-12 14:46:26
问题 StringTemplate allows programmers to fetch data through getters(a function with no arguments). I would like to know that Is it possible to call Java function with arguments from String Template? 回答1: There is a workaround by abusing dictionaries. Here is an example of implementing "function" for limiting item count in a List (issue on github). In your code add dictionary: group.defineDictionary("max", new MaxListItemsLimiter()); Usage (in this example first item in array is max. items count):

How to get StringTemplate V4 to ignore < as delimiter?

☆樱花仙子☆ 提交于 2019-12-12 11:32:12
问题 I'm using StringTemplate V4 to generate some HTML code in my project. I need to have HTML formatting in my templates, so using the default delimiters < and > would be very awkward. So, I'm creating a group passing the delimiter as argument (as recommended by this question), but it simply doesn't work. Here is my test code: public void testTemplate() { char sep = '$'; STGroup stGroup = new STGroupString("temp", "<html>hello, $name$!</html>", sep, sep); System.out.println("Group created"); ST

StringTemplate invalid character '<' when reading XML Template

醉酒当歌 提交于 2019-12-12 10:36:31
问题 I am trying to create a simple XML-Template which so far only consists of: <?xml version="1.0"?> I read the file like this: STGroup group = new STGroupDir("templates"); ST st = group.getInstanceOf("report"); st.add("analysis", ana); String result = st.render(); System.out.println(result); And the result is several error messages: report.st 1:1: invalid character '<' report.st 1:1: invalid character '?' report.st 1:19: invalid character '?' report.st 1:20: invalid character '>' report.st 1:2:

Any tutorials on setting up a templating framework on GAE (Java)?

北慕城南 提交于 2019-12-11 20:13:02
问题 I'm trying to format our emails by using HTML-formatted templates on Google App Engine (using Java), but for the life of me I cannot find a decent tutorial for how to set this up. I've tried looking at StringTemplate, but I cannot find any examples where a stand-alone template is loaded from a servlet's context and used as a formatter. Can anyone help? I'm open to any suggestions, such as Velocity or FreeMarker, so long as they run on GAE. Thanks 回答1: Figured out how to do it. The

Function to get list of all identifiers in String Template (Python)

纵然是瞬间 提交于 2019-12-11 10:26:07
问题 For standard library string template in Python, is there a function to get a list of all identifiers? For example, with the following xml file: <Text>Question ${PrimaryKey}:</Text> <Text>Cheat: ${orientation}</Text> the function will return something like PrimaryKey, orientation 回答1: You can use string.Formatter.parse from string import Formatter s="""<Text>Question ${PrimaryKey}:</Text> <Text>Cheat: ${orientation}</Text>""" print([ele[1] for ele in Formatter().parse(s) if ele[1]]) [

ANTLR and Xtext integration for developing plugin

↘锁芯ラ 提交于 2019-12-11 00:18:43
问题 My current project is focusing on code generation from High-level specification. More specifically, developers write high-level specifications and compiler parses them and generates Java code. For parser, I have used ANTLR grammar and for code generation I have used StringTemplateFiles. For providing nice editor support (with syntax high lighting & coloring), I have used xText. Now, the real problem comes - how can I integrate xText editor support with ANTLR parser and code generator? I want

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

孤街醉人 提交于 2019-12-10 16:09:16
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . 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 way to get the list of available

Custom format functions for StringTemplate4

…衆ロ難τιáo~ 提交于 2019-12-10 10:38:34
问题 I would like to know how to create a custom format function for string template. Let say I have the following code: render(attributes) :: << <html> $atributes: { <div> $customformat(atribute.name)$</div> } </html> >> customformat(name) ::= << $name; format="upper"$ >> Currently the behaviour of the function customformat is: Input: "hello world" -> Output: "HELLO WORLD" And I would like to modify the customformat function so the output is something like the following: Input: "hello world" ->

NoIndentWriter not respecting whitespace in template

守給你的承諾、 提交于 2019-12-10 08:48:54
问题 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 all leading (but not trailing whitespace) even if explicitly present in a template. E.g. with the following template file: $ cat src/templates/a.xml.stg ladder(value)::=<< 0 1 2 3 ^value^ >> ... and the following code: public static void main

embed java code inside a template

穿精又带淫゛_ 提交于 2019-12-08 05:02:25
问题 Is it possible to embed executable java code inside a ST4 template? eg if I want to pass a string to my template, which sometimes prints the string as-is, and sometimes prints it in caps, so I want a java code to do the necessary conversion. Without this feature, I see 3 ways to achieve the same functionality: (1) pre-compute the alternative values in java, and pass them all to the template at one shot (but this may result in too many arguments): // in the below code, if the template can