Simple format excerpts in activity
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
module ExcerptHelper
|
||||
def format_excerpt(content, length: 200)
|
||||
return "" if content.blank?
|
||||
|
||||
text = content.to_plain_text
|
||||
text = text.gsub(/^>\s*(.*)$/m, '> \1')
|
||||
text = text.gsub(/^[-*]\s*(.*)$/m, '• \1')
|
||||
text = text.gsub(/^\d+\.\s*(.*)$/m) { |m| m }
|
||||
text = text.gsub(/\s+/, " ").strip
|
||||
text.truncate(length)
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
<%= render "events/event/layout", card: event.eventable.card, event: event do %>
|
||||
<span class="txt-break overflow-line-clamp txt-tight-lines">
|
||||
<%= strip_tags(event&.eventable.body.to_s).truncate(200) -%>
|
||||
<%= format_excerpt(event&.eventable.body, length: 200) -%>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user