Forum: Ruby on Rails rhtml produces so many white places?????

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
sayoyo S. (Guest)
on 2006-04-12 18:10
(Received via mailing list)
Hi,

I have a rhtml file that uses some ruby code inside,
there are not too ruby codes, but it repeats itself
thousands of time. I find out each time when the ruby
code execute, it will produce the html code correctly.
But the produced html will conseved the "format" of
the rhtml, and it adds a lot no used white space!!!!
example : toto.rhtml

<body>
<table>
<% data.each{ |x| %>
<% y = x.methode1 %>
<tr><td><%= y %></td><tr>
<% z = x.methode2 %>
<tr><td><%= z %></td><tr>
</table>
</body>

So if data has 3000 rolls, I will have a html like
this:

<body>
<table>

<tr><td>y1</td><tr>

<tr><td>z1</td><tr>


<tr><td>y2</td><tr>

<tr><td>z2</td><tr>


<tr><td>y3</td><tr>

<tr><td>z3</td><tr>
.....

</table>
</body>

I have a lot of white space and each white space is
8byte, so my html file has almost 6meg instead of 2.5
meg (without white space)

Can someone know how shoulf I remove all the white
space????


Thanks you very much

Saiho


The mind is its own place, and in itself.
Can make a Heaven of Hell, a Hell of Heaven.

http://www.geocities.com/sayoyo/

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Samuel P. (Guest)
on 2006-04-12 18:26
(Received via mailing list)
Hey, in your <%   %> tags end them with -%> and that'll supress the
extra carriage return.
Alex Y. (Guest)
on 2006-04-12 18:26
(Received via mailing list)
Saiho Y. wrote:
> <body>
> <table>
> <% data.each{ |x| %>
> <% y = x.methode1 %>
> <tr><td><%= y %></td><tr>
> <% z = x.methode2 %>
> <tr><td><%= z %></td><tr>
> </table>
> </body>
<snip>
> Can someone know how shoulf I remove all the white
> space????

Each time you've got ruby code closed off with %> at the end of a line,
replace it with -%>.  That makes the processor consume the following
newline, which should make things a little easier.  Also, you can join
successive <% %> blocks together - you don't need a separate tag for
each line.  I'd write your block above as follows:

<body>
<table>
<% data.each do |x|
  y = x.methode1
  z = x.methode2 -%>
<tr><td><%= y %></td><tr>
<tr><td><%= z %></td><tr>
<% end -%>
</table>
</body>

Or possibly, simpler:

<body>
<table>
<% data.each do |x| -%>
<tr><td><%= x.methode1 %></td><tr>
<tr><td><%= x.methode2 %></td><tr>
<% end -%>
</table>
</body>
sayoyo S. (Guest)
on 2006-04-12 18:56
(Received via mailing list)
Hi, Thanks you very much for the information

the -%> works great with the end of a line, but is
there something that I can remove the white space at
the begining of the line, bacause if the ruby code it
placed after 3 tab ( for code visibility) the html
will also have 3 tab added. it is possible to remove
that also?


Thanks again for all the information!!!

Saiho



--- Alex Y. <removed_email_address@domain.invalid> wrote:

> correctly.
> > <tr><td><%= y %></td><tr>
> replace it with -%>.  That makes the processor
>   y = x.methode1
> <table>
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


The mind is its own place, and in itself.
Can make a Heaven of Hell, a Hell of Heaven.

http://www.geocities.com/sayoyo/

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Alex Y. (Guest)
on 2006-04-12 19:08
(Received via mailing list)
Saiho Y. wrote:
> Hi, Thanks you very much for the information
>
> the -%> works great with the end of a line, but is
> there something that I can remove the white space at
> the begining of the line, bacause if the ruby code it
> placed after 3 tab ( for code visibility) the html
> will also have 3 tab added. it is possible to remove
> that also?
No, but you could put the indentation inside the <% %> tags...
Paulie (Guest)
on 2006-04-12 19:36
Alex Y. wrote:
> Saiho Y. wrote:
>> Hi, Thanks you very much for the information
>>
>> the -%> works great with the end of a line, but is
>> there something that I can remove the white space at
>> the begining of the line, bacause if the ruby code it
>> placed after 3 tab ( for code visibility) the html
>> will also have 3 tab added. it is possible to remove
>> that also?
> No, but you could put the indentation inside the <% %> tags...

Could you content_for_layout.gsub!(/  /,'')  ?

Or maybe you'd need to do this lots of times.....

P
Alex Y. (Guest)
on 2006-04-12 20:10
(Received via mailing list)
Paulie wrote:
>>>will also have 3 tab added. it is possible to remove
>>>that also?
>>
>>No, but you could put the indentation inside the <% %> tags...
>
>
> Could you content_for_layout.gsub!(/  /,'')  ?
>
> Or maybe you'd need to do this lots of times.....
Hadn't thought of that.  You'd probably want to do something more along
the lines of .gsub(/\s+/, ' ') so that individual spaces don't get
clobbered.  I've got no idea how long it'll take on a 3+MB string,
though...
Ezra Z. (Guest)
on 2006-04-12 21:21
(Received via mailing list)
On Apr 12, 2006, at 9:09 AM, Alex Y. wrote:

>>>> will also have 3 tab added. it is possible to remove
> --
> Alex
> _______________________________________________


Don't do this! It will also remove spaces in your text that you want
to show up on the page.

-Ezra
Alex Y. (Guest)
on 2006-04-12 21:52
(Received via mailing list)
Ezra Z. wrote:
>
> On Apr 12, 2006, at 9:09 AM, Alex Y. wrote:
>
>> Paulie wrote:
>>
<snip>
> Don't do this! It will also remove spaces in your text that you want  to
> show up on the page.
That's why I suggested (/\s+/, ' ') rather than (/\s+/, '').  Aren't
consecutive space characters treated as a single space by HTML
renderers?  Or is that info hopelessly outdated?
Pazu (Guest)
on 2006-04-12 21:55
(Received via mailing list)
Ezra Z. <ezmobius@...> writes:

> Don't do this! It will also remove spaces in your text that you want
> to show up on the page.

There is no such thing. HTML clobbers spaces anyway, so runs of more
than one
consecutive spaces will be show as a single space.
Jean-François (Guest)
on 2006-04-12 22:32
(Received via mailing list)
Pazu <removed_email_address@domain.invalid>:
> Ezra Z. <ezmobius@...> writes:
>
> > Don't do this! It will also remove spaces in your text that you want
> > to show up on the page.
>
> There is no such thing. HTML clobbers spaces anyway, so runs
> of more than one consecutive spaces will be show as a single
> space.

What if there are some strings in javascript embedded snippet ?

   -- Jean-François.
Calle D. (Guest)
on 2006-04-12 22:57
(Received via mailing list)
>>>>> "Alex" == Alex Y. <removed_email_address@domain.invalid> writes:

> Aren't consecutive space characters treated as a single space by
> HTML renderers?

Not in <PRE> elements.
--
		     Calle D. <removed_email_address@domain.invalid>
		 http://www.livejournal.com/users/cdybedahl/
              Please pay no attention to the panda in the fridge.
Pazu (Guest)
on 2006-04-12 23:12
(Received via mailing list)
Jean-François <jf.web3@...> writes:

> What if there are some strings in javascript embedded snippet ?

Then you would be in trouble :)

-- P
This topic is locked and can not be replied to.