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
92783eae
Commit
92783eae
authored
Apr 25, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor `UserReferenceFilter#user_link_filter`
parent
9d3a1d00
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
35 deletions
+43
-35
lib/gitlab/markdown/user_reference_filter.rb
lib/gitlab/markdown/user_reference_filter.rb
+43
-35
No files found.
lib/gitlab/markdown/user_reference_filter.rb
View file @
92783eae
...
@@ -38,34 +38,11 @@ module Gitlab
...
@@ -38,34 +38,11 @@ module Gitlab
# Returns a String with `@user` references replaced with links. All links
# Returns a String with `@user` references replaced with links. All links
# have `gfm` and `gfm-project_member` class names attached for styling.
# have `gfm` and `gfm-project_member` class names attached for styling.
def
user_link_filter
(
text
)
def
user_link_filter
(
text
)
project
=
context
[
:project
]
self
.
class
.
references_in
(
text
)
do
|
match
,
username
|
if
username
==
'all'
self
.
class
.
references_in
(
text
)
do
|
match
,
user
|
link_to_all
klass
=
reference_class
(
:project_member
)
elsif
namespace
=
Namespace
.
find_by
(
path:
username
)
link_to_namespace
(
namespace
)
||
match
if
user
==
'all'
# FIXME (rspeicher): Law of Demeter
push_result
(
:user
,
*
project
.
team
.
members
.
flatten
)
url
=
link_to_all
(
project
)
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
elsif
namespace
=
Namespace
.
find_by
(
path:
user
)
if
namespace
.
is_a?
(
Group
)
if
user_can_reference_group?
(
namespace
)
push_result
(
:user
,
*
namespace
.
users
)
url
=
group_url
(
user
,
only_path:
context
[
:only_path
])
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
else
match
end
else
push_result
(
:user
,
namespace
.
owner
)
url
=
user_url
(
user
,
only_path:
context
[
:only_path
])
%(<a href="#{url}" class="#{klass}">@#{user}</a>)
end
else
else
match
match
end
end
...
@@ -78,17 +55,48 @@ module Gitlab
...
@@ -78,17 +55,48 @@ module Gitlab
Rails
.
application
.
routes
.
url_helpers
Rails
.
application
.
routes
.
url_helpers
end
end
def
group_url
(
*
args
)
def
link_class
urls
.
group_url
(
*
args
)
reference_class
(
:project_member
)
end
end
def
user_url
(
*
args
)
def
link_to_all
urls
.
user_url
(
*
args
)
project
=
context
[
:project
]
# FIXME (rspeicher): Law of Demeter
push_result
(
:user
,
*
project
.
team
.
members
.
flatten
)
url
=
urls
.
namespace_project_url
(
project
.
namespace
,
project
,
only_path:
context
[
:only_path
])
%(<a href="#{url}" class="#{link_class}">@all</a>)
end
end
def
link_to_all
(
project
)
def
link_to_namespace
(
namespace
)
urls
.
namespace_project_url
(
project
.
namespace
,
project
,
if
namespace
.
is_a?
(
Group
)
only_path:
context
[
:only_path
])
link_to_group
(
namespace
.
path
,
namespace
)
else
link_to_user
(
namespace
.
path
,
namespace
)
end
end
def
link_to_group
(
group
,
namespace
)
if
user_can_reference_group?
(
namespace
)
push_result
(
:user
,
*
namespace
.
users
)
url
=
urls
.
group_url
(
group
,
only_path:
context
[
:only_path
])
%(<a href="#{url}" class="#{link_class}">@#{group}</a>)
else
nil
end
end
def
link_to_user
(
user
,
namespace
)
push_result
(
:user
,
namespace
.
owner
)
url
=
urls
.
user_url
(
user
,
only_path:
context
[
:only_path
])
%(<a href="#{url}" class="#{link_class}">@#{user}</a>)
end
end
def
user_can_reference_group?
(
group
)
def
user_can_reference_group?
(
group
)
...
...
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