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
Kazuhiko Shiozaki
gitlab-ce
Commits
505203e7
Commit
505203e7
authored
Aug 11, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7466 from Razer6/improve_markup_handling
Improve readme markup, fixes #7455
parents
ddd238ef
d7701a26
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
94 additions
and
44 deletions
+94
-44
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+10
-0
app/helpers/tree_helper.rb
app/helpers/tree_helper.rb
+10
-18
app/models/tree.rb
app/models/tree.rb
+19
-1
app/views/projects/edit_tree/preview.html.haml
app/views/projects/edit_tree/preview.html.haml
+1
-1
app/views/projects/tree/_readme.html.haml
app/views/projects/tree/_readme.html.haml
+1
-8
lib/gitlab/markdown_helper.rb
lib/gitlab/markdown_helper.rb
+25
-0
spec/helpers/tree_helper_spec.rb
spec/helpers/tree_helper_spec.rb
+0
-16
spec/lib/gitlab/gitlab_markdown_helper_spec.rb
spec/lib/gitlab/gitlab_markdown_helper_spec.rb
+28
-0
No files found.
app/helpers/application_helper.rb
View file @
505203e7
...
...
@@ -222,6 +222,16 @@ module ApplicationHelper
def
render_markup
(
file_name
,
file_content
)
GitHub
::
Markup
.
render
(
file_name
,
file_content
).
html_safe
rescue
RuntimeError
simple_format
(
file_content
)
end
def
markup?
(
filename
)
Gitlab
::
MarkdownHelper
.
markup?
(
filename
)
end
def
gitlab_markdown?
(
filename
)
Gitlab
::
MarkdownHelper
.
gitlab_markdown?
(
filename
)
end
def
spinner
(
text
=
nil
,
visible
=
false
)
...
...
app/helpers/tree_helper.rb
View file @
505203e7
...
...
@@ -21,6 +21,16 @@ module TreeHelper
tree
.
html_safe
end
def
render_readme
(
readme
)
if
gitlab_markdown?
(
readme
.
name
)
preserve
(
markdown
(
readme
.
data
))
elsif
markup?
(
readme
.
name
)
render_markup
(
readme
.
name
,
readme
.
data
)
else
simple_format
(
readme
.
data
)
end
end
# Return an image icon depending on the file type
#
# type - String type of the tree item; either 'folder' or 'file'
...
...
@@ -38,24 +48,6 @@ module TreeHelper
"file_
#{
hexdigest
(
content
.
name
)
}
"
end
# Public: Determines if a given filename is compatible with GitHub::Markup.
#
# filename - Filename string to check
#
# Returns boolean
def
markup?
(
filename
)
filename
.
downcase
.
end_with?
(
*
%w(.textile .rdoc .org .creole .wiki .mediawiki
.rst .adoc .asciidoc .asc)
)
end
def
gitlab_markdown?
(
filename
)
filename
.
downcase
.
end_with?
(
*
%w(.mdown .md .markdown)
)
end
def
plain_text_readme?
filename
filename
=~
/^README(.txt)?$/i
end
# Simple shortcut to File.join
def
tree_join
(
*
args
)
File
.
join
(
*
args
)
...
...
app/models/tree.rb
View file @
505203e7
class
Tree
include
Gitlab
::
MarkdownHelper
attr_accessor
:entries
,
:readme
,
:contribution_guide
def
initialize
(
repository
,
sha
,
path
=
'/'
)
...
...
@@ -6,7 +8,23 @@ class Tree
git_repo
=
repository
.
raw_repository
@entries
=
Gitlab
::
Git
::
Tree
.
where
(
git_repo
,
sha
,
path
)
if
readme_tree
=
@entries
.
find
(
&
:readme?
)
available_readmes
=
@entries
.
select
(
&
:readme?
)
if
available_readmes
.
count
>
0
# If there is more than 1 readme in tree, find readme which is supported
# by markup renderer.
if
available_readmes
.
length
>
1
supported_readmes
=
available_readmes
.
select
do
|
readme
|
gitlab_markdown?
(
readme
.
name
)
||
markup?
(
readme
.
name
)
end
# Take the first supported readme, or the first available readme, if we
# don't support any of them
readme_tree
=
supported_readmes
.
first
||
available_readmes
.
first
else
readme_tree
=
available_readmes
.
first
end
readme_path
=
path
==
'/'
?
readme_tree
.
name
:
File
.
join
(
path
,
readme_tree
.
name
)
@readme
=
Gitlab
::
Git
::
Blob
.
find
(
git_repo
,
sha
,
readme_path
)
end
...
...
app/views/projects/edit_tree/preview.html.haml
View file @
505203e7
...
...
@@ -6,7 +6,7 @@
=
markdown
(
@content
)
-
elsif
markup?
(
@blob
.
name
)
.file-content.wiki
=
raw
GitHub
::
Markup
.
render
(
@blob
.
name
,
@content
)
=
raw
render_markup
(
@blob
.
name
,
@content
)
-
else
.file-content.code
-
unless
@diff
.
empty?
...
...
app/views/projects/tree/_readme.html.haml
View file @
505203e7
...
...
@@ -3,11 +3,4 @@
%i
.icon-file
=
readme
.
name
.wiki
-
if
gitlab_markdown?
(
readme
.
name
)
=
preserve
do
=
markdown
(
readme
.
data
)
-
elsif
plain_text_readme?
(
readme
.
name
)
%pre
.clean
=
readme
.
data
-
elsif
markup?
(
readme
.
name
)
=
render_markup
(
readme
.
name
,
readme
.
data
)
=
render_readme
(
readme
)
lib/gitlab/markdown_helper.rb
0 → 100644
View file @
505203e7
module
Gitlab
module
MarkdownHelper
module_function
# Public: Determines if a given filename is compatible with GitHub::Markup.
#
# filename - Filename string to check
#
# Returns boolean
def
markup?
(
filename
)
filename
.
downcase
.
end_with?
(
*
%w(.textile .rdoc .org .creole .wiki
.mediawiki .rst .adoc .asciidoc .asc)
)
end
# Public: Determines if a given filename is compatible with
# GitLab-flavored Markdown.
#
# filename - Filename string to check
#
# Returns boolean
def
gitlab_markdown?
(
filename
)
filename
.
downcase
.
end_with?
(
*
%w(.mdown .md .markdown)
)
end
end
end
spec/helpers/tree_helper_spec.rb
deleted
100644 → 0
View file @
ddd238ef
require
'spec_helper'
describe
TreeHelper
do
describe
'#markup?'
do
%w(textile rdoc org creole wiki mediawiki
rst adoc asciidoc asc)
.
each
do
|
type
|
it
"returns true for
#{
type
}
files"
do
markup?
(
"README.
#{
type
}
"
).
should
be_true
end
end
it
"returns false when given a non-markup filename"
do
markup?
(
'README.rb'
).
should_not
be_true
end
end
end
spec/lib/gitlab/gitlab_markdown_helper_spec.rb
0 → 100644
View file @
505203e7
require
'spec_helper'
describe
Gitlab
::
MarkdownHelper
do
describe
'#markup?'
do
%w(textile rdoc org creole wiki
mediawiki rst adoc asciidoc asc)
.
each
do
|
type
|
it
"returns true for
#{
type
}
files"
do
Gitlab
::
MarkdownHelper
.
markup?
(
"README.
#{
type
}
"
).
should
be_true
end
end
it
'returns false when given a non-markup filename'
do
Gitlab
::
MarkdownHelper
.
markup?
(
'README.rb'
).
should_not
be_true
end
end
describe
'#gitlab_markdown?'
do
%w(mdown md markdown)
.
each
do
|
type
|
it
"returns true for
#{
type
}
files"
do
Gitlab
::
MarkdownHelper
.
gitlab_markdown?
(
"README.
#{
type
}
"
).
should
be_true
end
end
it
'returns false when given a non-markdown filename'
do
Gitlab
::
MarkdownHelper
.
gitlab_markdown?
(
'README.rb'
).
should_not
be_true
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