Browse files

End of Chapter 10

  • Loading branch information...
1 parent 4cf1d73 commit 7fec78428340a2d4fc38061be81d7e19181ecb77 @dirksiemers committed Jun 6, 2012
View
15 app/helpers/microposts_helper.rb
@@ -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
View
2 app/views/microposts/_micropost.html.erb
@@ -1,5 +1,5 @@
<li>
- <span class="content"><%= micropost.content %></span>
+ <span class="content"><%= wrap micropost.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
</span>
View
2 app/views/shared/_feed_item.html.erb
@@ -3,7 +3,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>

0 comments on commit 7fec784

Please sign in to comment.