Make ExcerptHelper work for String inputs
This commit is contained in:
@@ -2,9 +2,9 @@ module ExcerptHelper
|
||||
def format_excerpt(content, length: 200)
|
||||
return "" if content.blank?
|
||||
|
||||
text = content.to_plain_text
|
||||
text = content.respond_to?(:to_plain_text) ? content.to_plain_text : content.to_s
|
||||
text = text.gsub(/^>\s*(.*)$/m, '> \1')
|
||||
text = text.gsub(/^[-*]\s*(.*)$/m, '• \1')
|
||||
text = text.gsub(/^\s*[-+]\s*(.*)$/m, '• \1')
|
||||
text = text.gsub(/^\d+\.\s*(.*)$/m) { |m| m }
|
||||
text = text.gsub(/\s+/, " ").strip
|
||||
text.truncate(length)
|
||||
|
||||
@@ -26,5 +26,6 @@ class ExcerptHelperTest < ActionView::TestCase
|
||||
private
|
||||
def assert_excerpt(expected, content, ...)
|
||||
assert_equal expected, format_excerpt(ActionText::Content.new(content), ...), "Excerpt of Action Text Content does not match"
|
||||
assert_equal expected, format_excerpt(content, ...), "Excerpt of String does not match"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user