styles
This commit is contained in:
parent
2e862b25cf
commit
3cc62b0149
@ -237,7 +237,7 @@
|
||||
|
||||
var lines = data.replace("\r", "").split("\n");
|
||||
|
||||
var regex = /^(?:([\d\/.]+)\s+)?(?:([\w-]+)(?:\s+of)?\s+)?(\w[\w ,\-\(\)\/]*)$/i;
|
||||
var regex = /^(?:([\d\/.]+(?:\s+[\d\/]+)?)\s+)?(?:([\w-]+)(?:\s+of)?\s+)?(\w[\w ,\-\(\)\/]*)$/i;
|
||||
|
||||
var magicFunc = function(str) {
|
||||
if (str == "-") {
|
||||
|
@ -48,4 +48,14 @@ div.step-editor {
|
||||
|
||||
div#ingredient-list, div#step-list {
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
|
||||
div.recipe-view {
|
||||
.ingredients div {
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
|
||||
.steps div {
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
class RecipesController < ApplicationController
|
||||
before_action :set_recipe, only: [:show, :edit, :update, :destroy]
|
||||
before_action :set_recipe, only: [:show, :edit, :update, :destroy, :scale]
|
||||
|
||||
# GET /recipes
|
||||
# GET /recipes.json
|
||||
def index
|
||||
@recipes = Recipe.all
|
||||
@recipes = Recipe.active
|
||||
end
|
||||
|
||||
# GET /recipes/1
|
||||
@ -12,6 +12,13 @@ class RecipesController < ApplicationController
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /recipes/1
|
||||
def scale
|
||||
@scale = params[:factor]
|
||||
@recipe.scale(@scale)
|
||||
render :show
|
||||
end
|
||||
|
||||
# GET /recipes/new
|
||||
def new
|
||||
@recipe = Recipe.new
|
||||
@ -54,10 +61,16 @@ class RecipesController < ApplicationController
|
||||
# DELETE /recipes/1
|
||||
# DELETE /recipes/1.json
|
||||
def destroy
|
||||
@recipe.destroy
|
||||
@recipe.deleted = true
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to recipes_url, notice: 'Recipe was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
if @recipe.save
|
||||
format.html { redirect_to recipes_url, notice: 'Recipe was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { redirect_to recipes_url, error: 'Recipe could not be destroyed.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -3,6 +3,8 @@ class Recipe < ActiveRecord::Base
|
||||
has_many :recipe_ingredients, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy
|
||||
has_many :recipe_steps, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy
|
||||
|
||||
scope :active, -> { where('deleted <> ? OR deleted IS NULL', true) }
|
||||
|
||||
accepts_nested_attributes_for :recipe_ingredients, allow_destroy: true
|
||||
accepts_nested_attributes_for :recipe_steps, allow_destroy: true
|
||||
|
||||
@ -11,5 +13,11 @@ class Recipe < ActiveRecord::Base
|
||||
validates :total_time, numericality: true, allow_blank: true
|
||||
validates :active_time, numericality: true, allow_blank: true
|
||||
|
||||
def scale(factor)
|
||||
recipe_ingredients.each do |ri|
|
||||
ri.scale(factor)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -22,4 +22,10 @@ class RecipeIngredient < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def scale(factor)
|
||||
if factor.present? && self.quantity.present? && factor != '1'
|
||||
self.quantity = UnitConversion.convert(self.quantity, factor, nil, nil)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -2,34 +2,50 @@
|
||||
<div class="recipe-view">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="col-xs-10">
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
<%= @recipe.name %>
|
||||
<small>
|
||||
<%= @recipe.description %>
|
||||
</small>
|
||||
<% if @scale %>
|
||||
<span class="label label-default"><%= @scale %> X</span>
|
||||
<% end %>
|
||||
</h1>
|
||||
</div>
|
||||
<p class="lead">
|
||||
<%= @recipe.description %>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-xs-2">
|
||||
<div class="dropdown">
|
||||
<button id="scaleLabel" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Scale
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="scaleLabel">
|
||||
<% ['1/4', '1/3', '1/2', '2/3', '3/4', '1', '1 1/2', '2', '3', '4'].each do |scale| %>
|
||||
<li><%= link_to scale, scale_recipe_path(@recipe, scale) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<% if @recipe.total_time.present? || @recipe.active_time.present? %>
|
||||
<div class="col-xs-4">
|
||||
<span><%= recipe_time(@recipe) %></span>
|
||||
<div class="col-xs-3">
|
||||
<p><%= recipe_time(@recipe) %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @recipe.yields.present? %>
|
||||
<div class="col-xs-4">
|
||||
<span>Yields</span><span><%= @recipe.yields %></span>
|
||||
<div class="col-xs-3">
|
||||
<p>Yields</p><p><%= @recipe.yields %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @recipe.source.present? %>
|
||||
<div class="col-xs-4">
|
||||
<span>Source</span><span><%= @recipe.source %></span>
|
||||
<div class="col-xs-6">
|
||||
<p>Source</p><p><%= @recipe.source %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@ -37,21 +53,34 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
<h4>Ingredients</h4>
|
||||
<ul>
|
||||
<% @recipe.recipe_ingredients.each do |i| %>
|
||||
<li><%= "#{i.quantity} #{i.units} of #{i.custom_name}" %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Ingredients</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<ul class="ingredients">
|
||||
<% @recipe.recipe_ingredients.each do |i| %>
|
||||
<li><div><%= "#{i.quantity} #{i.units} of #{i.custom_name}" %></div></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<h4>Directions</h4>
|
||||
<ol>
|
||||
<% @recipe.recipe_steps.each do |s| %>
|
||||
<li> <%= "#{s.step}" %></li>
|
||||
<% end %>
|
||||
</ol>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Directions</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<ol class="steps">
|
||||
<% @recipe.recipe_steps.each do |s| %>
|
||||
<li><div><%= "#{s.step}" %></div></li>
|
||||
<% end %>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
Rails.application.routes.draw do
|
||||
|
||||
resources :recipes
|
||||
resources :recipes do
|
||||
member do
|
||||
get 'scale/:factor', action: :scale, as: :scale
|
||||
end
|
||||
end
|
||||
|
||||
resources :ingredients, except: [:show] do
|
||||
collection do
|
||||
|
5
db/migrate/20160119012704_add_deleted_to_recipes.rb
Normal file
5
db/migrate/20160119012704_add_deleted_to_recipes.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddDeletedToRecipes < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :recipes, :deleted, :boolean
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160113002615) do
|
||||
ActiveRecord::Schema.define(version: 20160119012704) do
|
||||
|
||||
create_table "ingredients", force: :cascade do |t|
|
||||
t.string "name"
|
||||
@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20160113002615) do
|
||||
t.integer "active_time"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "deleted"
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user