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
Tatuya Kamada
gitlab-ce
Commits
9c642776
Commit
9c642776
authored
May 18, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9289 from jirutka/asciidoc-2
Refactor, simplify and unify helpers for rendering markup
parents
b61a44fe
b0659c1b
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
35 additions
and
49 deletions
+35
-49
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+6
-4
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+1
-1
app/helpers/tree_helper.rb
app/helpers/tree_helper.rb
+1
-9
app/models/tree.rb
app/models/tree.rb
+3
-3
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
+6
-4
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
+8
-8
No files found.
app/helpers/application_helper.rb
View file @
9c642776
...
@@ -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
).
...
@@ -233,15 +235,15 @@ module ApplicationHelper
...
@@ -233,15 +235,15 @@ module ApplicationHelper
end
end
def
markup?
(
filename
)
def
markup?
(
filename
)
Gitlab
::
Mark
down
Helper
.
markup?
(
filename
)
Gitlab
::
Mark
up
Helper
.
markup?
(
filename
)
end
end
def
gitlab_markdown?
(
filename
)
def
gitlab_markdown?
(
filename
)
Gitlab
::
Mark
down
Helper
.
gitlab_markdown?
(
filename
)
Gitlab
::
Mark
up
Helper
.
gitlab_markdown?
(
filename
)
end
end
def
asciidoc?
(
filename
)
def
asciidoc?
(
filename
)
Gitlab
::
Mark
down
Helper
.
asciidoc?
(
filename
)
Gitlab
::
Mark
up
Helper
.
asciidoc?
(
filename
)
end
end
# Overrides ActionView::Helpers::UrlHelper#link_to to add `rel="nofollow"` to
# Overrides ActionView::Helpers::UrlHelper#link_to to add `rel="nofollow"` to
...
...
app/helpers/blob_helper.rb
View file @
9c642776
...
@@ -55,7 +55,7 @@ module BlobHelper
...
@@ -55,7 +55,7 @@ module BlobHelper
end
end
def
editing_preview_title
(
filename
)
def
editing_preview_title
(
filename
)
if
Gitlab
::
Mark
down
Helper
.
previewable?
(
filename
)
if
Gitlab
::
Mark
up
Helper
.
previewable?
(
filename
)
'Preview'
'Preview'
else
else
'Preview changes'
'Preview changes'
...
...
app/helpers/tree_helper.rb
View file @
9c642776
...
@@ -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
...
...
app/models/tree.rb
View file @
9c642776
class
Tree
class
Tree
include
Gitlab
::
Mark
down
Helper
include
Gitlab
::
Mark
up
Helper
attr_accessor
:repository
,
:sha
,
:path
,
:entries
attr_accessor
:repository
,
:sha
,
:path
,
:entries
def
initialize
(
repository
,
sha
,
path
=
'/'
)
def
initialize
(
repository
,
sha
,
path
=
'/'
)
path
=
'/'
if
path
.
blank?
path
=
'/'
if
path
.
blank?
@repository
=
repository
@repository
=
repository
@sha
=
sha
@sha
=
sha
@path
=
path
@path
=
path
...
@@ -20,7 +20,7 @@ class Tree
...
@@ -20,7 +20,7 @@ class Tree
available_readmes
=
blobs
.
select
(
&
:readme?
)
available_readmes
=
blobs
.
select
(
&
:readme?
)
if
available_readmes
.
count
==
0
if
available_readmes
.
count
==
0
return
@readme
=
nil
return
@readme
=
nil
end
end
# Take the first previewable readme, or the first available readme, if we
# Take the first previewable readme, or the first available readme, if we
...
...
app/views/projects/blob/_text.html.haml
View file @
9c642776
-
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
...
...
app/views/search/results/_snippet_blob.html.haml
View file @
9c642776
...
@@ -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?
...
...
app/views/shared/snippets/_blob.html.haml
View file @
9c642776
-
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
...
...
lib/gitlab/mark
down
_helper.rb
→
lib/gitlab/mark
up
_helper.rb
View file @
9c642776
module
Gitlab
module
Gitlab
module
Mark
down
Helper
module
Mark
up
Helper
module_function
module_function
# Public: Determines if a given filename is compatible with GitHub::Markup.
# Public: Determines if a given filename is compatible with GitHub::Markup.
...
@@ -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
spec/helpers/application_helper_spec.rb
View file @
9c642776
...
@@ -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'
)
...
...
spec/lib/gitlab/
gitlab_markdown
_helper_spec.rb
→
spec/lib/gitlab/
markup
_helper_spec.rb
View file @
9c642776
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Mark
down
Helper
do
describe
Gitlab
::
Mark
up
Helper
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
::
Mark
down
Helper
.
markup?
(
"README.
#{
type
}
"
)).
to
be_truthy
expect
(
Gitlab
::
Mark
up
Helper
.
markup?
(
"README.
#{
type
}
"
)).
to
be_truthy
end
end
end
end
it
'returns false when given a non-markup filename'
do
it
'returns false when given a non-markup filename'
do
expect
(
Gitlab
::
Mark
down
Helper
.
markup?
(
'README.rb'
)).
not_to
be_truthy
expect
(
Gitlab
::
Mark
up
Helper
.
markup?
(
'README.rb'
)).
not_to
be_truthy
end
end
end
end
describe
'#gitlab_markdown?'
do
describe
'#gitlab_markdown?'
do
%w(mdown md markdown)
.
each
do
|
type
|
%w(mdown md markdown)
.
each
do
|
type
|
it
"returns true for
#{
type
}
files"
do
it
"returns true for
#{
type
}
files"
do
expect
(
Gitlab
::
Mark
down
Helper
.
gitlab_markdown?
(
"README.
#{
type
}
"
)).
to
be_truthy
expect
(
Gitlab
::
Mark
up
Helper
.
gitlab_markdown?
(
"README.
#{
type
}
"
)).
to
be_truthy
end
end
end
end
it
'returns false when given a non-markdown filename'
do
it
'returns false when given a non-markdown filename'
do
expect
(
Gitlab
::
Mark
down
Helper
.
gitlab_markdown?
(
'README.rb'
)).
not_to
be_truthy
expect
(
Gitlab
::
Mark
up
Helper
.
gitlab_markdown?
(
'README.rb'
)).
not_to
be_truthy
end
end
end
end
describe
'#asciidoc?'
do
describe
'#asciidoc?'
do
%w(adoc ad asciidoc ADOC)
.
each
do
|
type
|
%w(adoc ad asciidoc ADOC)
.
each
do
|
type
|
it
"returns true for
#{
type
}
files"
do
it
"returns true for
#{
type
}
files"
do
expect
(
Gitlab
::
Mark
down
Helper
.
asciidoc?
(
"README.
#{
type
}
"
)).
to
be_truthy
expect
(
Gitlab
::
Mark
up
Helper
.
asciidoc?
(
"README.
#{
type
}
"
)).
to
be_truthy
end
end
end
end
it
'returns false when given a non-asciidoc filename'
do
it
'returns false when given a non-asciidoc filename'
do
expect
(
Gitlab
::
Mark
down
Helper
.
asciidoc?
(
'README.rb'
)).
not_to
be_truthy
expect
(
Gitlab
::
Mark
up
Helper
.
asciidoc?
(
'README.rb'
)).
not_to
be_truthy
end
end
end
end
end
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