Updated recipe decorator
This commit is contained in:
parent
c71e356195
commit
846c8aa294
@ -1,5 +1,15 @@
|
|||||||
class RecipeDecorator < BaseDecorator
|
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
|
def source_markup
|
||||||
uri = begin
|
uri = begin
|
||||||
URI.parse(self.source)
|
URI.parse(self.source)
|
||||||
|
@ -13,16 +13,6 @@ class Recipe < ActiveRecord::Base
|
|||||||
validates :total_time, numericality: true, allow_blank: true
|
validates :total_time, numericality: true, allow_blank: true
|
||||||
validates :active_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)
|
def scale(factor, auto_unit = false)
|
||||||
recipe_ingredients.each do |ri|
|
recipe_ingredients.each do |ri|
|
||||||
ri.scale(factor, auto_unit)
|
ri.scale(factor, auto_unit)
|
||||||
|
@ -24,9 +24,9 @@
|
|||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @recipes.each do |recipe| %>
|
<% decorate(@recipes, RecipeDecorator).each do |recipe| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= link_to recipe.display_name, recipe %></td>
|
<td><%= link_to recipe.short_name, recipe %></td>
|
||||||
<td><%= recipe.yields %></td>
|
<td><%= recipe.yields %></td>
|
||||||
<td><%= recipe_time(recipe) %></td>
|
<td><%= recipe_time(recipe) %></td>
|
||||||
<td><%= timestamp(recipe.created_at) %></td>
|
<td><%= timestamp(recipe.created_at) %></td>
|
||||||
|
Loading…
Reference in New Issue
Block a user