BigW Consortium Gitlab

Commit b0659c1b by Jakub Jirutka

Simplify and unify helpers for rendering markup

parent daa09250
...@@ -222,7 +222,9 @@ module ApplicationHelper ...@@ -222,7 +222,9 @@ module ApplicationHelper
end end
def render_markup(file_name, file_content) def render_markup(file_name, file_content)
if asciidoc?(file_name) if gitlab_markdown?(file_name)
Haml::Helpers.preserve(markdown(file_content))
elsif asciidoc?(file_name)
asciidoc(file_content) asciidoc(file_content)
else else
GitHub::Markup.render(file_name, file_content). GitHub::Markup.render(file_name, file_content).
......
...@@ -25,15 +25,7 @@ module TreeHelper ...@@ -25,15 +25,7 @@ module TreeHelper
end end
def render_readme(readme) def render_readme(readme)
if gitlab_markdown?(readme.name) render_markup(readme.name, readme.data)
preserve(markdown(readme.data))
elsif asciidoc?(readme.name)
asciidoc(readme.data)
elsif markup?(readme.name)
render_markup(readme.name, readme.data)
else
simple_format(readme.data)
end
end end
# Return an image icon depending on the file type and mode # Return an image icon depending on the file type and mode
......
- if gitlab_markdown?(blob.name) - if markup?(blob.name)
.file-content.wiki
= preserve do
= markdown(blob.data)
- elsif markup?(blob.name)
.file-content.wiki .file-content.wiki
= render_markup(blob.name, blob.data) = render_markup(blob.name, blob.data)
- else - else
......
...@@ -13,16 +13,7 @@ ...@@ -13,16 +13,7 @@
.file-title .file-title
%i.fa.fa-file %i.fa.fa-file
%strong= snippet_blob[:snippet_object].file_name %strong= snippet_blob[:snippet_object].file_name
- if gitlab_markdown?(snippet_blob[:snippet_object].file_name) - if markup?(snippet_blob[:snippet_object].file_name)
.file-content.wiki
- snippet_blob[:snippet_chunks].each do |snippet|
- unless snippet[:data].empty?
= preserve do
= markdown(snippet[:data])
- else
.file-content.code
.nothing-here-block Empty file
- elsif markup?(snippet_blob[:snippet_object].file_name)
.file-content.wiki .file-content.wiki
- snippet_blob[:snippet_chunks].each do |snippet| - snippet_blob[:snippet_chunks].each do |snippet|
- unless snippet[:data].empty? - unless snippet[:data].empty?
......
- unless @snippet.content.empty? - unless @snippet.content.empty?
- if gitlab_markdown?(@snippet.file_name) - if markup?(@snippet.file_name)
.file-content.wiki
= preserve do
= markdown(@snippet.data)
- elsif markup?(@snippet.file_name)
.file-content.wiki .file-content.wiki
= render_markup(@snippet.file_name, @snippet.data) = render_markup(@snippet.file_name, @snippet.data)
- else - else
......
...@@ -8,8 +8,10 @@ module Gitlab ...@@ -8,8 +8,10 @@ module Gitlab
# #
# Returns boolean # Returns boolean
def markup?(filename) def markup?(filename)
filename.downcase.end_with?(*%w(.textile .rdoc .org .creole .wiki gitlab_markdown?(filename) ||
.mediawiki .rst .adoc .ad .asciidoc)) asciidoc?(filename) ||
filename.downcase.end_with?(*%w(.textile .rdoc .org .creole .wiki
.mediawiki .rst))
end end
# Public: Determines if a given filename is compatible with # Public: Determines if a given filename is compatible with
...@@ -32,7 +34,7 @@ module Gitlab ...@@ -32,7 +34,7 @@ module Gitlab
end end
def previewable?(filename) def previewable?(filename)
gitlab_markdown?(filename) || markup?(filename) markup?(filename)
end end
end end
end end
...@@ -269,6 +269,13 @@ describe ApplicationHelper do ...@@ -269,6 +269,13 @@ describe ApplicationHelper do
expect(render_markup('foo.rst', content).encoding.name).to eq('UTF-8') expect(render_markup('foo.rst', content).encoding.name).to eq('UTF-8')
end end
it "should delegate to #markdown when file name corresponds to Markdown" do
expect(self).to receive(:gitlab_markdown?).with('foo.md').and_return(true)
expect(self).to receive(:markdown).and_return('NOEL')
expect(render_markup('foo.md', content)).to eq('NOEL')
end
it "should delegate to #asciidoc when file name corresponds to AsciiDoc" do it "should delegate to #asciidoc when file name corresponds to AsciiDoc" do
expect(self).to receive(:asciidoc?).with('foo.adoc').and_return(true) expect(self).to receive(:asciidoc?).with('foo.adoc').and_return(true)
expect(self).to receive(:asciidoc).and_return('NOEL') expect(self).to receive(:asciidoc).and_return('NOEL')
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe Gitlab::MarkupHelper do describe Gitlab::MarkupHelper do
describe '#markup?' do describe '#markup?' do
%w(textile rdoc org creole wiki %w(textile rdoc org creole wiki
mediawiki rst adoc ad asciidoc).each do |type| mediawiki rst adoc ad asciidoc mdown md markdown).each do |type|
it "returns true for #{type} files" do it "returns true for #{type} files" do
expect(Gitlab::MarkupHelper.markup?("README.#{type}")).to be_truthy expect(Gitlab::MarkupHelper.markup?("README.#{type}")).to be_truthy
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment