Skip to content

Commit

Permalink
Fix bugs in truncation helper where it wouldn't properly detect that …
Browse files Browse the repository at this point in the history
…preserve_html_tags was requested
  • Loading branch information
parndt committed Nov 18, 2009
1 parent a5fd569 commit ea16960
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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}
Expand Down
13 changes: 7 additions & 6 deletions vendor/plugins/refinery/lib/refinery/html_truncation_helper.rb
Expand Up @@ -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!
Expand All @@ -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
Expand Down

0 comments on commit ea16960

Please sign in to comment.