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
c06b9ecc
Commit
c06b9ecc
authored
Oct 21, 2020
by
derek-knox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply review feedback
Refactor to hasValidMatter and refactor prior cache in syncContent
parent
ff81c193
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
35 deletions
+17
-35
app/assets/javascripts/static_site_editor/components/edit_area.vue
...s/javascripts/static_site_editor/components/edit_area.vue
+2
-2
app/assets/javascripts/static_site_editor/services/front_matterify.js
...avascripts/static_site_editor/services/front_matterify.js
+1
-16
app/assets/javascripts/static_site_editor/services/parse_source_file.js
...ascripts/static_site_editor/services/parse_source_file.js
+8
-15
spec/frontend/static_site_editor/services/front_matterify_spec.js
...ntend/static_site_editor/services/front_matterify_spec.js
+6
-2
No files found.
app/assets/javascripts/static_site_editor/components/edit_area.vue
View file @
c06b9ecc
...
...
@@ -84,8 +84,8 @@ export default {
const
{
isModified
,
hasMatter
,
isMatterValid
}
=
this
.
parsedSource
;
this
.
isModified
=
isModified
();
this
.
hasMatter
=
hasMatter
();
const
hasValid
atedMatterCondition
=
this
.
hasMatter
?
isMatterValid
()
:
true
;
this
.
isSaveable
=
this
.
isModified
&&
hasValid
atedMatterCondition
;
const
hasValid
Matter
=
this
.
hasMatter
?
isMatterValid
()
:
true
;
this
.
isSaveable
=
this
.
isModified
&&
hasValid
Matter
;
},
onDrawerOpen
()
{
this
.
isDrawerOpen
=
true
;
...
...
app/assets/javascripts/static_site_editor/services/front_matterify.js
View file @
c06b9ecc
...
...
@@ -8,19 +8,6 @@ const hasMatter = (firstThreeChars, fourthChar) => {
return
isYamlDelimiter
&&
isFourthCharNewline
;
};
const
validateMatter
=
matterStr
=>
{
let
isMatterValid
=
true
;
let
matter
;
try
{
matter
=
jsYaml
.
safeLoad
(
matterStr
);
}
catch
(
error
)
{
isMatterValid
=
false
;
}
return
{
matter
,
isMatterValid
};
};
export
const
frontMatterify
=
source
=>
{
let
index
=
3
;
let
offset
;
...
...
@@ -30,7 +17,6 @@ export const frontMatterify = source => {
source
,
matter
:
null
,
hasMatter
:
false
,
isMatterValid
:
false
,
spacing
:
null
,
content
:
source
,
delimiter
:
null
,
...
...
@@ -54,7 +40,7 @@ export const frontMatterify = source => {
}
const
matterStr
=
source
.
slice
(
index
,
offset
);
const
{
matter
,
isMatterValid
}
=
validateMatter
(
matterStr
);
const
matter
=
jsYaml
.
safeLoad
(
matterStr
);
let
content
=
source
.
slice
(
offset
+
delimiter
.
length
);
let
spacing
=
''
;
...
...
@@ -69,7 +55,6 @@ export const frontMatterify = source => {
source
,
matter
,
hasMatter
:
true
,
isMatterValid
,
spacing
,
content
,
delimiter
,
...
...
app/assets/javascripts/static_site_editor/services/parse_source_file.js
View file @
c06b9ecc
import
{
frontMatterify
,
stringify
}
from
'
./front_matterify
'
;
const
parseSourceFile
=
raw
=>
{
const
remake
=
source
=>
frontMatterify
(
source
);
let
editable
=
remake
(
raw
);
let
lastValidMatter
=
null
;
let
editable
;
const
syncContent
=
(
newVal
,
isBody
)
=>
{
if
(
isBody
)
{
editable
.
content
=
newVal
;
}
else
{
// 1. Cache last valid matter to account for mid-edit resulting in matter invalidation
if
(
editable
.
hasMatter
)
{
lastValidMatter
=
editable
.
matter
;
}
// 2. Update editable
editable
=
remake
(
newVal
);
// 3. Use last valid matter cache if mid-edit results in matter invalidation
if
(
!
editable
.
isMatterValid
)
{
editable
.
matter
=
lastValidMatter
;
try
{
editable
=
frontMatterify
(
newVal
);
editable
.
isMatterValid
=
true
;
}
catch
(
e
)
{
editable
.
isMatterValid
=
false
;
}
}
};
...
...
@@ -39,6 +30,8 @@ const parseSourceFile = raw => {
const
isMatterValid
=
()
=>
editable
.
isMatterValid
;
syncContent
(
raw
);
return
{
matter
,
isMatterValid
,
...
...
spec/frontend/static_site_editor/services/front_matterify_spec.js
View file @
c06b9ecc
...
...
@@ -12,7 +12,6 @@ describe('static_site_editor/services/front_matterify', () => {
source
:
content
,
matter
:
yamlFrontMatterObj
,
hasMatter
:
true
,
isMatterValid
:
true
,
spacing
,
content
:
body
,
delimiter
:
'
---
'
,
...
...
@@ -22,7 +21,6 @@ describe('static_site_editor/services/front_matterify', () => {
source
:
body
,
matter
:
null
,
hasMatter
:
false
,
isMatterValid
:
false
,
spacing
:
null
,
content
:
body
,
delimiter
:
null
,
...
...
@@ -37,6 +35,12 @@ describe('static_site_editor/services/front_matterify', () => {
`
(
'
returns $target from $frontMatterified
'
,
({
frontMatterified
,
target
})
=>
{
expect
(
frontMatterified
).
toEqual
(
target
);
});
it
(
'
should throw when matter is invalid
'
,
()
=>
{
const
invalidContent
=
`---\nkey: val\nkeyNoVal\n---\n
${
body
}
`
;
expect
(()
=>
frontMatterify
(
invalidContent
)).
toThrow
();
});
});
describe
(
'
stringify
'
,
()
=>
{
...
...
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