Story#description_or_story_cache: handle truncation properly
This commit is contained in:
parent
81b3be6165
commit
09f65774c2
|
@ -221,12 +221,19 @@ class Story < ActiveRecord::Base
|
||||||
self.markeddown_description = self.generated_markeddown_description
|
self.markeddown_description = self.generated_markeddown_description
|
||||||
end
|
end
|
||||||
|
|
||||||
def description_or_story_cache
|
def description_or_story_cache(chars = 0)
|
||||||
if self.description.present?
|
s = if self.description.present?
|
||||||
self.markeddown_description.gsub(/<[^>]*>/, "")
|
self.markeddown_description.gsub(/<[^>]*>/, "")
|
||||||
else
|
else
|
||||||
self.story_cache
|
self.story_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if chars > 0
|
||||||
|
# remove last truncated word
|
||||||
|
s = s.to_s[0, chars].gsub(/ [^ ]*$/, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
HTMLEntities.new.decode(s.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def domain
|
def domain
|
||||||
|
|
|
@ -81,9 +81,9 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
|
||||||
|
|
||||||
<% if !(defined?(single_story) && single_story) && @user &&
|
<% if !(defined?(single_story) && single_story) && @user &&
|
||||||
@user.show_story_previews? %>
|
@user.show_story_previews? %>
|
||||||
<% if (sc = story.description_or_story_cache).present? %>
|
<% if (sc = story.description_or_story_cache(500)).present? %>
|
||||||
<div class="story_content">
|
<div class="story_content">
|
||||||
<%= break_long_words(sc[0, 500]) %>
|
<%= break_long_words(sc) %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Reference in a new issue