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
c10684ed
Commit
c10684ed
authored
May 31, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code nav: Accept tokens instead of raw HTML on FE
It's a safer and more natural approach
parent
9b596143
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
4 deletions
+64
-4
app/assets/javascripts/code_navigation/components/doc_line.vue
...ssets/javascripts/code_navigation/components/doc_line.vue
+22
-0
app/assets/javascripts/code_navigation/components/popover.vue
...assets/javascripts/code_navigation/components/popover.vue
+3
-2
spec/frontend/code_navigation/components/__snapshots__/popover_spec.js.snap
..._navigation/components/__snapshots__/popover_spec.js.snap
+21
-1
spec/frontend/code_navigation/components/popover_spec.js
spec/frontend/code_navigation/components/popover_spec.js
+18
-1
No files found.
app/assets/javascripts/code_navigation/components/doc_line.vue
0 → 100644
View file @
c10684ed
<
script
>
export
default
{
props
:
{
language
:
{
type
:
String
,
required
:
true
,
},
tokens
:
{
type
:
Array
,
required
:
true
,
},
},
};
</
script
>
<
template
>
<span
class=
"line"
:lang=
"language"
>
<span
v-for=
"(token, tokenIndex) in tokens"
:key=
"tokenIndex"
:class=
"token.class"
>
{{
token
.
value
}}
</span>
</span>
</
template
>
app/assets/javascripts/code_navigation/components/popover.vue
View file @
c10684ed
<
script
>
import
{
GlButton
}
from
'
@gitlab/ui
'
;
import
DocLine
from
'
./doc_line.vue
'
;
export
default
{
components
:
{
GlButton
,
DocLine
,
},
props
:
{
position
:
{
...
...
@@ -83,8 +85,7 @@ export default {
ref=
"code-output"
:class=
"$options.colorScheme"
class=
"border-0 bg-transparent m-0 code highlight"
v-html=
"hover.value"
></pre>
><doc-line
v-for=
"(tokens, tokenIndex) in hover.tokens"
:key=
"tokenIndex"
:language=
"hover.language"
:tokens=
"tokens"
/></pre>
<p
v-else
ref=
"doc-output"
class=
"p-3 m-0"
>
{{
hover
.
value
}}
</p>
...
...
spec/frontend/code_navigation/components/__snapshots__/popover_spec.js.snap
View file @
c10684ed
...
...
@@ -16,7 +16,27 @@ exports[`Code navigation popover component renders popover 1`] = `
<pre
class="border-0 bg-transparent m-0 code highlight"
>
console.log
<span
class="line"
lang="javascript"
>
<span
class="k"
>
function
</span>
<span>
main() {
</span>
</span>
<span
class="line"
lang="javascript"
>
<span>
}
</span>
</span>
</pre>
</div>
...
...
spec/frontend/code_navigation/components/popover_spec.js
View file @
c10684ed
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
Popover
from
'
~/code_navigation/components/popover.vue
'
;
import
DocLine
from
'
~/code_navigation/components/doc_line.vue
'
;
const
DEFINITION_PATH_PREFIX
=
'
http://gitlab.com
'
;
...
...
@@ -7,7 +8,22 @@ const MOCK_CODE_DATA = Object.freeze({
hover
:
[
{
language
:
'
javascript
'
,
value
:
'
console.log
'
,
tokens
:
[
[
{
class
:
'
k
'
,
value
:
'
function
'
,
},
{
value
:
'
main() {
'
,
},
],
[
{
value
:
'
}
'
,
},
],
],
},
],
definition_path
:
'
test.js#L20
'
,
...
...
@@ -28,6 +44,7 @@ let wrapper;
function
factory
({
position
,
data
,
definitionPathPrefix
,
blobPath
=
'
index.js
'
})
{
wrapper
=
shallowMount
(
Popover
,
{
propsData
:
{
position
,
data
,
definitionPathPrefix
,
blobPath
},
stubs
:
{
DocLine
},
});
}
...
...
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