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
8917db41
Commit
8917db41
authored
Aug 25, 2020
by
derek-knox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update parse_source_file w/read/write of front matter
parent
a54aaa00
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
3 deletions
+48
-3
app/assets/javascripts/static_site_editor/services/parse_source_file.js
...ascripts/static_site_editor/services/parse_source_file.js
+11
-2
spec/frontend/static_site_editor/services/parse_source_file_spec.js
...end/static_site_editor/services/parse_source_file_spec.js
+37
-1
No files found.
app/assets/javascripts/static_site_editor/services/parse_source_file.js
View file @
8917db41
...
...
@@ -30,7 +30,7 @@ const parseSourceFile = raw => {
editable
=
parse
(
editable
.
raw
);
};
const
syncBodyTo
Raw
=
()
=>
{
const
refreshEditable
Raw
=
()
=>
{
editable
.
raw
=
`
${
editable
.
header
}${
editable
.
spacing
}${
editable
.
body
}
`
;
};
...
...
@@ -39,12 +39,19 @@ const parseSourceFile = raw => {
editable
[
editableKey
]
=
newVal
;
if
(
isBodyToRaw
)
{
syncBodyTo
Raw
();
refreshEditable
Raw
();
}
syncEditable
();
};
const
frontMatter
=
()
=>
editable
.
header
;
const
setFrontMatter
=
val
=>
{
editable
.
header
=
val
;
refreshEditableRaw
();
};
const
content
=
(
isBody
=
false
)
=>
{
const
editableKey
=
isBody
?
'
body
'
:
'
raw
'
;
return
editable
[
editableKey
];
...
...
@@ -56,6 +63,8 @@ const parseSourceFile = raw => {
editable
=
parse
(
raw
);
return
{
frontMatter
,
setFrontMatter
,
content
,
isModified
,
sync
,
...
...
spec/frontend/static_site_editor/services/parse_source_file_spec.js
View file @
8917db41
import
{
sourceContent
as
content
,
sourceContentBody
as
body
}
from
'
../mock_data
'
;
import
{
sourceContent
as
content
,
sourceContentHeader
as
frontMatter
,
sourceContentBody
as
body
,
}
from
'
../mock_data
'
;
import
parseSourceFile
from
'
~/static_site_editor/services/parse_source_file
'
;
...
...
@@ -9,6 +13,16 @@ describe('parseSourceFile', () => {
const
newContent
=
`
${
content
}
${
edit
}
`
;
const
newContentComplex
=
`
${
contentComplex
}
${
edit
}
`
;
describe
(
'
unmodified front matter
'
,
()
=>
{
it
.
each
`
parsedSource
${
parseSourceFile
(
content
)}
${
parseSourceFile
(
contentComplex
)}
`
(
'
returns the correct front matter when queried
'
,
({
parsedSource
})
=>
{
expect
(
parsedSource
.
frontMatter
()).
toBe
(
frontMatter
);
});
});
describe
(
'
unmodified content
'
,
()
=>
{
it
.
each
`
parsedSource
...
...
@@ -34,6 +48,28 @@ describe('parseSourceFile', () => {
);
});
describe
(
'
modified front matter
'
,
()
=>
{
const
newFrontMatter
=
'
---
\n
newKey: newVal
\n
---
'
;
const
contentWithNewFrontMatter
=
content
.
replace
(
frontMatter
,
newFrontMatter
);
const
contentComplexWithNewFrontMatter
=
contentComplex
.
replace
(
frontMatter
,
newFrontMatter
);
it
.
each
`
parsedSource | targetContent
${
parseSourceFile
(
content
)}
|
${
contentWithNewFrontMatter
}
${
parseSourceFile
(
contentComplex
)}
|
${
contentComplexWithNewFrontMatter
}
`
(
'
returns the correct front matter and modified content
'
,
({
parsedSource
,
targetContent
})
=>
{
expect
(
parsedSource
.
frontMatter
()).
toBe
(
frontMatter
);
parsedSource
.
setFrontMatter
(
newFrontMatter
);
expect
(
parsedSource
.
frontMatter
()).
toBe
(
newFrontMatter
);
expect
(
parsedSource
.
content
()).
toBe
(
targetContent
);
},
);
});
describe
(
'
modified content
'
,
()
=>
{
const
newBody
=
`
${
body
}
${
edit
}
`
;
const
newComplexBody
=
`
${
complexBody
}
${
edit
}
`
;
...
...
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