
Untitled
By: a guest on
May 25th, 2012 | syntax:
Ruby | size: 1.07 KB | hits: 61 | expires: Never
module Extentions
module Cleanup
class << self
def cleanup(text)
lines = []
text.lines do |line|
line.gsub! /(style=".*?")/, ''
line.gsub! /<br.?\/>/, "</p>\n<p>"
line.gsub! /<\/?span.?>/, ''
line.gsub! '</div>', '</p>'
line.gsub! '<div', '<p'
lines << line
end
lines.join
end
end
extend ActiveSupport::Concern
self.included do
attr_accessor :enable_cleanup
class << self
class_attribute :symbols
def cleanup_markup_for(symbols)
symbols = [symbols] if symbols.kind_of? Symbol
raise ArgumentError unless symbols.kind_of? Array
puts self.inspect
@symbols = symbols
end
end
before_validation :cleanup_callback
end
def cleanup_callback
if self.enable_cleanup
(self.class.symbols || []).each do |sym|
self.send "#{sym}=".to_sym, Cleanup.cleanup(self.send sym)
end
end
end
end
end