Skip to content

Instantly share code, notes, and snippets.

@bgkittrell
Created April 10, 2012 16:43
Show Gist options
  • Save bgkittrell/2352751 to your computer and use it in GitHub Desktop.
Save bgkittrell/2352751 to your computer and use it in GitHub Desktop.
module DoodlekitExtensions
module ContentFilter extend ActiveSupport::Concern
module ClassMethods
def content_filter(field, options = {})
before_save { |r| r.apply_filter(field)}
include DoodlekitExtensions::ContentFilter::InstanceMethods
end
end
module InstanceMethods
def apply_filter(field)
self.send("#{field.to_s}=", filter(self.send("#{field}")))
end
def filter(s)
s.nil? ? s : s.gsub(/<style>.*<\/style>/mi, '')
end
end
end
end
Doodlekit::Application.config.after_initialize do
ActiveRecord::Base.send(:include, DoodlekitExtensions::ContentFilter)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment