Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
b0659c1b
Commit
b0659c1b
authored
May 13, 2015
by
Jakub Jirutka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify and unify helpers for rendering markup
parent
daa09250
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
20 additions
and
34 deletions
+20
-34
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+3
-1
app/helpers/tree_helper.rb
app/helpers/tree_helper.rb
+1
-9
app/views/projects/blob/_text.html.haml
app/views/projects/blob/_text.html.haml
+1
-5
app/views/search/results/_snippet_blob.html.haml
app/views/search/results/_snippet_blob.html.haml
+1
-10
app/views/shared/snippets/_blob.html.haml
app/views/shared/snippets/_blob.html.haml
+1
-5
lib/gitlab/markup_helper.rb
lib/gitlab/markup_helper.rb
+5
-3
spec/helpers/application_helper_spec.rb
spec/helpers/application_helper_spec.rb
+7
-0
spec/lib/gitlab/markup_helper_spec.rb
spec/lib/gitlab/markup_helper_spec.rb
+1
-1
No files found.
app/helpers/application_helper.rb
View file @
b0659c1b
...
...
@@ -222,7 +222,9 @@ module ApplicationHelper
end
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
)
else
GitHub
::
Markup
.
render
(
file_name
,
file_content
).
...
...
app/helpers/tree_helper.rb
View file @
b0659c1b
...
...
@@ -25,15 +25,7 @@ module TreeHelper
end
def
render_readme
(
readme
)
if
gitlab_markdown?
(
readme
.
name
)
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
render_markup
(
readme
.
name
,
readme
.
data
)
end
# Return an image icon depending on the file type and mode
...
...
app/views/projects/blob/_text.html.haml
View file @
b0659c1b
-
if
gitlab_markdown?
(
blob
.
name
)
.file-content.wiki
=
preserve
do
=
markdown
(
blob
.
data
)
-
elsif
markup?
(
blob
.
name
)
-
if
markup?
(
blob
.
name
)
.file-content.wiki
=
render_markup
(
blob
.
name
,
blob
.
data
)
-
else
...
...
app/views/search/results/_snippet_blob.html.haml
View file @
b0659c1b
...
...
@@ -13,16 +13,7 @@
.file-title
%i
.fa.fa-file
%strong
=
snippet_blob
[
:snippet_object
].
file_name
-
if
gitlab_markdown?
(
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
)
-
if
markup?
(
snippet_blob
[
:snippet_object
].
file_name
)
.file-content.wiki
-
snippet_blob
[
:snippet_chunks
].
each
do
|
snippet
|
-
unless
snippet
[
:data
].
empty?
...
...
app/views/shared/snippets/_blob.html.haml
View file @
b0659c1b
-
unless
@snippet
.
content
.
empty?
-
if
gitlab_markdown?
(
@snippet
.
file_name
)
.file-content.wiki
=
preserve
do
=
markdown
(
@snippet
.
data
)
-
elsif
markup?
(
@snippet
.
file_name
)
-
if
markup?
(
@snippet
.
file_name
)
.file-content.wiki
=
render_markup
(
@snippet
.
file_name
,
@snippet
.
data
)
-
else
...
...
lib/gitlab/markup_helper.rb
View file @
b0659c1b
...
...
@@ -8,8 +8,10 @@ module Gitlab
#
# Returns boolean
def
markup?
(
filename
)
filename
.
downcase
.
end_with?
(
*
%w(.textile .rdoc .org .creole .wiki
.mediawiki .rst .adoc .ad .asciidoc)
)
gitlab_markdown?
(
filename
)
||
asciidoc?
(
filename
)
||
filename
.
downcase
.
end_with?
(
*
%w(.textile .rdoc .org .creole .wiki
.mediawiki .rst)
)
end
# Public: Determines if a given filename is compatible with
...
...
@@ -32,7 +34,7 @@ module Gitlab
end
def
previewable?
(
filename
)
gitlab_markdown?
(
filename
)
||
markup?
(
filename
)
markup?
(
filename
)
end
end
end
spec/helpers/application_helper_spec.rb
View file @
b0659c1b
...
...
@@ -269,6 +269,13 @@ describe ApplicationHelper do
expect
(
render_markup
(
'foo.rst'
,
content
).
encoding
.
name
).
to
eq
(
'UTF-8'
)
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
expect
(
self
).
to
receive
(
:asciidoc?
).
with
(
'foo.adoc'
).
and_return
(
true
)
expect
(
self
).
to
receive
(
:asciidoc
).
and_return
(
'NOEL'
)
...
...
spec/lib/gitlab/markup_helper_spec.rb
View file @
b0659c1b
...
...
@@ -3,7 +3,7 @@ require 'spec_helper'
describe
Gitlab
::
MarkupHelper
do
describe
'#markup?'
do
%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
expect
(
Gitlab
::
MarkupHelper
.
markup?
(
"README.
#{
type
}
"
)).
to
be_truthy
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment