Sha256: d35a0f8672c2130f59f68c05fe8f3ce9255e89b69c2ebff9c4e2cb2ebd32c54a
Contents?: true
Size: 1.04 KB
Versions: 4
Compression:
Stored size: 1.04 KB
Contents
ActiveRecord::Base.class_eval do include ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper, WhiteListHelper def self.format_attribute(attr_name) class << self; include ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper, WhiteListHelper; end define_method(:body) { read_attribute attr_name } define_method(:body_html) { read_attribute "#{attr_name}_html" } define_method(:body_html=) { |value| write_attribute "#{attr_name}_html", value } before_save :format_content end def dom_id [self.class.name.downcase.pluralize.dasherize, id] * '-' end protected def format_content body.strip! if body.respond_to?(:strip!) self.body_html = body.blank? ? '' : body_html_with_formatting end def body_html_with_formatting body_html = auto_link(body) { |text| truncate(text, 50) } textilized = RedCloth.new(body_html, [ :hard_breaks ]) textilized.hard_breaks = true if textilized.respond_to?("hard_breaks=") white_list(textilized.to_html) end end
Version data entries
4 entries across 4 versions & 2 rubygems