Sha256: 70213fd036851279488f37d7f97be83e43c5f1fe8b5ecd5fb22cf5960e4ef56b

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

require 'white_list_helper'
ActionView::Base.send :include, WhiteListHelper
ActiveRecord::Base.send :include, WhiteListHelper

ActiveRecord::Base.class_eval do
  include ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper, WhiteListHelper, ActionView::Helpers::UrlHelper
  
  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=)      { |value| write_attribute "#{attr_name}", value }    
    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
      self.body = white_list(self.body)
    end
    
    def body_html_with_formatting
      body_html = auto_link(body) { |text| truncate(text, :length => 50) }
      white_list(body_html) 
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
community_engine-2.3.2 vendor/plugins/white_list/init.rb
community_engine-2.3.1 vendor/plugins/white_list/init.rb
community_engine-2.3.0 vendor/plugins/white_list/init.rb
community_engine-2.1.0 vendor/plugins/white_list/init.rb
community_engine-2.0.0 vendor/plugins/white_list/init.rb