diff --git a/app/helpers/microposts_helper.rb b/app/helpers/microposts_helper.rb new file mode 100644 index 0000000..ba2702d --- /dev/null +++ b/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 \ No newline at end of file diff --git a/app/views/shared/_feed_item.html.erb b/app/views/shared/_feed_item.html.erb index 682ef51..3bb07c3 100644 --- a/app/views/shared/_feed_item.html.erb +++ b/app/views/shared/_feed_item.html.erb @@ -6,7 +6,7 @@ <%= link_to feed_item.user.name, feed_item.user %> - <%= feed_item.content %> + <%= wrap(feed_item.content) %> Posted <%= time_ago_in_words(feed_item.created_at) %> ago.