diff --git a/Gemfile b/Gemfile
index 8743f0f..f88cec8 100644
--- a/Gemfile
+++ b/Gemfile
@@ -19,6 +19,7 @@ gem 'turbolinks', '~> 5.0.1'
gem 'jbuilder', '~> 2.6'
gem 'cocoon', '~> 1.2.9'
gem 'unitwise', '~> 2.0.0'
+gem 'redcarpet', '~> 3.4.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.11'
diff --git a/Gemfile.lock b/Gemfile.lock
index b4c0477..e99b204 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -164,6 +164,7 @@ GEM
rb-fsevent (0.9.8)
rb-inotify (0.9.8)
ffi (>= 0.5.0)
+ redcarpet (3.4.0)
ref (2.0.0)
rspec (3.5.0)
rspec-core (~> 3.5.0)
@@ -245,6 +246,7 @@ DEPENDENCIES
puma
rails (= 5.0.2)
rails-controller-testing
+ redcarpet (~> 3.4.0)
rspec-rails (~> 3.5.0)
sass-rails (~> 5.0)
sqlite3
diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb
index 1eabc62..1e32c6c 100644
--- a/app/controllers/recipes_controller.rb
+++ b/app/controllers/recipes_controller.rb
@@ -106,6 +106,6 @@ class RecipesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def recipe_params
- params.require(:recipe).permit(:name, :description, :source, :yields, :total_time, :active_time, tag_names: [], recipe_ingredients_attributes: [:name, :ingredient_id, :quantity, :units, :preparation, :sort_order, :id, :_destroy], recipe_steps_attributes: [:step, :sort_order, :id, :_destroy])
+ params.require(:recipe).permit(:name, :description, :source, :yields, :total_time, :active_time, :step_text, tag_names: [], recipe_ingredients_attributes: [:name, :ingredient_id, :quantity, :units, :preparation, :sort_order, :id, :_destroy])
end
end
diff --git a/app/decorators/base_decorator.rb b/app/decorators/base_decorator.rb
index bbed4ff..2be92b3 100644
--- a/app/decorators/base_decorator.rb
+++ b/app/decorators/base_decorator.rb
@@ -44,6 +44,10 @@ class BaseDecorator < SimpleDelegator
ERB::Util.html_escape(*args)
end
+ def markdown(text)
+ MarkdownProcessor.render(text).html_safe
+ end
+
def wrapped
__getobj__
end
diff --git a/app/decorators/recipe_decorator.rb b/app/decorators/recipe_decorator.rb
index 4045d45..8629c04 100644
--- a/app/decorators/recipe_decorator.rb
+++ b/app/decorators/recipe_decorator.rb
@@ -31,4 +31,8 @@ class RecipeDecorator < BaseDecorator
end
end
+ def step_text
+ markdown(wrapped.step_text)
+ end
+
end
\ No newline at end of file
diff --git a/app/views/recipes/_editor.html.erb b/app/views/recipes/_editor.html.erb
index b8be741..d7bc818 100644
--- a/app/views/recipes/_editor.html.erb
+++ b/app/views/recipes/_editor.html.erb
@@ -64,21 +64,15 @@
Steps
-
-
- <%= f.fields_for :recipe_steps do |rs_form| %>
- <%= render partial: 'recipes/editor/step', locals: { f: rs_form } %>
- <% end %>
+
+
+ <%= f.text_area :step_text, class: 'form-control', rows: 15 %>
+
-
-
- <%= link_to_add_association 'Add Step', f, :recipe_steps, partial: 'recipes/editor/step', :'data-association-insertion-node' => '#step-list', :'data-association-insertion-method' => 'append', class: 'btn btn-primary', id: 'addStepButton' %>
-
<% content_for(:page_bottom) do %>
<%= render partial: 'recipes/editor/bulk_ingredient_dialog' %>
- <%= render partial: 'recipes/editor/bulk_step_dialog' %>
diff --git a/app/views/recipes/show.html.erb b/app/views/recipes/show.html.erb
index b255bcb..e7f30a6 100644
--- a/app/views/recipes/show.html.erb
+++ b/app/views/recipes/show.html.erb
@@ -73,11 +73,7 @@
Directions
-
- <% @recipe.recipe_steps.each do |s| %>
- <%= "#{s.step}" %>
- <% end %>
-
+ <%= @recipe.step_text %>
diff --git a/config/initializers/lib.rb b/config/initializers/lib.rb
index 7b1286f..5a26b59 100644
--- a/config/initializers/lib.rb
+++ b/config/initializers/lib.rb
@@ -1,3 +1,4 @@
+require 'markdown_processor'
require 'unit_conversion'
require 'yield_parser'
\ No newline at end of file
diff --git a/db/migrate/20170413173225_add_step_text_to_recipes.rb b/db/migrate/20170413173225_add_step_text_to_recipes.rb
new file mode 100644
index 0000000..6c3ee48
--- /dev/null
+++ b/db/migrate/20170413173225_add_step_text_to_recipes.rb
@@ -0,0 +1,5 @@
+class AddStepTextToRecipes < ActiveRecord::Migration[5.0]
+ def change
+ add_column :recipes, :step_text, :text
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 6ef5d60..d3784cc 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20161014173138) do
+ActiveRecord::Schema.define(version: 20170413173225) do
create_table "ingredient_units", force: :cascade do |t|
t.integer "ingredient_id", null: false
@@ -108,6 +108,7 @@ ActiveRecord::Schema.define(version: 20161014173138) do
t.integer "user_id"
t.boolean "is_log"
t.float "rating"
+ t.text "step_text"
end
create_table "recipes_tags", id: false, force: :cascade do |t|
diff --git a/lib/markdown_processor.rb b/lib/markdown_processor.rb
new file mode 100644
index 0000000..2394e5e
--- /dev/null
+++ b/lib/markdown_processor.rb
@@ -0,0 +1,30 @@
+module MarkdownProcessor
+ class << self
+
+ def render_options
+ {}
+ end
+
+ def markdown_extensions
+ {
+ no_intra_emphasis: true,
+ fenced_code_blocks: true,
+ disable_indented_code_blocks: true
+ }
+ end
+
+ def renderer
+ @renderer ||= Redcarpet::Render::SmartyHTML.new(render_options)
+ end
+
+ def markdown_obj
+ @markdown_obj ||= Redcarpet::Markdown.new(renderer, markdown_extensions)
+ end
+
+ def render(text)
+ return '' unless text.present?
+ markdown_obj.render(text)
+ end
+
+ end
+end
\ No newline at end of file