I have YAML file
with my configuration name applications.yaml, this data will be my bindings:
applications:
- name: service1
port: 8080
path: /servier1
- name: service2
port: 8081
path: /service2
Then I have a template file applications.config:
<% applications.each { application -> %>
ApplicationName: <%= application.name %>
<% } $ %>
And putting all together:
@Grab('org.yaml:snakeyaml:1.17')
import org.yaml.snakeyaml.Yaml
Yaml parser = new Yaml()
Map data = parser.load(("applications.yaml" as File).text)
String template_content = new File('applications.config').text
def binding = [applications: data.applications]
def template = new groovy.text.GStringTemplateEngine().createTemplate(template_content).make(binding)
println template.toString()
The issues is now: the output of this process is:
ApplicationName: service1
ApplicationName: service2
But I want this:
ApplicationName: service1
ApplicationName: service2
I do not know why are those extra spaces there. I will like to remove those but I do not see how or when or what is putting those new or breaking lines.
Thank you.
{% my_value -%}
where the - allows me to skip new lines but I will like to know if the template has something like that or a configuration. – Pogy