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