Module: SanitizeHtmlFields::InstanceMethods

Includes:
ActionView::Helpers::SanitizeHelper, ClassMethods
Defined in:
lib/sanitize_html_fields/sanitize_html_fields.rb

Instance Method Summary collapse

Methods included from ClassMethods

#sanitize_html_fields

Instance Method Details

#convert_html_fieldsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sanitize_html_fields/sanitize_html_fields.rb', line 29

def convert_html_fields
  options = self.class.shf_options
  self.class.content_columns.each do |c|
    if self.respond_to?("#{c.name}_html") && !self.send("#{c.name}").nil?

      sanitized_html = sanitize(self.send("#{c.name}"), options)
      sanitized_html.gsub!(/[\s\n\r\t]+\Z/, '') if self.class.shf_remove_excessive_whitespaces
      sanitized_html.gsub!("\n", '<br />') if self.class.shf_convert_newlines

      self.send("#{c.name}_html=", sanitized_html)
    end
  end
end