story list: break up long words in titles and domains with <wbr>

This commit is contained in:
joshua stein 2015-03-21 21:56:34 -05:00
parent 21f3334155
commit 168d9bfec3
2 changed files with 27 additions and 15 deletions

View file

@ -1,6 +1,16 @@
module ApplicationHelper
MAX_PAGES = 15
def break_long_words(str, len = 30)
safe_join(str.split(" ").map{|w|
if w.length > len
safe_join(w.split(/(.{#{len}})/), "<wbr>".html_safe)
else
w
end
}, " ")
end
def errors_for(object, message=nil)
html = ""
unless object.errors.blank?
@ -14,17 +24,6 @@ module ApplicationHelper
raw(html)
end
def time_ago_in_words_label(time, options = {})
strip_about = options.delete(:strip_about)
ago = time_ago_in_words(time, options)
if strip_about
ago.gsub!(/^about /, "")
end
raw(label_tag(nil, ago, :title => time.strftime("%F %T %z")))
end
def page_numbers_for_pagination(max, cur)
if max <= MAX_PAGES
return (1 .. max).to_a
@ -60,4 +59,15 @@ module ApplicationHelper
pages
end
def time_ago_in_words_label(time, options = {})
strip_about = options.delete(:strip_about)
ago = time_ago_in_words(time, options)
if strip_about
ago.gsub!(/^about /, "")
end
raw(label_tag(nil, ago, :title => time.strftime("%F %T %z")))
end
end

View file

@ -15,7 +15,8 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
<div class="details">
<span class="link">
<% if story.can_be_seen_by_user?(@user) %>
<a href="<%= story.url_or_comments_path %>"><%= story.title %></a>
<a href="<%= story.url_or_comments_path %>"><%=
break_long_words(story.title) %></a>
<% end %>
<% if story.is_gone? %>
[Story removed by <%= story.is_moderated? ? "moderator" :
@ -32,7 +33,7 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
</span>
<% if story.domain.present? %>
<a class="domain" href="<%= story.domain_search_url %>"><%=
story.domain %></a>
break_long_words(story.domain) %></a>
<% end %>
<% if defined?(single_story) && single_story %>
@ -40,7 +41,8 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
<br>
<span class="merge"></span>
<span class="link">
<a href="<%= ms.url_or_comments_path %>"><%= ms.title %></a>
<a href="<%= ms.url_or_comments_path %>"><%=
break_long_words(ms.title) %></a>
</span>
<span class="tags">
<% ms.sorted_taggings.each do |tagging| %>
@ -51,7 +53,7 @@ class="story <%= story.vote && story.vote[:vote] == 1 ? "upvoted" : "" %>
</span>
<% if ms.domain.present? %>
<a class="domain" href="<%= ms.domain_search_url %>"><%=
ms.domain %></a>
break_long_words(ms.domain) %></a>
<% end %>
<span class="byline">
by