How to remove unnecessary spaces from a compiled Eco template

Let's say I have this simple but fairly nested Eco template:

<div class="example">
  <% for thing, i in @things: %>
    <div class="nested">
      <% if i % 2 == 0: %>
        This block is fairly nested.
      <% end %>
    </div>
  <% end %>
</div>

When compiling in JS, the result is:

function(__obj) {
  // ... A couple of auxiliary functions ...
  (function() {
    (function() {
      var i, thing, _i, _len, _ref;

      __out.push('<div class="example">\n  ');

      _ref = this.things;
      for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
        thing = _ref[i];
        __out.push('\n    <div class="nested">\n      ');
        if (i % 2 === 0) {
          __out.push('\n        This block is fairly nested.\n      ');
        }
        __out.push('\n    </div>\n  ');
      }

      __out.push('\n</div>\n');

    }).call(this);

  }).call(__obj);
  __obj.safe = __objSafe, __obj.escape = __escape;
  return __out.join('');
}

Now this function (which is used as JS for the client for visualization on the client side) includes some unnecessary spaces in the lines, for example ...

`'\n        This block is fairly nested.\n      '`

... that cannot be removed using the JS compressor, since they are not JS free space (but become HTML free when rendering). I understand that Eco compiles the templates in such a way as to keep their result indented, which is cool in the development environment, but not so much on one of them: D

Is there a way to remove extra spaces from the output eco.precompile?

, Sprockets , .

+3
2

, :

<div class="example">
  <% for thing, i in @things: %>
    <div class="nested"><%= "fairly nested" if i % 2 is 0 %></div>
  <% end %>
</div>

ECO README, .

+2

Eco XML, :

<div class="example">
  <% for thing, i in @things: %><!--
    --><div class="nested"><!--
      --><% if i % 2 == 0: %>
        This block is fairly nested.
      <% end %>
    </div>
  <% end %>
</div>

, .

0

All Articles