diff --git a/app/decorators/recipe_decorator.rb b/app/decorators/recipe_decorator.rb index 9a65715..49de7d2 100644 --- a/app/decorators/recipe_decorator.rb +++ b/app/decorators/recipe_decorator.rb @@ -1,5 +1,15 @@ class RecipeDecorator < BaseDecorator + NAME_CUTOFF = 35 + + def short_name + if wrapped.name.length >= NAME_CUTOFF + wrapped.name[0...NAME_CUTOFF] + '...' + else + wrapped.name + end + end + def source_markup uri = begin URI.parse(self.source) diff --git a/app/models/recipe.rb b/app/models/recipe.rb index 81f1ae2..c76386f 100644 --- a/app/models/recipe.rb +++ b/app/models/recipe.rb @@ -13,16 +13,6 @@ class Recipe < ActiveRecord::Base validates :total_time, numericality: true, allow_blank: true validates :active_time, numericality: true, allow_blank: true - NAME_CUTOFF = 35 - - def display_name - if self.name.length >= NAME_CUTOFF - self.name[0...NAME_CUTOFF] + '...' - else - self.name - end - end - def scale(factor, auto_unit = false) recipe_ingredients.each do |ri| ri.scale(factor, auto_unit) diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb index 7616540..924cee9 100644 --- a/app/views/recipes/index.html.erb +++ b/app/views/recipes/index.html.erb @@ -24,9 +24,9 @@ - <% @recipes.each do |recipe| %> + <% decorate(@recipes, RecipeDecorator).each do |recipe| %> - <%= link_to recipe.display_name, recipe %> + <%= link_to recipe.short_name, recipe %> <%= recipe.yields %> <%= recipe_time(recipe) %> <%= timestamp(recipe.created_at) %>