-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No need to duplicate `helpers.emojify` and manually render markdown if we can just render a partial.
- Loading branch information
1 parent
65c0fa5
commit b3893e3
Showing
8 changed files
with
13 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
class MarkdownController < ApplicationController | ||
skip_before_action :authenticate_user!, only: [:preview] | ||
respond_to :js | ||
|
||
def preview | ||
if params[:source] | ||
markdown_source = params[:source].to_str.gsub(/(?<=^|\s):([\w+-]+):(?=\s|$)/) do |match| | ||
%(![add-emoji](https://github.githubassets.com/images/icons/emoji/#{match.to_str.tr(':', '')}.png)) | ||
end | ||
end | ||
@rendered = MarkdownHelper.render markdown_source | ||
respond_with @rendered | ||
@markdown_source = helpers.emojify(params[:source]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:markdown | ||
#{markdown_source} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe MarkdownController, type: :controller do | ||
describe 'GET #preview' do | ||
it 'correctly assigns rendered html' do | ||
source = '*italic*' | ||
|
||
get :preview, xhr: true, params: { source: source } | ||
render_views | ||
|
||
expect(response).to be_successful | ||
expect(assigns(:rendered)).to eq "<p><em>italic</em></p>\n" | ||
describe 'GET #preview' do | ||
it 'renders a markdown preview' do | ||
sign_in create :user | ||
get :preview, xhr: true, params: { source: '**hans**' } | ||
expect(response.body).to include('$(\'# .preview-contents\').html("<p><strong>hans<\/strong><\/p>\n\n");') | ||
end | ||
end | ||
end |