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
Léo-Paul Géneau
gitlab-ce
Commits
3f6d91c5
Commit
3f6d91c5
authored
Jul 10, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Gitlab::StringRegexMarker
parent
e1797078
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
2 deletions
+33
-2
lib/gitlab/string_regex_marker.rb
lib/gitlab/string_regex_marker.rb
+13
-0
spec/lib/gitlab/string_range_marker_spec.rb
spec/lib/gitlab/string_range_marker_spec.rb
+2
-2
spec/lib/gitlab/string_regex_marker_spec.rb
spec/lib/gitlab/string_regex_marker_spec.rb
+18
-0
No files found.
lib/gitlab/string_regex_marker.rb
0 → 100644
View file @
3f6d91c5
module
Gitlab
class
StringRegexMarker
<
StringRangeMarker
def
mark
(
regex
,
group:
0
,
&
block
)
regex_match
=
raw_line
.
match
(
regex
)
return
rich_line
unless
regex_match
begin_index
,
end_index
=
regex_match
.
offset
(
group
)
name_range
=
begin_index
..
(
end_index
-
1
)
super
([
name_range
],
&
block
)
end
end
end
spec/lib/gitlab/string_range_marker_spec.rb
View file @
3f6d91c5
...
...
@@ -6,7 +6,7 @@ describe Gitlab::StringRangeMarker, lib: true do
let
(
:raw
)
{
"abc <def>"
}
let
(
:rich
)
{
%{<span class="abc">abc</span><span class="space"> </span><span class="def"><def></span>}
.
html_safe
}
let
(
:inline_diffs
)
{
[
2
..
5
]
}
let
(
:subject
)
do
subject
do
described_class
.
new
(
raw
,
rich
).
mark
(
inline_diffs
)
do
|
text
,
left
:,
right
:|
"LEFT
#{
text
}
RIGHT"
end
...
...
@@ -21,7 +21,7 @@ describe Gitlab::StringRangeMarker, lib: true do
context
"when the rich text is not html safe"
do
let
(
:raw
)
{
"abc <def>"
}
let
(
:inline_diffs
)
{
[
2
..
5
]
}
let
(
:subject
)
do
subject
do
described_class
.
new
(
raw
).
mark
(
inline_diffs
)
do
|
text
,
left
:,
right
:|
"LEFT
#{
text
}
RIGHT"
end
...
...
spec/lib/gitlab/string_regex_marker_spec.rb
0 → 100644
View file @
3f6d91c5
require
'spec_helper'
describe
Gitlab
::
StringRegexMarker
,
lib:
true
do
describe
'#mark'
do
let
(
:raw
)
{
%{"name": "AFNetworking"}
}
let
(
:rich
)
{
%{<span class="key">"name"</span><span class="punctuation">: </span><span class="value">"AFNetworking"</span>}
.
html_safe
}
subject
do
described_class
.
new
(
raw
,
rich
).
mark
(
/"[^"]+":\s*"(?<name>[^"]+)"/
,
group: :name
)
do
|
text
,
left
:,
right
:|
%{<a href="#">#{text}</a>}
end
end
it
'marks the inline diffs'
do
expect
(
subject
).
to
eq
(
%{<span class="key">"name"</span><span class="punctuation">: </span><span class="value">"<a href="#">AFNetworking</a>"</span>}
)
expect
(
subject
).
to
be_html_safe
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