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
Boxiang Sun
gitlab-ce
Commits
41e40723
Commit
41e40723
authored
May 25, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add regexp_for_value helper method
parent
4ba54780
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
40 deletions
+25
-40
lib/gitlab/dependency_linker/base_linker.rb
lib/gitlab/dependency_linker/base_linker.rb
+13
-0
lib/gitlab/dependency_linker/json_linker.rb
lib/gitlab/dependency_linker/json_linker.rb
+4
-23
lib/gitlab/dependency_linker/method_linker.rb
lib/gitlab/dependency_linker/method_linker.rb
+8
-17
No files found.
lib/gitlab/dependency_linker/base_linker.rb
View file @
41e40723
...
@@ -68,6 +68,19 @@ module Gitlab
...
@@ -68,6 +68,19 @@ module Gitlab
def
highlighted_lines
def
highlighted_lines
@highlighted_lines
||=
highlighted_text
.
lines
@highlighted_lines
||=
highlighted_text
.
lines
end
end
def
regexp_for_value
(
value
,
default:
/[^'"]+/
)
case
value
when
Array
Regexp
.
union
(
value
.
map
{
|
v
|
regexp_for_value
(
v
,
default:
default
)
})
when
String
Regexp
.
escape
(
value
)
when
Regexp
value
else
default
end
end
end
end
end
end
end
end
lib/gitlab/dependency_linker/json_linker.rb
View file @
41e40723
...
@@ -24,32 +24,13 @@ module Gitlab
...
@@ -24,32 +24,13 @@ module Gitlab
# link_json('specific_package', '1.0.1', link: :key)
# link_json('specific_package', '1.0.1', link: :key)
# # Will link `specific_package` in `"specific_package": "1.0.1"`
# # Will link `specific_package` in `"specific_package": "1.0.1"`
def
link_json
(
key
,
value
=
nil
,
link: :value
,
&
url_proc
)
def
link_json
(
key
,
value
=
nil
,
link: :value
,
&
url_proc
)
key
=
key
=
regexp_for_value
(
key
,
default:
/[^"]+/
)
case
key
value
=
regexp_for_value
(
value
,
default:
/[^"]+/
)
when
Array
Regexp
.
union
(
key
.
map
{
|
name
|
Regexp
.
escape
(
name
)
})
when
String
Regexp
.
escape
(
key
)
when
nil
'[^"]+'
else
key
end
value
=
case
value
when
String
Regexp
.
escape
(
value
)
when
nil
'[^"]+'
else
value
end
if
link
==
:value
if
link
==
:value
value
=
"(?<name>
#{
value
}
)"
value
=
/(?<name>
#{
value
}
)/
else
else
key
=
"(?<name>
#{
key
}
)"
key
=
/(?<name>
#{
key
}
)/
end
end
link_regex
(
/"
#{
key
}
":\s*"
#{
value
}
"/
,
&
url_proc
)
link_regex
(
/"
#{
key
}
":\s*"
#{
value
}
"/
,
&
url_proc
)
...
...
lib/gitlab/dependency_linker/method_linker.rb
View file @
41e40723
...
@@ -20,25 +20,16 @@ module Gitlab
...
@@ -20,25 +20,16 @@ module Gitlab
#
#
# link_method_call('name')
# link_method_call('name')
# # Will link `package` in `self.name = "package"`
# # Will link `package` in `self.name = "package"`
def
link_method_call
(
method_names
,
value
=
nil
,
&
url_proc
)
def
link_method_call
(
method_name
,
value
=
nil
,
&
url_proc
)
method_names
=
Array
(
method_names
).
map
{
|
name
|
Regexp
.
escape
(
name
)
}
method_name
=
regexp_for_value
(
method_name
)
value
=
regexp_for_value
(
value
)
value
=
case
value
when
String
Regexp
.
escape
(
value
)
when
nil
/[^'"]+/
else
value
end
regex
=
%r{
regex
=
%r{
#{
Regexp
.
union
(
method_names
)
}
# Method name
#{
method_name
}
# Method name
\s
*
# Whitespace
\s
* # Whitespace
[(=]?
# Opening brace or equals sign
[(=]? # Opening brace or equals sign
\s
*
# Whitespace
\s
* # Whitespace
['"](?<name>
#{
value
}
)['"]
# Package name in quotes
['"](?<name>
#{
value
}
)['"] # Package name in quotes
}x
}x
link_regex
(
regex
,
&
url_proc
)
link_regex
(
regex
,
&
url_proc
)
...
...
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