Skip to content

Commit

Permalink
fix issue hgmnz#65
Browse files Browse the repository at this point in the history
  • Loading branch information
ElvinEfendi committed May 31, 2015
1 parent a09ddcd commit 1cae722
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/app/helpers/truncate_html_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions lib/truncate_html/html_truncator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def truncate
build_output
end

def truncated_html
@truncated_html
end

private

def word_boundary
Expand Down

0 comments on commit 1cae722

Please sign in to comment.