Skip to content

Commit

Permalink
Added a wrap method
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartl committed Feb 19, 2011
1 parent 11a3336 commit 337c1de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/helpers/microposts_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module MicropostsHelper

def wrap(content)
sanitize(raw(content.split.map{ |s| wrap_long_string(s) }.join(' ')))
end

private

def wrap_long_string(text, max_width = 30)
zero_width_space = "​"
regex = /.{1,#{max_width}}/
(text.length < max_width) ? text :
text.scan(regex).join(zero_width_space)
end
end
2 changes: 1 addition & 1 deletion app/views/shared/_feed_item.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<span class="user">
<%= link_to feed_item.user.name, feed_item.user %>
</span>
<span class="content"><%= feed_item.content %></span>
<span class="content"><%= wrap(feed_item.content) %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(feed_item.created_at) %> ago.
</span>
Expand Down

0 comments on commit 337c1de

Please sign in to comment.