From ea16960bea8ec03546262f349313899451fd2b60 Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Thu, 19 Nov 2009 10:50:22 +1300 Subject: [PATCH] Fix bugs in truncation helper where it wouldn't properly detect that preserve_html_tags was requested --- refinerycms.gemspec | 2 +- .../refinery/lib/refinery/html_truncation_helper.rb | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/refinerycms.gemspec b/refinerycms.gemspec index 9481afee66..ae21d8fd04 100644 --- a/refinerycms.gemspec +++ b/refinerycms.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = %q{refinerycms} - s.version = "0.9.5.11" + s.version = "0.9.5.12" s.authors = ["Resolve Digital", "David Jones", "Philip Arndt"] s.date = %q{2009-11-19} diff --git a/vendor/plugins/refinery/lib/refinery/html_truncation_helper.rb b/vendor/plugins/refinery/lib/refinery/html_truncation_helper.rb index ba50a6c1d9..5a81c866f9 100644 --- a/vendor/plugins/refinery/lib/refinery/html_truncation_helper.rb +++ b/vendor/plugins/refinery/lib/refinery/html_truncation_helper.rb @@ -25,7 +25,7 @@ module Refinery::HtmlTruncationHelper # Like the Rails _truncate_ helper but doesn't break HTML tags, entities, and optionally. words. def truncate(text, *args) - return super unless args.include?(:preserve_html_tags) + return super unless ((arguments = args.dup).extract_options![:preserve_html_tags] == true) # don't ruin the current args object return if text.nil? options = args.extract_options! @@ -45,12 +45,13 @@ def truncate(text, *args) word_length = actual_length - (truncated_doc.inner_html.mb_chars.length - truncated_doc.inner_html.rindex(' ')) truncated_doc = doc.truncate(word_length) end - - last_child = truncated_doc.children.last - if last_child.inner_html.nil? - truncated_doc.inner_html + omission + options[:link] if options[:link] + + if (last_child = truncated_doc.children.last).inner_html.nil? + "#{truncated_doc.inner_html}#{omission}#{options[:link]}" if options[:link] else - last_child.inner_html = last_child.inner_html.gsub(/\W.[^\s]+$/, "") + omission + logger.warn(last_child) + logger.warn(last_child.inner_html) + last_child.inner_html = "#{last_child.inner_html.gsub(/\W.[^\s]+$/, "")}#{omission}" last_child.inner_html += options[:link] if options[:link] truncated_doc end