1 ActiveRecord::Base.class_eval do
2 include ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper, WhiteListHelper
3 def self.format_attribute(attr_name)
4 class << self; include ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper, WhiteListHelper; end
5 define_method(:body) { read_attribute attr_name }
6 define_method(:body_html) { read_attribute "#{attr_name}_html" }
7 define_method(:body_html=) { |value| write_attribute "#{attr_name}_html", value }
8 before_save :format_content
12 [self.class.name.downcase.pluralize.dasherize, id] * '-'
17 body.strip! if body.respond_to?(:strip!)
18 self.body_html = body.blank? ? '' : body_html_with_formatting
21 def body_html_with_formatting
22 body_html = auto_link(body) { |text| truncate(text, 50) }
23 textilized = RedCloth.new(body_html, [ :hard_breaks ])
24 textilized.hard_breaks = true if textilized.respond_to?("hard_breaks=")
25 white_list(textilized.to_html)