lib/onebox/helpers.rb in onebox-1.8.76 vs lib/onebox/helpers.rb in onebox-1.8.77

- old
+ new

@@ -167,15 +167,25 @@ value.respond_to?(:empty?) ? !!value.empty? : !value end end def self.truncate(string, length = 50) + string = sanitize(string) string.size > length ? string[0...(string.rindex(" ", length) || length)] + "..." : string end def self.title_attr(meta) - title = meta[:title].gsub("'", "'").gsub('"', """) - (meta && !blank?(title)) ? "title='#{title}'" : "" + title = get(meta, :title) + !title.nil? ? "title='#{title}'" : "" + end + + def self.get(meta, attr) + (meta && !blank?(meta[attr])) ? sanitize(meta[attr]) : nil + end + + def self.sanitize(value, length = 50) + return nil if blank?(value) + Sanitize.fragment(value).strip end def self.normalize_url_for_output(url) return "" unless url url = url.dup