lalalalala pqpqpqpqpq
2012-Jul-26 18:16 UTC
How to render a text file without changing its formatting?
Currently I am using <%= File.read(''/path/to/file.txt'') %> to render my file on the screen, but this puts the whole file in one line. How would I output the file on the screen the way it is saved in the .txt document? (I can''t use render_file) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Walter Lee Davis
2012-Jul-26 19:07 UTC
Re: How to render a text file without changing its formatting?
On Jul 26, 2012, at 2:16 PM, lalalalala pqpqpqpqpq wrote:> Currently I am using > > <%= File.read(''/path/to/file.txt'') %> > > to render my file on the screen, but this puts the whole file in one > line. How would I output the file on the screen the way it is saved in > the .txt document? (I can''t use render_file) >If the txt file has HTML formatting in it (saved as html code), then a browser will render it the way you might expect it to. But browsers don''t have any particular rules for plain text, and will run them out in a single line if that''s all that is there. You might try running it through the simple_format view helper to see if that fixes things for you. That will at lease put a br at the end of each single line break and a p at every double-line-break. It''s not going to render other tags, like lists or similar. Walter> -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Hassan Schroeder
2012-Jul-26 19:29 UTC
Re: How to render a text file without changing its formatting?
On Thu, Jul 26, 2012 at 12:07 PM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> ...But browsers don''t have any particular rules for plain text ...Uh, well -- sure they do: collapse adjacent instances of white-space (including tabs and newlines) to single space chars :-) But which, to the OP''s point, won''t be done if the content is wrapped in a PRE element... -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
lalalalala pqpqpqpqpq
2012-Jul-26 19:57 UTC
Re: How to render a text file without changing its formatting?
Hassan Schroeder wrote in post #1070306:> On Thu, Jul 26, 2012 at 12:07 PM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> > wrote: > >> ...But browsers don''t have any particular rules for plain text ... > > Uh, well -- sure they do: collapse adjacent instances of white-space > (including tabs and newlines) to single space chars :-) > > But which, to the OP''s point, won''t be done if the content is wrapped > in a PRE element... > > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > http://about.me/hassanschroeder > twitter: @hassanwrapped it in pre, made no difference. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
lalalalala pqpqpqpqpq
2012-Jul-26 19:58 UTC
Re: How to render a text file without changing its formatting?
Hassan Schroeder wrote in post #1070306:> On Thu, Jul 26, 2012 at 12:07 PM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> > wrote: > >> ...But browsers don''t have any particular rules for plain text ... > > Uh, well -- sure they do: collapse adjacent instances of white-space > (including tabs and newlines) to single space chars :-) > > But which, to the OP''s point, won''t be done if the content is wrapped > in a PRE element... > > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > http://about.me/hassanschroeder > twitter: @hassannevermind, this worked. thanks a lot. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Robert Walker
2012-Jul-26 20:21 UTC
Re: How to render a text file without changing its formatting?
lalalalala pqpqpqpqpq wrote in post #1070310:>> But which, to the OP''s point, won''t be done if the content is wrapped >> in a PRE element... > nevermind, this worked. thanks a lot.Keep in mind that, unless you have complete control over the content of that text file, this solution could be very dangerous from a security perspective. For instance if you''re getting that file from an end user through some sort of file upload you better make sure you sanitize it before sending it back to the browser to be rendered. That''s what we would call "user provided data" and you should never trust user provided data. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Jul-26 20:32 UTC
Re: Re: How to render a text file without changing its formatting?
On 26 July 2012 21:21, Robert Walker <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> lalalalala pqpqpqpqpq wrote in post #1070310: >>> But which, to the OP''s point, won''t be done if the content is wrapped >>> in a PRE element... >> nevermind, this worked. thanks a lot. > > Keep in mind that, unless you have complete control over the content of > that text file, this solution could be very dangerous from a security > perspective. For instance if you''re getting that file from an end user > through some sort of file upload you better make sure you sanitize it > before sending it back to the browser to be rendered. > > That''s what we would call "user provided data" and you should never > trust user provided data.Will html not automatically be escaped (assuming this is on Rails 3) as the string will not be marked html safe? If not on 3 then certainly it must be sanitised. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Robert Walker
2012-Jul-26 23:39 UTC
Re: Re: How to render a text file without changing its formatting?
Colin Law wrote in post #1070313:> On 26 July 2012 21:21, Robert Walker <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> That''s what we would call "user provided data" and you should never >> trust user provided data. > > Will html not automatically be escaped (assuming this is on Rails 3) > as the string will not be marked html safe? If not on 3 then > certainly it must be sanitised.Yeah... I didn''t consider that. Thanks for the clarification. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
zvaya
2012-Jul-27 01:25 UTC
Re: How to render a text file without changing its formatting?
How about wrap content in "<pre></pre>"?? On Friday, July 27, 2012 2:16:44 AM UTC+8, Ruby-Forum.com User wrote:> > Currently I am using > > <%= File.read(''/path/to/file.txt'') %> > > to render my file on the screen, but this puts the whole file in one > line. How would I output the file on the screen the way it is saved in > the .txt document? (I can''t use render_file) > > -- > Posted via http://www.ruby-forum.com/. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/-u3Yr9XY3A4J. For more options, visit https://groups.google.com/groups/opt_out.