Commit 8320faf1

mo khan <mo@mokhan.ca>
2015-01-21 04:52:32
use built-in truncate helper.
1 parent f5e6295
Changed files (6)
app/helpers/creations_helper.rb
@@ -1,17 +0,0 @@
-module CreationsHelper
-  def short_name(creation, length)
-    if( creation.name.length > length)
-      creation.name[0...length] + '...'
-    else
-      creation.name
-    end
-  end
-  def shrink(name, length, default = nil)
-    return default unless name.present?
-    if name.length > length
-      name[0...length] + '...'
-    else
-      name
-    end
-  end
-end
app/views/my/favorites/index.html.erb
@@ -13,7 +13,7 @@
                 <%= image_tag creation.primary_image.url_for(:thumb) %>
               <% end %>
               <div class="caption">
-                <small><%= link_to shrink(creation.name, 12), cake_path(creation) %></small>
+                <small><%= link_to truncate(creation.name, length: 12), cake_path(creation) %></small>
               </div>
             </div>
           </li>
app/views/profiles/_index.html.erb
@@ -9,7 +9,7 @@
                 <%= avatar_for(profile) %>
               <% end %>
               <div class="caption">
-                <small><%= link_to shrink(profile.name, 20), profile_path(profile) %></small>
+                <small><%= link_to truncate(profile.name, length: 20), profile_path(profile) %></small>
               </div>
             </div>
           </li>
app/views/profiles/show.html.erb
@@ -33,7 +33,7 @@
               <%= image_tag creation.primary_image.url_for(:thumb) %>
             <% end %>
             <div class="caption">
-              <small><%= link_to shrink(creation.name, 20), cake_path(creation) %></small>
+              <small><%= link_to truncate(creation.name, length: 20), cake_path(creation) %></small>
             </div>
           </div>
         </li>
app/views/tutorial_tags/show.html.erb
@@ -9,8 +9,8 @@
               <%= image_tag tutorial.image_url %>
             <% end %>
             <div class="caption">
-              <h4><%= link_to shrink(tutorial.heading, 12), tutorial %></h4>
-              <p><%= link_to shrink(tutorial.user.name, 20), profile_path(tutorial.user) %></p>
+              <h4><%= link_to truncate(tutorial.heading, length: 12), tutorial %></h4>
+              <p><%= link_to truncate(tutorial.user.name, length: 20), profile_path(tutorial.user) %></p>
               <p><small><%= time_ago_in_words(tutorial.created_at) %> ago.</small></p>
             </div>
           </div>
app/views/tutorials/index.html.erb
@@ -10,7 +10,7 @@
               <%= image_tag tutorial.image_url, width: 240 %>
             <% end %>
             <div class="caption">
-              <small><%= link_to shrink(tutorial.heading, 20), tutorial %></small>
+              <small><%= link_to truncate(tutorial.heading, length: 20), tutorial %></small>
             </div>
           </div>
         </li>