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
Hey, in your <% %> tags end them with -%> and that''ll supress the extra carriage return. On 4/12/06, Saiho Yuen <sayoyo@yahoo.com> wrote:> 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Saiho Yuen wrote:> 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><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> -- Alex
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 Young <alex@blackkettle.org> wrote:> Saiho Yuen wrote: > > 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> > <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> > > -- > Alex > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > 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
Saiho Yuen 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
Alex Young wrote:> Saiho Yuen 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 -- Posted via http://www.ruby-forum.com/.
If you want to nicely format up the html (so you can better see what''s going on) might I suggest using Tidy and running the output through that? Works well! Andrew -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Paulie Sent: 12 April 2006 16:36 To: rails@lists.rubyonrails.org Subject: [Rails] Re: rhtml produces so many white places????? Alex Young wrote:> Saiho Yuen 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 -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Paulie wrote:> Alex Young wrote: > >>Saiho Yuen 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.....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... -- Alex
Ezra Zygmuntowicz
2006-Apr-12 17:20 UTC
[Rails] Re: rhtml produces so many white places?????
On Apr 12, 2006, at 9:09 AM, Alex Young wrote:> Paulie wrote: >> Alex Young wrote: >>> Saiho Yuen 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..... > 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... > > -- > Alex > _______________________________________________Don''t do this! It will also remove spaces in your text that you want to show up on the page. -Ezra
Ezra Zygmuntowicz wrote:> > On Apr 12, 2006, at 9:09 AM, Alex Young wrote: > >> Paulie wrote: >><snip>>>> 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... >> >> -- >> Alex > 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? -- Alex
Ezra Zygmuntowicz <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.
Pazu <pazu@pazu.com.br>:> Ezra Zygmuntowicz <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. -- ? la renverse.
>>>>> "Alex" == Alex Young <alex@blackkettle.org> writes:> Aren''t consecutive space characters treated as a single space by > HTML renderers?Not in <PRE> elements. -- Calle Dybedahl <calle@cyberpomo.com> http://www.livejournal.com/users/cdybedahl/ Please pay no attention to the panda in the fridge.