From 1cae722a5ddcdcee829ce55b65b2243596a3703b Mon Sep 17 00:00:00 2001 From: Elvin Efendi Date: Sun, 31 May 2015 23:50:28 +0200 Subject: [PATCH] fix issue #65 --- lib/app/helpers/truncate_html_helper.rb | 10 ++++++++++ lib/truncate_html/html_truncator.rb | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/lib/app/helpers/truncate_html_helper.rb b/lib/app/helpers/truncate_html_helper.rb index fe3cb90..4c54ce1 100644 --- a/lib/app/helpers/truncate_html_helper.rb +++ b/lib/app/helpers/truncate_html_helper.rb @@ -6,4 +6,14 @@ def truncate_html(html, options={}) TruncateHtml::HtmlTruncator.new(html_string, options).truncate.html_safe end + def slice_html(html, options={}) + return ['', ''] if html.nil? + html_string = TruncateHtml::HtmlString.new(html) + truncator = TruncateHtml::HtmlTruncator.new(html_string, options) + first_part = truncator.truncate.html_safe + second_part = html_string.html_tokens. + slice(truncator.truncated_html.length-1, html_string.length).join.html_safe + [first_part, second_part] + end + end diff --git a/lib/truncate_html/html_truncator.rb b/lib/truncate_html/html_truncator.rb index 52b707f..b963992 100644 --- a/lib/truncate_html/html_truncator.rb +++ b/lib/truncate_html/html_truncator.rb @@ -25,6 +25,10 @@ def truncate build_output end + def truncated_html + @truncated_html + end + private def word_boundary