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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
54d889a6
Commit
54d889a6
authored
Feb 11, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add plain_highlighted_data field to SnippetBlobType
parent
7343c4f2
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
75 additions
and
11 deletions
+75
-11
app/graphql/types/snippets/blob_type.rb
app/graphql/types/snippets/blob_type.rb
+4
-0
app/presenters/snippet_blob_presenter.rb
app/presenters/snippet_blob_presenter.rb
+7
-5
changelogs/unreleased/fj-add-plain-data-field-to-snippet-blob-type-endpoint.yml
...fj-add-plain-data-field-to-snippet-blob-type-endpoint.yml
+5
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+5
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+14
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+1
-0
spec/graphql/types/snippets/blob_type_spec.rb
spec/graphql/types/snippets/blob_type_spec.rb
+3
-4
spec/presenters/snippet_blob_presenter_spec.rb
spec/presenters/snippet_blob_presenter_spec.rb
+36
-2
No files found.
app/graphql/types/snippets/blob_type.rb
View file @
54d889a6
...
...
@@ -12,6 +12,10 @@ module Types
description:
'Blob highlighted data'
,
null:
true
field
:plain_highlighted_data
,
GraphQL
::
STRING_TYPE
,
description:
'Blob plain highlighted data'
,
null:
true
field
:raw_path
,
GraphQL
::
STRING_TYPE
,
description:
'Blob raw content endpoint path'
,
null:
false
...
...
app/presenters/snippet_blob_presenter.rb
View file @
54d889a6
...
...
@@ -4,11 +4,13 @@ class SnippetBlobPresenter < BlobPresenter
def
highlighted_data
return
if
blob
.
binary?
if
blob
.
rich_viewer
&
.
partial_name
==
'markup'
blob
.
rendered_markup
else
highlight
end
highlight
(
plain:
false
)
end
def
plain_highlighted_data
return
if
blob
.
binary?
highlight
(
plain:
true
)
end
def
raw_path
...
...
changelogs/unreleased/fj-add-plain-data-field-to-snippet-blob-type-endpoint.yml
0 → 100644
View file @
54d889a6
---
title
:
Add plain_highlighted_data field to SnippetBlobType
merge_request
:
24856
author
:
type
:
changed
doc/api/graphql/reference/gitlab_schema.graphql
View file @
54d889a6
...
...
@@ -6772,6 +6772,11 @@ type SnippetBlob {
"""
path
:
String
"""
Blob
plain
highlighted
data
"""
plainHighlightedData
:
String
"""
Blob
raw
content
endpoint
path
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
54d889a6
...
...
@@ -7612,6 +7612,20 @@
"isDeprecated"
:
false
,
"deprecationReason"
:
null
},
{
"name"
:
"plainHighlightedData"
,
"description"
:
"Blob plain highlighted data"
,
"args"
:
[
],
"type"
:
{
"kind"
:
"SCALAR"
,
"name"
:
"String"
,
"ofType"
:
null
},
"isDeprecated"
:
false
,
"deprecationReason"
:
null
},
{
"name"
:
"rawPath"
,
"description"
:
"Blob raw content endpoint path"
,
...
...
doc/api/graphql/reference/index.md
View file @
54d889a6
...
...
@@ -1070,6 +1070,7 @@ Represents the snippet blob
|
`mode`
| String | Blob mode |
|
`name`
| String | Blob name |
|
`path`
| String | Blob path |
|
`plainHighlightedData`
| String | Blob plain highlighted data |
|
`rawPath`
| String! | Blob raw content endpoint path |
|
`richViewer`
| SnippetBlobViewer | Blob content rich viewer |
|
`simpleViewer`
| SnippetBlobViewer! | Blob content simple viewer |
...
...
spec/graphql/types/snippets/blob_type_spec.rb
View file @
54d889a6
...
...
@@ -4,10 +4,9 @@ require 'spec_helper'
describe
GitlabSchema
.
types
[
'SnippetBlob'
]
do
it
'has the correct fields'
do
expected_fields
=
[
:highlighted_data
,
:raw_path
,
:size
,
:binary
,
:name
,
:path
,
:simple_viewer
,
:rich_viewer
,
:mode
]
expected_fields
=
[
:highlighted_data
,
:plain_highlighted_data
,
:raw_path
,
:size
,
:binary
,
:name
,
:path
,
:simple_viewer
,
:rich_viewer
,
:mode
]
is_expected
.
to
have_graphql_fields
(
*
expected_fields
)
end
...
...
spec/presenters/snippet_blob_presenter_spec.rb
View file @
54d889a6
...
...
@@ -18,7 +18,7 @@ describe SnippetBlobPresenter do
snippet
.
file_name
=
'test.md'
snippet
.
content
=
'*foo*'
expect
(
subject
).
to
eq
'<
p data-sourcepos="1:1-1:5" dir="auto"><em>foo</em></p
>'
expect
(
subject
).
to
eq
'<
span id="LC1" class="line" lang="markdown"><span class="ge">*foo*</span></span
>'
end
it
'returns syntax highlighted content'
do
...
...
@@ -33,7 +33,41 @@ describe SnippetBlobPresenter do
snippet
.
file_name
=
'test'
snippet
.
content
=
'foo'
expect
(
described_class
.
new
(
snippet
.
blob
).
highlighted_data
).
to
eq
'<span id="LC1" class="line" lang="plaintext">foo</span>'
expect
(
subject
).
to
eq
'<span id="LC1" class="line" lang="plaintext">foo</span>'
end
end
describe
'#plain_highlighted_data'
do
let
(
:snippet
)
{
build
(
:personal_snippet
)
}
subject
{
described_class
.
new
(
snippet
.
blob
).
plain_highlighted_data
}
it
'returns nil when the snippet blob is binary'
do
allow
(
snippet
.
blob
).
to
receive
(
:binary?
).
and_return
(
true
)
expect
(
subject
).
to
be_nil
end
it
'returns plain content when snippet file is markup'
do
snippet
.
file_name
=
'test.md'
snippet
.
content
=
'*foo*'
expect
(
subject
).
to
eq
'<span id="LC1" class="line" lang="">*foo*</span>'
end
it
'returns plain syntax content'
do
snippet
.
file_name
=
'test.rb'
snippet
.
content
=
'class Foo;end'
expect
(
subject
)
.
to
eq
'<span id="LC1" class="line" lang="">class Foo;end</span>'
end
it
'returns plain text highlighted content'
do
snippet
.
file_name
=
'test'
snippet
.
content
=
'foo'
expect
(
subject
).
to
eq
'<span id="LC1" class="line" lang="">foo</span>'
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