diff --git a/app/assets/javascripts/recipe_editor.js b/app/assets/javascripts/recipe_editor.js index 04daa6a..0d9ebc9 100644 --- a/app/assets/javascripts/recipe_editor.js +++ b/app/assets/javascripts/recipe_editor.js @@ -160,7 +160,37 @@ } 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({ diff --git a/app/assets/javascripts/recipes.js b/app/assets/javascripts/recipes.js index 5122c7b..d2f328e 100644 --- a/app/assets/javascripts/recipes.js +++ b/app/assets/javascripts/recipes.js @@ -2,7 +2,7 @@ $(document).on("turbolinks:load", function() { $(".recipe-view ul.ingredients").checkable(); - $(".recipe-view ol.steps").checkable(); + $(".recipe-view div.steps ol").checkable(); var $searchBtn = $("#recipe_index_search_button"); diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index b398e18..36aeb37 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -27,6 +27,7 @@ @import "typeahead-bootstrap"; @import "recipes"; @import "star_rating"; +@import "codemirror_custom"; // Skin overrides .has-error { diff --git a/app/assets/stylesheets/codemirror_custom.scss b/app/assets/stylesheets/codemirror_custom.scss new file mode 100644 index 0000000..5dfe50c --- /dev/null +++ b/app/assets/stylesheets/codemirror_custom.scss @@ -0,0 +1,5 @@ +.CodeMirror { + border: 1px solid $gray-light; + font-family: inconsolata monospace; + font-size: 15px; +} \ No newline at end of file diff --git a/app/assets/stylesheets/font_references.scss b/app/assets/stylesheets/font_references.scss index 16e250c..3830510 100644 --- a/app/assets/stylesheets/font_references.scss +++ b/app/assets/stylesheets/font_references.scss @@ -87,3 +87,19 @@ font-weight: 700; 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; +} \ No newline at end of file diff --git a/app/assets/stylesheets/recipes.scss b/app/assets/stylesheets/recipes.scss index 038e42d..905e104 100644 --- a/app/assets/stylesheets/recipes.scss +++ b/app/assets/stylesheets/recipes.scss @@ -30,11 +30,6 @@ div.ingredient-editor { } -div.recipe_editor div.steps { - border: 1px solid black ; -} - - div#ingredient-list { padding-bottom: 15px; } diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb index 4d35dc4..02f4947 100644 --- a/app/controllers/logs_controller.rb +++ b/app/controllers/logs_controller.rb @@ -66,7 +66,7 @@ class LogsController < ApplicationController def set_recipe 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 @@ -77,7 +77,7 @@ class LogsController < ApplicationController end 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 \ No newline at end of file diff --git a/app/models/recipe.rb b/app/models/recipe.rb index 2e4c771..e54f21d 100644 --- a/app/models/recipe.rb +++ b/app/models/recipe.rb @@ -2,7 +2,6 @@ class Recipe < ApplicationRecord include TokenizedLike 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 has_and_belongs_to_many :tags @@ -12,7 +11,6 @@ class Recipe < ApplicationRecord scope :active, -> { undeleted.not_log } accepts_nested_attributes_for :recipe_ingredients, allow_destroy: true - accepts_nested_attributes_for :recipe_steps, allow_destroy: true validates :name, presence: true validates :total_time, numericality: true, allow_blank: true @@ -92,15 +90,12 @@ class Recipe < ApplicationRecord copy.yields = self.yields copy.total_time = self.total_time copy.active_time = self.active_time + copy.step_text = self.step_text self.recipe_ingredients.each do |ri| copy.recipe_ingredients << ri.log_copy end - self.recipe_steps.each do |rs| - copy.recipe_steps << rs.log_copy - end - copy end diff --git a/app/models/recipe_step.rb b/app/models/recipe_step.rb deleted file mode 100644 index 3b4b937..0000000 --- a/app/models/recipe_step.rb +++ /dev/null @@ -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 diff --git a/app/views/logs/show.html.erb b/app/views/logs/show.html.erb index 0bf2b8a..7019342 100644 --- a/app/views/logs/show.html.erb +++ b/app/views/logs/show.html.erb @@ -72,12 +72,8 @@