BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
b3276661
Commit
b3276661
authored
May 11, 2015
by
Jakub Jirutka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RelativeLinkFilter: refactor according to suggestions by @tsigo
parent
f7adac87
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
17 deletions
+13
-17
markdown.rb
lib/gitlab/markdown.rb
+0
-1
relative_link_filter.rb
lib/gitlab/markdown/relative_link_filter.rb
+13
-16
No files found.
lib/gitlab/markdown.rb
View file @
b3276661
...
@@ -98,7 +98,6 @@ module Gitlab
...
@@ -98,7 +98,6 @@ module Gitlab
Gitlab
::
Markdown
::
SanitizationFilter
,
Gitlab
::
Markdown
::
SanitizationFilter
,
Gitlab
::
Markdown
::
RelativeLinkFilter
,
Gitlab
::
Markdown
::
RelativeLinkFilter
,
Gitlab
::
Markdown
::
EmojiFilter
,
Gitlab
::
Markdown
::
EmojiFilter
,
Gitlab
::
Markdown
::
TableOfContentsFilter
,
Gitlab
::
Markdown
::
TableOfContentsFilter
,
Gitlab
::
Markdown
::
AutolinkFilter
,
Gitlab
::
Markdown
::
AutolinkFilter
,
...
...
lib/gitlab/markdown/relative_link_filter.rb
View file @
b3276661
require
'html/pipeline/filter'
require
'uri'
require
'uri'
module
Gitlab
module
Gitlab
...
@@ -13,7 +14,7 @@ module Gitlab
...
@@ -13,7 +14,7 @@ module Gitlab
class
RelativeLinkFilter
<
HTML
::
Pipeline
::
Filter
class
RelativeLinkFilter
<
HTML
::
Pipeline
::
Filter
def
call
def
call
if
!
project_wiki
&&
repository
.
try
(
:exists?
)
&&
!
repository
.
empty
?
if
linkable_files
?
doc
.
search
(
'a'
).
each
do
|
el
|
doc
.
search
(
'a'
).
each
do
|
el
|
process_link_attr
el
.
attribute
(
'href'
)
process_link_attr
el
.
attribute
(
'href'
)
end
end
...
@@ -28,6 +29,10 @@ module Gitlab
...
@@ -28,6 +29,10 @@ module Gitlab
protected
protected
def
linkable_files?
context
[
:project_wiki
].
nil?
&&
repository
.
try
(
:exists?
)
&&
!
repository
.
empty?
end
def
process_link_attr
(
html_attr
)
def
process_link_attr
(
html_attr
)
return
if
html_attr
.
blank?
return
if
html_attr
.
blank?
...
@@ -42,7 +47,7 @@ module Gitlab
...
@@ -42,7 +47,7 @@ module Gitlab
uri
.
path
=
[
uri
.
path
=
[
relative_url_root
,
relative_url_root
,
project
.
path_with_namespace
,
context
[
:project
]
.
path_with_namespace
,
path_type
(
file_path
),
path_type
(
file_path
),
ref
||
'master'
,
# assume that if no ref exists we can point to master
ref
||
'master'
,
# assume that if no ref exists we can point to master
file_path
file_path
...
@@ -52,7 +57,7 @@ module Gitlab
...
@@ -52,7 +57,7 @@ module Gitlab
end
end
def
relative_file_path
(
path
)
def
relative_file_path
(
path
)
nested_path
=
build_nested_path
(
path
,
requested_path
)
nested_path
=
build_nested_path
(
path
,
context
[
:requested_path
]
)
file_exists?
(
nested_path
)
?
nested_path
:
path
file_exists?
(
nested_path
)
?
nested_path
:
path
end
end
...
@@ -89,28 +94,20 @@ module Gitlab
...
@@ -89,28 +94,20 @@ module Gitlab
end
end
def
current_sha
def
current_sha
if
commit
context
[
:commit
].
try
(
:id
)
||
commit
.
id
ref
?
repository
.
commit
(
ref
).
try
(:
sha
)
:
repository
.
head_commit
.
sha
elsif
ref
repository
.
commit
(
ref
).
try
(
:sha
)
else
repository
.
head_commit
.
sha
end
end
end
def
relative_url_root
def
relative_url_root
Gitlab
.
config
.
gitlab
.
relative_url_root
.
presence
||
'/'
Gitlab
.
config
.
gitlab
.
relative_url_root
.
presence
||
'/'
end
end
[
:commit
,
:project
,
:project_wiki
,
:requested_path
,
:ref
].
each
do
|
name
|
def
ref
define_method
(
name
)
do
context
[
:ref
]
context
[
name
]
end
end
end
def
repository
def
repository
return
if
project
.
nil?
context
[
:project
].
try
(
:repository
)
project
.
repository
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