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 {
...
@@ -84,8 +84,8 @@ export default {
const
{
isModified
,
hasMatter
,
isMatterValid
}
=
this
.
parsedSource
;
const
{
isModified
,
hasMatter
,
isMatterValid
}
=
this
.
parsedSource
;
this
.
isModified
=
isModified
();
this
.
isModified
=
isModified
();
this
.
hasMatter
=
hasMatter
();
this
.
hasMatter
=
hasMatter
();
const
hasValid
atedMatterCondition
=
this
.
hasMatter
?
isMatterValid
()
:
true
;
const
hasValid
Matter
=
this
.
hasMatter
?
isMatterValid
()
:
true
;
this
.
isSaveable
=
this
.
isModified
&&
hasValid
atedMatterCondition
;
this
.
isSaveable
=
this
.
isModified
&&
hasValid
Matter
;
},
},
onDrawerOpen
()
{
onDrawerOpen
()
{
this
.
isDrawerOpen
=
true
;
this
.
isDrawerOpen
=
true
;
...
...
app/assets/javascripts/static_site_editor/services/front_matterify.js
View file @
c06b9ecc
...
@@ -8,19 +8,6 @@ const hasMatter = (firstThreeChars, fourthChar) => {
...
@@ -8,19 +8,6 @@ const hasMatter = (firstThreeChars, fourthChar) => {
return
isYamlDelimiter
&&
isFourthCharNewline
;
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
=>
{
export
const
frontMatterify
=
source
=>
{
let
index
=
3
;
let
index
=
3
;
let
offset
;
let
offset
;
...
@@ -30,7 +17,6 @@ export const frontMatterify = source => {
...
@@ -30,7 +17,6 @@ export const frontMatterify = source => {
source
,
source
,
matter
:
null
,
matter
:
null
,
hasMatter
:
false
,
hasMatter
:
false
,
isMatterValid
:
false
,
spacing
:
null
,
spacing
:
null
,
content
:
source
,
content
:
source
,
delimiter
:
null
,
delimiter
:
null
,
...
@@ -54,7 +40,7 @@ export const frontMatterify = source => {
...
@@ -54,7 +40,7 @@ export const frontMatterify = source => {
}
}
const
matterStr
=
source
.
slice
(
index
,
offset
);
const
matterStr
=
source
.
slice
(
index
,
offset
);
const
{
matter
,
isMatterValid
}
=
validateMatter
(
matterStr
);
const
matter
=
jsYaml
.
safeLoad
(
matterStr
);
let
content
=
source
.
slice
(
offset
+
delimiter
.
length
);
let
content
=
source
.
slice
(
offset
+
delimiter
.
length
);
let
spacing
=
''
;
let
spacing
=
''
;
...
@@ -69,7 +55,6 @@ export const frontMatterify = source => {
...
@@ -69,7 +55,6 @@ export const frontMatterify = source => {
source
,
source
,
matter
,
matter
,
hasMatter
:
true
,
hasMatter
:
true
,
isMatterValid
,
spacing
,
spacing
,
content
,
content
,
delimiter
,
delimiter
,
...
...
app/assets/javascripts/static_site_editor/services/parse_source_file.js
View file @
c06b9ecc
import
{
frontMatterify
,
stringify
}
from
'
./front_matterify
'
;
import
{
frontMatterify
,
stringify
}
from
'
./front_matterify
'
;
const
parseSourceFile
=
raw
=>
{
const
parseSourceFile
=
raw
=>
{
const
remake
=
source
=>
frontMatterify
(
source
);
let
editable
;
let
editable
=
remake
(
raw
);
let
lastValidMatter
=
null
;
const
syncContent
=
(
newVal
,
isBody
)
=>
{
const
syncContent
=
(
newVal
,
isBody
)
=>
{
if
(
isBody
)
{
if
(
isBody
)
{
editable
.
content
=
newVal
;
editable
.
content
=
newVal
;
}
else
{
}
else
{
// 1. Cache last valid matter to account for mid-edit resulting in matter invalidation
try
{
if
(
editable
.
hasMatter
)
{
editable
=
frontMatterify
(
newVal
);
lastValidMatter
=
editable
.
matter
;
editable
.
isMatterValid
=
true
;
}
}
catch
(
e
)
{
editable
.
isMatterValid
=
false
;
// 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
;
}
}
}
}
};
};
...
@@ -39,6 +30,8 @@ const parseSourceFile = raw => {
...
@@ -39,6 +30,8 @@ const parseSourceFile = raw => {
const
isMatterValid
=
()
=>
editable
.
isMatterValid
;
const
isMatterValid
=
()
=>
editable
.
isMatterValid
;
syncContent
(
raw
);
return
{
return
{
matter
,
matter
,
isMatterValid
,
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', () => {
...
@@ -12,7 +12,6 @@ describe('static_site_editor/services/front_matterify', () => {
source
:
content
,
source
:
content
,
matter
:
yamlFrontMatterObj
,
matter
:
yamlFrontMatterObj
,
hasMatter
:
true
,
hasMatter
:
true
,
isMatterValid
:
true
,
spacing
,
spacing
,
content
:
body
,
content
:
body
,
delimiter
:
'
---
'
,
delimiter
:
'
---
'
,
...
@@ -22,7 +21,6 @@ describe('static_site_editor/services/front_matterify', () => {
...
@@ -22,7 +21,6 @@ describe('static_site_editor/services/front_matterify', () => {
source
:
body
,
source
:
body
,
matter
:
null
,
matter
:
null
,
hasMatter
:
false
,
hasMatter
:
false
,
isMatterValid
:
false
,
spacing
:
null
,
spacing
:
null
,
content
:
body
,
content
:
body
,
delimiter
:
null
,
delimiter
:
null
,
...
@@ -37,6 +35,12 @@ describe('static_site_editor/services/front_matterify', () => {
...
@@ -37,6 +35,12 @@ describe('static_site_editor/services/front_matterify', () => {
`
(
'
returns $target from $frontMatterified
'
,
({
frontMatterified
,
target
})
=>
{
`
(
'
returns $target from $frontMatterified
'
,
({
frontMatterified
,
target
})
=>
{
expect
(
frontMatterified
).
toEqual
(
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
'
,
()
=>
{
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