Added some filtering to make descriptions more consistent

This commit is contained in:
Godwin
2014-07-13 13:15:05 -06:00
parent 44a6bce08c
commit 14792c14f3
2 changed files with 20 additions and 3 deletions
+18 -1
View File
@@ -1,3 +1,4 @@
module ApplicationHelper
@@keyQueue = nil
@@translationsOnThisPage = nil
@@ -363,7 +364,23 @@ module ApplicationHelper
end
def p(object, attribute)
('<p>' + object.send(attribute.to_s).strip.gsub(/\s*\n+\s*/, '</p><p>') + '</p>').html_safe
content = object.send(attribute.to_s)
result = ''
if content =~ /<(p|span|h\d|div)[^>]*>/
result = content.gsub(/\s*(style|class|id|width|height|font)=\".*?\"/, '')
.gsub(/&nbsp;/, ' ')
.gsub(/<(\/)?\s*h\d\s*>/, '<\1h3>')
.gsub(/<p>(.*?)<br\s\/?>\s*(<br\s\/?>)+/, '<p>\1</p><p>')
.gsub(/<span[^>]*>\s*(.*?)\s*<\/span>/, '\1')
.gsub(/<p>\s*<\/p>/, '')
.gsub(/<(\/)?div>/, '<\1p>')
if !(result =~ /<p[^>]*>/)
result = '<p>' + result + '</p>'
end
else
result = '<p>' + content.strip.gsub(/\s*\n+\s*/, '</p><p>') + '</p>'
end
result.html_safe
end
def form_field(f, response = nil)