Hi all,
I'm designing a templating plugin that uses stringTemplate4. Currently if I want to template in a number value into a template, I need to specify each of the number in the data file. For example, if I wanted to generate the following code:
String method0 = differentMethod0();
String method1 = differentMethod1();
String method2 = differentMethod2();
String method3 = differentMethod3();
I would need to create a data file (yaml)
with a list like this:
toggles:
- 0
- 1
- 2
- 3
I could use a template with a loop like this:
template(data) :: <<
%data.toggles:[toggle|
String method%toggle% = differentMethod%toggle%();
>>
But what if I wanted to generate 200 methods from 1-200. It would be best to
not have to make an extremely long yaml file that goes all the way from 1 to
200.
I am asking if it possible to implement a range function into stringTemplate4 (where
range is like the Python function range() == inclusive 0..3). This
function would look something like this:
template(data) :: <<
%range(%data.num_of_toggles):[toggle|
String method%toggle% = differentMethod%toggle%();
And then the data file would look like:
num_of_toggles: 4
This would produce the following:
String method0 = differentMethod0();
String method1 = differentMethod1();
String method2 = differentMethod2();
String method3 = differentMethod3();
The range function would allow the user to specify the end of a range value and then the template is able to loop through from 0 to the end of the range value.
Is this something that is possible to implement? Let me know if you have any questions.
--
You received this message because you are subscribed to the Google Groups "stringtemplate-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stringtemplate-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/stringtemplate-discussion/2136416b-795c-4bf2-b6e3-0255d7e2261en%40googlegroups.com.