HubSpot / jinjava

Jinja template engine for Java
Apache License 2.0
704 stars 169 forks source link

incorrect whitespacing #166

Open prior opened 6 years ago

prior commented 6 years ago

example template that reveals error:

{%- macro do_thing() -%}
  {%- set x = 1 -%}
  token
{%- endmacro -%}
xx{{ do_thing() }}xx

I would expect output to be: (as confirmed by http://jinja2test.tk/ )

xxtokenxxx

but instead jinjava outputs:

xx
  tokenxxx
AnakinPt commented 6 years ago

I have a similar problem with new lines.

Some templates have for loops and if statements, and they always render a line in the output. Is possible to not render a new line when we have a line, exclusively, with for, endfor, if or endif (at least)?

mattcoley commented 6 years ago

@AnakinPt Do you have an example snippet I could use to see what is going on?

AnakinPt commented 6 years ago

Original template:

Resources:
{% for n in bucketList %}
  {{ n.resourceName }}:
    Type: 'AWS::S3::Bucket'
    Properties:

Generated:

Resources:

  LoggingS3Bucket:
    Type: 'AWS::S3::Bucket'
    Properties:

If you see in the previous code it generates an empty line in the line with the {% for %} loop?

mattcoley commented 6 years ago

You can use {%- for n in bucketList -%} to strip whitespace.

AnakinPt commented 6 years ago

Thanks. I'll try it next week.

AnakinPt commented 6 years ago

worked perfectly, but only with the dash in the beginning. The both will strip other space.