olado/doT

Indenting is really off

marcellino-ornelas opened this issue · 1 comments

Hey there,

Description

I'm using doT to generate js files for me to make my life easier but the indenting is really off and it leaves white spaces in my files. all dot commands leave a new line in my files. when it should only be leaving the data I supply. I'm wondering if this can be addressed in v2.

Examples

Say I using this data in my .dot files.

{
  "name": "lino"
}

now when generating a file like so:

{{var name = it.name;}}
console.log('{{=name}}');

it renders to

      <-- leaves new line
console.log('lino')

This also happens if the value of the variable is empty it leaves a new line char behind.

another example is:

{{? true}}
    <h1>hey</h1>
{{?}}

renders to

      <-- leaves new line
    <h1>hey</h1>       <-- leaves extra space
      <-- leaves new line

when I would expect it to look like

<h1>hey</h1>

Also having a problem with defs. I will use an html file as an example but I'm getting this no matter what file I try to generate.

In my def file

{{##def.name:
<h1>lino</h1>
#}}

Now ina dot file

<div>
    {{#def.name}}
</div>

renders to.

<div>
<h1>lino</h1>
</div>

when it should look like

<div>
    <h1>lino</h1>
</div>

There is an option strip that controls whether whitespace and line breaks are preserved.

It was never the intention to preserve the indentation beyond that - it makes no real difference for html or js. What you ask would probably require making quite arbitrary decisions about which whitespace / line-break characters should be preserved.

Please use js-beautify to reformat generated html or code.