Forum: Ruby on Rails RedCloth

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.
Charlie B. (Guest)
on 2006-02-27 05:58
Is this the prefered method to implement RedCloth in your views.  I'm
trying to display user input that will sometimes have code references in
it.   This strips out all tags.  I would like for the tags to be
displayed but not read as html.
Thanks in advance!

<%= RedCloth.new(strip_tags(comment.comment),[:filter_html]).to_html %>

charlie bowman
recentrambles.com
Chris Johanesen (Guest)
on 2006-02-27 07:37
Usually it's better to convert the text when it gets submitted and store
a clean version in a separate field. That way there's no overhead of
doing a conversion every time the record is viewed.

Checkout how Typo does it. For instance, the table article has a field
"body" that is what the user entered, and another field "body_html" that
is the red or blue cloth translated text. They have a file called
html_engine.rb in the Lib folder. I just stole that file whole sale for
my app and then in your model just do:

  before_save :transform_body

  def transform_body
    self.body_html = HtmlEngine.transform(body, 'textile',
[:filter_html])
  end

And in your views do <%= @article.body_html %> instead of @article.body

Easy peasy.
Jamie Wilson (Guest)
on 2006-03-03 15:04
(Received via mailing list)
On 27 Feb 2006, at 05:37, Chris Johanesen wrote:

> Usually it's better to convert the text when it gets submitted and
> store
> a clean version in a separate field. That way there's no overhead of
> doing a conversion every time the record is viewed.

That's a really obvious way of doing it that i'd never considered -
d'oh!

Has anyone done any benchmarking to roughly determine how much
overhead is involved in throwing a chunk of text at RedCloth?

If not, i'll have to experiment with that when I get home.

...j
Josh S. (Guest)
on 2006-03-03 23:14
Jamie Wilson wrote:
> On 27 Feb 2006, at 05:37, Chris Johanesen wrote:
>
>> Usually it's better to convert the text when it gets submitted and store
>> a clean version in a separate field. That way there's no overhead of
>> doing a conversion every time the record is viewed.
>
> That's a really obvious way of doing it that i'd never considered - d'oh!
>
> Has anyone done any benchmarking to roughly determine how much
> overhead is involved in throwing a chunk of text at RedCloth?

Hang on a sec...  That sounds like premature optimization to me. If you
are properly caching pages or even fragments then pre-converting markup
on submission is largely redundant. I'd say leave off the optimization
until you do some performance profiling to see what actually needs to be
optimized. I know Typo does pre-conversion which may work well for that
setup, but I've got a simpler site that runs about 99.9% out of cache,
so conversion overhead is almost entirely irrelevant.

By the way, check out the "textilize" helper in the TextHelper library.
That's how I convert using RedCloth in the view. If you need different
options for RedCloth, I suggest making your own flavor of helper and use
that.

--josh
blog.hasmanythrough.com
Berin L. (Guest)
on 2006-03-03 23:43
(Received via mailing list)
Josh S. wrote:
>>
> so conversion overhead is almost entirely irrelevant.
>
>
If we are simply talking about sanitizing input, I would argue that
pre-sanitizing on input gives you a safer environment.  You won't have
to worry about changes in the display exposing latent XSS hacks stored
in the database.

However, if we are talking about when to mark up, I do follow the meme
ingrained by my sound recording experience: do no harm to your input.
So yes, like a good compressor or EQ, you only apply it on the way out.
You can always change it then, but once you record it you can't change
it back.  Sure text is a bit more malleable, if there isn't a good
reason (like safety) then leave it alone.  BTW, recording does provide
pre-processing on the bass guitar to protect equipment--particularly if
the player uses funk influenced bass lines.  But thats about it.
Jay L. (Guest)
on 2006-03-05 01:07
(Received via mailing list)
On Fri, 03 Mar 2006 16:42:24 -0500, Berin L. wrote:

> However, if we are talking about when to mark up, I do follow the meme
> ingrained by my sound recording experience: do no harm to your input.

Is there a British method of textilizing, where you do all your markup
and
localization before you commit the record to disk?  Is RedCloth warmer
and
punchier than BlueCloth?

Jay
Chris Johanesen (Guest)
on 2006-03-05 02:26
> However, if we are talking about when to mark up, I do follow the meme
> ingrained by my sound recording experience: do no harm to your input.

Yes, I believe that is why typo keeps a copy of the original input in
say "body" and the converted text in "body_html".

Of course everything depends on implementation. I've been sort of using
Typo as my model as I learn rails, it's nice to know there are other
ways to do things :)

It makes sense that if you're caching almost everything then maybe do
the conversion on the way out.
Jack B. (Guest)
on 2006-03-05 17:20
Chris Johanesen wrote:
>> However, if we are talking about when to mark up, I do follow the meme
>> ingrained by my sound recording experience: do no harm to your input.
>
> Yes, I believe that is why typo keeps a copy of the original input in
> say "body" and the converted text in "body_html".

There's also a "filters_column" plugin which makes storing a copy of the
converted text pretty simple if you go that route.

http://wiki.rubyonrails.org/rails/pages/Filters+Co...
Chris Johanesen (Guest)
on 2006-03-05 18:45
> There's also a "filters_column" plugin which makes storing a copy of the
> converted text pretty simple if you go that route.
>
> http://wiki.rubyonrails.org/rails/pages/Filters+Co...

I've seen this too, but the code doesn't seem to exist anywhere.
Jack B. (Guest)
on 2006-03-05 18:59
Chris Johanesen wrote:
>> There's also a "filters_column" plugin which makes storing a copy of the
>> converted text pretty simple if you go that route.
>>
>> http://wiki.rubyonrails.org/rails/pages/Filters+Co...
>
> I've seen this too, but the code doesn't seem to exist anywhere.

The Subversion repository still works for me, which is where I believe I
got it from originally....

http://yayforgecko.com/svn/filters_column/
This topic is locked and can not be replied to.