finished markdown transition

This commit is contained in:
Dan Elbert 2017-04-14 16:40:38 -05:00
parent f560764292
commit 2a5301f5d5
19 changed files with 92 additions and 54 deletions

View File

@ -160,7 +160,37 @@
} }
if ($stepInput.length) { if ($stepInput.length) {
CodeMirror.fromTextArea($stepInput[0]); CodeMirror.fromTextArea(
$stepInput[0],
{
mode: {
name: 'markdown',
strikethrough: true
},
// config tomfoolery to enable soft tabs
extraKeys: {
Tab: function(cm) {
if (cm.somethingSelected()) {
cm.indentSelection("add");
return;
}
if (cm.options.indentWithTabs)
cm.replaceSelection("\t", "end", "+input");
else
cm.execCommand("insertSoftTab");
},
"Shift-Tab": function(cm) {
cm.indentSelection("subtract");
}
},
indentUnit: 2,
tabSize: 2,
indentWithTabs: false,
lineWrapping: true,
lineNumbers: true
}
);
} }
$tagInput.tagsinput({ $tagInput.tagsinput({

View File

@ -2,7 +2,7 @@
$(document).on("turbolinks:load", function() { $(document).on("turbolinks:load", function() {
$(".recipe-view ul.ingredients").checkable(); $(".recipe-view ul.ingredients").checkable();
$(".recipe-view ol.steps").checkable(); $(".recipe-view div.steps ol").checkable();
var $searchBtn = $("#recipe_index_search_button"); var $searchBtn = $("#recipe_index_search_button");

View File

@ -27,6 +27,7 @@
@import "typeahead-bootstrap"; @import "typeahead-bootstrap";
@import "recipes"; @import "recipes";
@import "star_rating"; @import "star_rating";
@import "codemirror_custom";
// Skin overrides // Skin overrides
.has-error { .has-error {

View File

@ -0,0 +1,5 @@
.CodeMirror {
border: 1px solid $gray-light;
font-family: inconsolata monospace;
font-size: 15px;
}

View File

@ -87,3 +87,19 @@
font-weight: 700; font-weight: 700;
src: local('News Cycle Bold'), local('NewsCycle-Bold'), font_url("news-cycle-bold.woff2") format('woff2'); src: local('News Cycle Bold'), local('NewsCycle-Bold'), font_url("news-cycle-bold.woff2") format('woff2');
} }
@font-face {
font-family: 'Inconsolata';
font-style: normal;
font-weight: 400;
src: local('Inconsolata Regular'), local('Inconsolata-Regular'), font_url('inconsolata.woff2') format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
}
@font-face {
font-family: 'Inconsolata';
font-style: normal;
font-weight: 700;
src: local('Inconsolata Bold'), local('Inconsolata-Bold'), font_url('inconsolata-bold.woff2') format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
}

View File

@ -30,11 +30,6 @@ div.ingredient-editor {
} }
div.recipe_editor div.steps {
border: 1px solid black ;
}
div#ingredient-list { div#ingredient-list {
padding-bottom: 15px; padding-bottom: 15px;
} }

View File

@ -66,7 +66,7 @@ class LogsController < ApplicationController
def set_recipe def set_recipe
if params[:recipe_id].present? if params[:recipe_id].present?
@recipe = Recipe.includes([{recipe_ingredients: [:ingredient]}, :recipe_steps]).find(params[:recipe_id]) @recipe = Recipe.includes([{recipe_ingredients: [:ingredient]}]).find(params[:recipe_id])
end end
end end
@ -77,7 +77,7 @@ class LogsController < ApplicationController
end end
def log_params def log_params
params.require(:log).permit(:date, :rating, :notes, recipe_attributes: [:name, :description, :source, :yields, :total_time, :active_time, recipe_ingredients_attributes: [:name, :ingredient_id, :quantity, :units, :preparation, :sort_order, :id, :_destroy], recipe_steps_attributes: [:step, :sort_order, :id, :_destroy]]) params.require(:log).permit(:date, :rating, :notes, recipe_attributes: [:name, :description, :source, :yields, :total_time, :active_time, :step_text, recipe_ingredients_attributes: [:name, :ingredient_id, :quantity, :units, :preparation, :sort_order, :id, :_destroy]])
end end
end end

View File

@ -2,7 +2,6 @@ class Recipe < ApplicationRecord
include TokenizedLike include TokenizedLike
has_many :recipe_ingredients, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy has_many :recipe_ingredients, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy
has_many :recipe_steps, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy
belongs_to :user belongs_to :user
has_and_belongs_to_many :tags has_and_belongs_to_many :tags
@ -12,7 +11,6 @@ class Recipe < ApplicationRecord
scope :active, -> { undeleted.not_log } scope :active, -> { undeleted.not_log }
accepts_nested_attributes_for :recipe_ingredients, allow_destroy: true accepts_nested_attributes_for :recipe_ingredients, allow_destroy: true
accepts_nested_attributes_for :recipe_steps, allow_destroy: true
validates :name, presence: true validates :name, presence: true
validates :total_time, numericality: true, allow_blank: true validates :total_time, numericality: true, allow_blank: true
@ -92,15 +90,12 @@ class Recipe < ApplicationRecord
copy.yields = self.yields copy.yields = self.yields
copy.total_time = self.total_time copy.total_time = self.total_time
copy.active_time = self.active_time copy.active_time = self.active_time
copy.step_text = self.step_text
self.recipe_ingredients.each do |ri| self.recipe_ingredients.each do |ri|
copy.recipe_ingredients << ri.log_copy copy.recipe_ingredients << ri.log_copy
end end
self.recipe_steps.each do |rs|
copy.recipe_steps << rs.log_copy
end
copy copy
end end

View File

@ -1,16 +0,0 @@
class RecipeStep < ApplicationRecord
belongs_to :recipe, inverse_of: :recipe_steps
validates :step, presence: true
validates :sort_order, presence: true
def log_copy
copy = RecipeStep.new
copy.sort_order = self.sort_order
copy.step = self.step
copy
end
end

View File

@ -72,12 +72,8 @@
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">Directions</h3> <h3 class="panel-title">Directions</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body steps">
<ol class="steps"> <%= @recipe.step_text %>
<% @recipe.recipe_steps.each do |s| %>
<li><div><%= "#{s.step}" %></div></li>
<% end %>
</ol>
</div> </div>
</div> </div>
</div> </div>

View File

@ -72,7 +72,7 @@
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">Directions</h3> <h3 class="panel-title">Directions</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body steps">
<%= @recipe.step_text %> <%= @recipe.step_text %>
</div> </div>
</div> </div>

View File

@ -0,0 +1,28 @@
class MigrateSteps < ActiveRecord::Migration[5.0]
class RecipeStub < ActiveRecord::Base
self.table_name = 'recipes'
end
class RecipeStepStub < ActiveRecord::Base
self.table_name = 'recipe_steps'
end
def up
RecipeStub.all.each do |r|
text = ''
RecipeStepStub.where(recipe_id: r.id).order(:sort_order).each do |s|
text << '1. '
text << s.step
text << "\n"
end
r.step_text = text
r.save!
end
end
def down
raise ActiveRecord::IrreversibleMigration, "Can't undo step migration"
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170413173225) do ActiveRecord::Schema.define(version: 20170414185039) do
create_table "ingredient_units", force: :cascade do |t| create_table "ingredient_units", force: :cascade do |t|
t.integer "ingredient_id", null: false t.integer "ingredient_id", null: false

View File

@ -72,7 +72,7 @@ RSpec.describe NotesController, type: :controller do
it "redirects to the created note" do it "redirects to the created note" do
post :create, params: {note: valid_attributes}, session: valid_session post :create, params: {note: valid_attributes}, session: valid_session
expect(response).to redirect_to(Note.last) expect(response).to redirect_to notes_path
end end
end end
@ -111,7 +111,7 @@ RSpec.describe NotesController, type: :controller do
it "redirects to the note" do it "redirects to the note" do
note = create(:note, user: user) note = create(:note, user: user)
put :update, params: {id: note.to_param, note: valid_attributes}, session: valid_session put :update, params: {id: note.to_param, note: valid_attributes}, session: valid_session
expect(response).to redirect_to(note) expect(response).to redirect_to(notes_path)
end end
it 'redirects if note is not owned' do it 'redirects if note is not owned' do

View File

@ -1,7 +0,0 @@
FactoryGirl.define do
factory :recipe_step do
sort_order 1
step "MyText"
end
end

View File

@ -1,4 +0,0 @@
require 'rails_helper'
RSpec.describe RecipeStep, type: :model do
end

Binary file not shown.

BIN
vendor/assets/fonts/inconsolata.woff2 vendored Normal file

Binary file not shown.

View File

@ -678,4 +678,3 @@ fieldset[disabled] .datepicker table tr td span.active.disabled:hover.focus {
margin-left: -5px; margin-left: -5px;
margin-right: -5px; margin-right: -5px;
} }
/*# sourceMappingURL=bootstrap-datepicker3.css.map */