Rhtml produces so many white places?

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

<% data.each{ |x| %> <% y = x.methode1 %> <% z = x.methode2 %>
<%= y %>
<%= z %>

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

.....
y1
z1
y2
z2
y3
z3

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.


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around

Hey, in your <% %> tags end them with -%> and that’ll supress the
extra carriage return.

Saiho Y. wrote:

<% data.each{ |x| %> <% y = x.methode1 %> <% z = x.methode2 %>
<%= y %>
<%= z %>
> 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:

<% data.each do |x| y = x.methode1 z = x.methode2 -%> <% end -%>
<%= y %>
<%= z %>

Or possibly, simpler:

<% data.each do |x| -%> <% end -%>
<%= x.methode1 %>
<%= x.methode2 %>

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…

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

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…

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. [email protected] wrote:

correctly.

<%= y %>

replace it with -%>. That makes the processor
y = x.methode1

Rails mailing list [email protected] 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.


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around

Ezra Z. wrote:

On Apr 12, 2006, at 9:09 AM, Alex Y. wrote:

Paulie wrote:

> 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?

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

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.

“Alex” == Alex Y. [email protected] writes:

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

Not in
 elements.

	     Calle D. <[email protected]>
	 http://www.livejournal.com/users/cdybedahl/
          Please pay no attention to the panda in the fridge.

Pazu [email protected]:

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.

Jean-François <jf.web3@…> writes:

What if there are some strings in javascript embedded snippet ?

Then you would be in trouble :slight_smile:

– P