Added tags to homepage

This commit is contained in:
Dan Elbert 2016-10-20 18:06:53 -05:00
parent cc398bd9d8
commit b09b3eb196
4 changed files with 24 additions and 11 deletions

View File

@ -10,6 +10,13 @@ class RecipeDecorator < BaseDecorator
end
end
def tag_names
tags = wrapped.tag_names
tags.map do |t|
h.content_tag('span', t, class: 'label label-default')
end.join('&nbsp;').html_safe
end
def source_markup
uri = begin
URI.parse(self.source)

View File

@ -67,18 +67,20 @@ class RecipeIngredient < ApplicationRecord
end
def to_mass
value_unit = as_value_unit
density = self.ingredient.density? ? UnitConversion.parse(ingredient.density) : nil
if ingredient
value_unit = as_value_unit
density = self.ingredient.density? ? UnitConversion.parse(ingredient.density) : nil
case
when value_unit.nil?
when value_unit.mass?
self.quantity = value_unit.pretty_value
self.units = value_unit.unit.to_s
when value_unit.volume? && density && density.density?
value_unit = value_unit.to_mass(density)
self.quantity = value_unit.pretty_value
self.units = value_unit.unit.to_s
case
when value_unit.nil?
when value_unit.mass?
self.quantity = value_unit.pretty_value
self.units = value_unit.unit.to_s
when value_unit.volume? && density && density.density?
value_unit = value_unit.to_mass(density)
self.quantity = value_unit.pretty_value
self.units = value_unit.unit.to_s
end
end
end

View File

@ -18,6 +18,7 @@
<thead>
<tr>
<th><%= index_sort_header('Name', :name, @criteria) %></th>
<th>Tags</th>
<th><%= index_sort_header('Rating', :rating, @criteria) %></th>
<th>Yields</th>
<th><%= index_sort_header('Time', :total_time, @criteria) %></th>
@ -32,6 +33,7 @@
<% decorate(@recipes, RecipeDecorator).each do |recipe| %>
<tr>
<td><%= link_to recipe.short_name, recipe %></td>
<td><%= recipe.tag_names %></td>
<td>
<% if recipe.rating %>
<%= text_field_tag('rating', recipe.rating, disabled: true, data: {rating: true, size: '20px', interval: '0.25'}) %>

View File

@ -9,6 +9,8 @@
<% if @scale %>
<span class="label label-default"><%= @scale %> X</span>
<% end %>
<br/>
<small><%= @recipe.tag_names %></small>
</h1>
</div>
<p class="lead">