The attached patch adds a mode "-T m" (for Marc ;-)). This mode strips out
lines that have nothing but white-space and <% ... %> sections. For example:
----------
<% 1.upto(3) do %>
Hello !
<% end %>
----------
With normal "erb" this produces:
----------
Hello !
Hello !
Hello !
----------
With "erb -T m" this produces:
----------
Hello !
Hello !
Hello !
----------
Same with stuff like this:
----------
<% bar = true %>
Foo
<% if bar %> <% one = "1" %>
Bar
<% end %>
Baz
----------
Normal mode:
----------
Foo
Bar
Baz Foo
<% if bar %>
Bar
<% end %>
Baz
----------
"erb -T m":
----------
Foo
Bar
Baz
----------
The code is not very beautiful and if someone considers integrating this stuff
in the official ERb then "-T m" might not be a good mode name but
nevertheless, here's the code.
Comments welcome.
Bye,
Marc
--
Marc Haisenko
Comdasys AG
Rüdesheimer Str. 7
80686 München
Germany
Tel.: +49 (0)89 548 433 321
This is of course a copy&paste error... should be:
----------
Foo
Bar
Baz
----------
Bye,
----------
<% 1.upto(3) do -%>
Hello !
<% end -%>
----------
produces
Hello !
Hello !
Hello !
It's the dash in "-%>" that signals this.
Jason
No, it doesn't. Try it :-) It produces:
----------
Hello !
Hello !
Hello !
----------
Notice the leading tab. Same with this:
---------
<% true -%>
foo
---------
The result is:
---------
foo
---------
But not with my patch.
Your first post only talks about white-space where the <% %> was, not
about this leading tab-spacing issue.
Jason
You're right, sorry. So my patch makes the line get omitted entirely (if it
contains nothing but white-space), "-%>" only ommits the newline.
Plus my mode doesn't need the explicit "-%>", only the normal "%>".
> You're right, sorry. So my patch makes the line get omitted entirely (if it
> contains nothing but white-space), "-%>" only ommits the newline.
>
> Plus my mode doesn't need the explicit "-%>", only the normal "%>".
Could a more aggressive patch read the <!DOCTYPE..>, then apply its XML DTD to
remove all non-significant blanks? I suspect that would save wear and tear on
servers. If the HTML DTDs actually specify which blanks are significant!
--
Phlip
Sorry, but ERb doesn't do any XML processing, it's a simple templating system.
>> Could a more aggressive patch read the <!DOCTYPE..>, then apply its XML DTD
^
> to
>> remove all non-significant blanks? I suspect that would save wear and tear
> on
>> servers. If the HTML DTDs actually specify which blanks are significant!
> Sorry, but ERb doesn't do any XML processing, it's a simple templating system.
That's why I said "patch".
Well, yes, you could write one :-) But I'd say that's not an easy task,
especially if you want to do it correctly (e.g. still have the correct line
numbers in exceptions).
On Mar 26, 2008, at 2:45 PM, Marc Haisenko wrote:
> On Wednesday 26 March 2008, Phlip wrote:
>> Marc Haisenko wrote:
>>
>>>> Could a more aggressive patch read the <!DOCTYPE..>, then apply
>>>> its XML
>>>> DTD to remove all non-significant blanks? I suspect that would
>>>> save wear
>>>> and tear on servers. If the HTML DTDs actually specify which
>>>> blanks are
>>>> significant!
>>>
>>> Sorry, but ERb doesn't do any XML processing, it's a simple
>>> templating
>>> system.
>>
>> That's why I said "patch".
>
I have the impression that this goes beyond the scope of a templating
system. It
also could get messy if you your template has no doctype (Partials,
for example).
Why not use tidy for such a task?
Greetings
Florian Gilcher
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
iEYEARECAAYFAkfspjEACgkQJA/zY0IIRZZ6KACggTd2UW9iZa/d4S/GEFHNMqJH
RyIAoIvq/zX7iPhUSr76Zw/WlQfOBb52
=/wJQ
-----END PGP SIGNATURE-----