Commit 7809c533 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'fj-add-plain-data-field-to-snippet-blob-type-endpoint' into 'master'

Add plain_highlighted_data field to SnippetBlobType

See merge request gitlab-org/gitlab!24856
parents 1e72da63 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
......
......@@ -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
highlight(plain: false)
end
def plain_highlighted_data
return if blob.binary?
highlight(plain: true)
end
def raw_path
......
---
title: Add plain_highlighted_data field to SnippetBlobType
merge_request: 24856
author:
type: changed
......@@ -6777,6 +6777,11 @@ type SnippetBlob {
"""
path: String
"""
Blob plain highlighted data
"""
plainHighlightedData: String
"""
Blob raw content endpoint path
"""
......
......@@ -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",
......
......@@ -1071,6 +1071,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 |
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment