Added markdown
This commit is contained in:
parent
a11ab12cd8
commit
624ca9ee7a
1
Gemfile
1
Gemfile
@ -19,6 +19,7 @@ gem 'turbolinks', '~> 5.0.1'
|
|||||||
gem 'jbuilder', '~> 2.6'
|
gem 'jbuilder', '~> 2.6'
|
||||||
gem 'cocoon', '~> 1.2.9'
|
gem 'cocoon', '~> 1.2.9'
|
||||||
gem 'unitwise', '~> 2.0.0'
|
gem 'unitwise', '~> 2.0.0'
|
||||||
|
gem 'redcarpet', '~> 3.4.0'
|
||||||
|
|
||||||
# Use ActiveModel has_secure_password
|
# Use ActiveModel has_secure_password
|
||||||
gem 'bcrypt', '~> 3.1.11'
|
gem 'bcrypt', '~> 3.1.11'
|
||||||
|
@ -164,6 +164,7 @@ GEM
|
|||||||
rb-fsevent (0.9.8)
|
rb-fsevent (0.9.8)
|
||||||
rb-inotify (0.9.8)
|
rb-inotify (0.9.8)
|
||||||
ffi (>= 0.5.0)
|
ffi (>= 0.5.0)
|
||||||
|
redcarpet (3.4.0)
|
||||||
ref (2.0.0)
|
ref (2.0.0)
|
||||||
rspec (3.5.0)
|
rspec (3.5.0)
|
||||||
rspec-core (~> 3.5.0)
|
rspec-core (~> 3.5.0)
|
||||||
@ -245,6 +246,7 @@ DEPENDENCIES
|
|||||||
puma
|
puma
|
||||||
rails (= 5.0.2)
|
rails (= 5.0.2)
|
||||||
rails-controller-testing
|
rails-controller-testing
|
||||||
|
redcarpet (~> 3.4.0)
|
||||||
rspec-rails (~> 3.5.0)
|
rspec-rails (~> 3.5.0)
|
||||||
sass-rails (~> 5.0)
|
sass-rails (~> 5.0)
|
||||||
sqlite3
|
sqlite3
|
||||||
|
@ -106,6 +106,6 @@ class RecipesController < ApplicationController
|
|||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
def recipe_params
|
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
|
||||||
end
|
end
|
||||||
|
@ -44,6 +44,10 @@ class BaseDecorator < SimpleDelegator
|
|||||||
ERB::Util.html_escape(*args)
|
ERB::Util.html_escape(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def markdown(text)
|
||||||
|
MarkdownProcessor.render(text).html_safe
|
||||||
|
end
|
||||||
|
|
||||||
def wrapped
|
def wrapped
|
||||||
__getobj__
|
__getobj__
|
||||||
end
|
end
|
||||||
|
@ -31,4 +31,8 @@ class RecipeDecorator < BaseDecorator
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def step_text
|
||||||
|
markdown(wrapped.step_text)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
@ -64,21 +64,15 @@
|
|||||||
|
|
||||||
|
|
||||||
<h3>Steps</h3>
|
<h3>Steps</h3>
|
||||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#bulk_steps_modal">Bulk Edit</button>
|
<div class="steps">
|
||||||
<div id="step-list">
|
<div class="form-group form-group-sm">
|
||||||
<%= f.fields_for :recipe_steps do |rs_form| %>
|
<%= f.text_area :step_text, class: 'form-control', rows: 15 %>
|
||||||
<%= render partial: 'recipes/editor/step', locals: { f: rs_form } %>
|
</div>
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="deleted_steps"></div>
|
|
||||||
|
|
||||||
<%= 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 %>
|
<% content_for(:page_bottom) do %>
|
||||||
|
|
||||||
<%= render partial: 'recipes/editor/bulk_ingredient_dialog' %>
|
<%= render partial: 'recipes/editor/bulk_ingredient_dialog' %>
|
||||||
<%= render partial: 'recipes/editor/bulk_step_dialog' %>
|
|
||||||
|
|
||||||
<div class="modal fade" id="convert_modal" tabindex="-1" role="dialog">
|
<div class="modal fade" id="convert_modal" tabindex="-1" role="dialog">
|
||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
|
@ -73,11 +73,7 @@
|
|||||||
<h3 class="panel-title">Directions</h3>
|
<h3 class="panel-title">Directions</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<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>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
|
require 'markdown_processor'
|
||||||
require 'unit_conversion'
|
require 'unit_conversion'
|
||||||
require 'yield_parser'
|
require 'yield_parser'
|
5
db/migrate/20170413173225_add_step_text_to_recipes.rb
Normal file
5
db/migrate/20170413173225_add_step_text_to_recipes.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class AddStepTextToRecipes < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
add_column :recipes, :step_text, :text
|
||||||
|
end
|
||||||
|
end
|
@ -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: 20161014173138) do
|
ActiveRecord::Schema.define(version: 20170413173225) 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
|
||||||
@ -108,6 +108,7 @@ ActiveRecord::Schema.define(version: 20161014173138) do
|
|||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.boolean "is_log"
|
t.boolean "is_log"
|
||||||
t.float "rating"
|
t.float "rating"
|
||||||
|
t.text "step_text"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "recipes_tags", id: false, force: :cascade do |t|
|
create_table "recipes_tags", id: false, force: :cascade do |t|
|
||||||
|
30
lib/markdown_processor.rb
Normal file
30
lib/markdown_processor.rb
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user