move logic into legacy_render_context helper method

This commit is contained in:
Brett Walker 2018-09-04 08:42:23 -05:00
parent a963721f79
commit 589776fc2e
9 changed files with 25 additions and 16 deletions

View file

@ -115,13 +115,13 @@ module MarkupHelper
text = wiki_page.content
return '' unless text.present?
context.merge!({
context.merge!(
pipeline: :wiki,
project: @project,
project_wiki: @project_wiki,
page_slug: wiki_page.slug,
issuable_state_filter_enabled: true
})
)
html =
case wiki_page.format

View file

@ -252,6 +252,10 @@ module ProjectsHelper
"xcode://clone?repo=#{CGI.escape(default_url_to_repo(project))}"
end
def legacy_render_context(params)
params[:legacy_render] ? { markdown_engine: :redcarpet } : {}
end
private
def get_project_nav_tabs(project, current_user)

View file

@ -2,8 +2,7 @@
%div{ class: container_class }
.prepend-top-default.append-bottom-default
.wiki
- context = params[:legacy_render] ? { markdown_engine: :redcarpet} : {}
= render_wiki_content(@wiki_home, context)
= render_wiki_content(@wiki_home, legacy_render_context(params))
- else
- can_create_wiki = can?(current_user, :create_wiki, @project)
.project-home-empty{ class: [('row-content-block' if can_create_wiki), ('content-block' unless can_create_wiki)] }

View file

@ -2,8 +2,7 @@
.diff-content
- if markup?(@blob.name)
.file-content.wiki
- context = params[:legacy_render] ? { markdown_engine: :redcarpet} : {}
= markup(@blob.name, @content, context)
= markup(@blob.name, @content, legacy_render_context(params))
- else
.file-content.code.js-syntax-highlight
- unless @diff_lines.empty?

View file

@ -1,8 +1,6 @@
- blob = viewer.blob
- context = {}
- if params[:legacy_render]
- context[:markdown_engine] = :redcarpet
- else
- context = legacy_render_context(params)
- unless context[:markdown_engine] == :redcarpet
- context[:rendered] = blob.rendered_markup if blob.respond_to?(:rendered_markup)
.file-content.wiki
= markup(blob.name, blob.data, context)

View file

@ -12,8 +12,7 @@
.blocks-container
.block.block-first
- if @sidebar_page
- context = params[:legacy_render] ? { markdown_engine: :redcarpet} : {}
= render_wiki_content(@sidebar_page, context)
= render_wiki_content(@sidebar_page, legacy_render_context(params))
- else
%ul.wiki-pages
= render @sidebar_wiki_entries, context: 'sidebar'

View file

@ -26,7 +26,6 @@
.prepend-top-default.append-bottom-default
.wiki
- context = params[:legacy_render] ? { markdown_engine: :redcarpet} : {}
= render_wiki_content(@page, context)
= render_wiki_content(@page, legacy_render_context(params))
= render 'sidebar'

View file

@ -21,8 +21,7 @@
.file-content.wiki
- snippet_chunks.each do |chunk|
- unless chunk[:data].empty?
- context = params[:legacy_render] ? { markdown_engine: :redcarpet} : {}
= markup(snippet.file_name, chunk[:data], context)
= markup(snippet.file_name, chunk[:data], legacy_render_context(params))
- else
.file-content.code
.nothing-here-block Empty file

View file

@ -470,4 +470,16 @@ describe ProjectsHelper do
end
end
end
describe '#legacy_render_context' do
it 'returns the redcarpet engine' do
params = { legacy_render: '1' }
expect(helper.legacy_render_context(params)).to include(markdown_engine: :redcarpet)
end
it 'returns nothing' do
expect(helper.legacy_render_context({})).to be_empty
end
end
end