BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
857 stars 130 forks source link

redundant linebreaks in the product of a "for" statement #309

Closed eugene-panferov closed 9 years ago

eugene-panferov commented 9 years ago

i have noticed that: <div data-link="{for Obj tmpl="#tmpl"}"></div> produces something like: <div> <script>...</script>

tmpl's body

<script>...</script>

tmpl's body

<script>...</script>

tmpl's body

</div>

which puts an amount of linebreaks within the div's text element. and linebreaks (shame on html authors!) have SIZE. so that creating unnecessary intervals between the "#tmpl" elements in the on-screen presentation.

may i ask you to exclude linebreaks from the produced text element, either by commenting them out, or putting inside these script tags.

something like the following: <div><!-- --><script>...</script >#tmpl's body <script>...</script >#tmpl's body <script>...</script >#tmpl's body<!-- --></div>

BorisMoore commented 9 years ago

If your template #tmpl does not include line breaks:

<script id="tmpl" type="text/x-jsrender">templatebody</script>

then the innerHTML of your <div data-link="{for someArray tmpl="#tmpl"}"></div> should be:

<script type="jsv#2_"></script><script type="jsv#3_"></script>templatebody<script type="jsv/3_"></script><script type="jsv#4_"></script>templatebody<script type="jsv/4_"></script><script type="jsv#5_"></script>templatebody<script type="jsv/5_"></script><script type="jsv/2_"></script>"

No line breaks - works for me.

OTOH if you include line breaks in the template:

<script id="tmpl" type="text/x-jsrender">
templatebody
</script>

they will be preserved.

Note that the template is the full innerHTML of the script element. No whitespace trimming... Since you may actually want, for example, a single linebreak as your template:

<script id="tmpl" type="text/x-jsrender">
</script>
eugene-panferov commented 9 years ago

thanx for the explanation. works for me too!