From 5e3487f5526a9a63cf18b17016163f89651335dd Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 28 Oct 2008 11:25:59 -0400 Subject: [PATCH] moving basic htmlization of post content into the model. two immediate benefits: 1. we can test Post output in a unit test 2. we can easily support new storage formats (like markdown and raw html) without writing new view logic --- app/helpers/application_helper.rb | 3 +-- app/models/post.rb | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c37f273..cf26bce 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -34,9 +34,8 @@ def twitterize(string) end def clean_content_for(post) - text = post.content + text = post.to_html text.gsub!(/<(script|noscript|object|embed|style|frameset|frame|iframe)[>\s\S]*<\/\1>/, '') if post.from_feed? - text = RedCloth.new(text, [:filter_styles, :no_span_caps]).to_html text = spanify_links(text) end diff --git a/app/models/post.rb b/app/models/post.rb index f557632..b7d51a5 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -45,4 +45,10 @@ def deleted? def link(root='') "#{root}/#{type.tableize}/#{to_param}" end + + def to_html + text = content + text = RedCloth.new(text, [:filter_styles, :no_span_caps]).to_html + end + end