Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jsontoVueBuilder
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Amulya Nagesh Jilla
jsontoVueBuilder
Commits
9aad39ce
Commit
9aad39ce
authored
Nov 23, 2023
by
Amulya Nagesh Jilla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style chnages
parent
db5922f3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
10 deletions
+58
-10
convertingjsontovue.js
convertingjsontovue.js
+37
-3
data.json
data.json
+21
-7
No files found.
convertingjsontovue.js
View file @
9aad39ce
...
@@ -3,6 +3,8 @@ const path = require('path');
...
@@ -3,6 +3,8 @@ const path = require('path');
const
jsonDataPath
=
path
.
join
(
__dirname
,
'data.json'
);
const
jsonDataPath
=
path
.
join
(
__dirname
,
'data.json'
);
const
jsonData
=
require
(
jsonDataPath
);
const
jsonData
=
require
(
jsonDataPath
);
const
templateContent
=
generateTemplate
(
jsonData
);
const
templateContent
=
generateTemplate
(
jsonData
);
const
styles
=
generateStyles
(
jsonData
.
template
,[]);
const
componentCode
=
`
const
componentCode
=
`
<template>
<template>
${
templateContent
}
${
templateContent
}
...
@@ -16,6 +18,8 @@ export default {
...
@@ -16,6 +18,8 @@ export default {
<style scoped>
<style scoped>
${
styles
}
</style>
</style>
`
;
`
;
const
outputFilePath
=
path
.
join
(
__dirname
,
'GeneratedComponent.vue'
);
const
outputFilePath
=
path
.
join
(
__dirname
,
'GeneratedComponent.vue'
);
...
@@ -48,13 +52,11 @@ function generateTemplate(data) {
...
@@ -48,13 +52,11 @@ function generateTemplate(data) {
}
}
function
generateScriptContent
(
scriptData
)
{
function
generateScriptContent
(
scriptData
)
{
console
.
log
(
'scriptData:'
,
scriptData
);
console
.
log
(
'scriptData:'
,
scriptData
);
const
scriptProperties
=
scriptData
.
exportDefault
?
generateDataProperties
(
scriptData
.
exportDefault
)
:
'{}'
;
const
scriptProperties
=
scriptData
.
exportDefault
?
generateDataProperties
(
scriptData
.
exportDefault
)
:
'{}'
;
return
`
return
`
data() {
data() {
return
${
scriptProperties
}
return
${
scriptProperties
}
},
},
// Add other Vue component options here
`
;
`
;
}
}
function
generateDataProperties
(
data
)
{
function
generateDataProperties
(
data
)
{
...
@@ -68,4 +70,36 @@ function generateDataProperties(data) {
...
@@ -68,4 +70,36 @@ function generateDataProperties(data) {
})
})
.
join
(
', '
);
.
join
(
', '
);
return
`{
${
properties
}
}`
;
return
`{
${
properties
}
}`
;
}
}
\ No newline at end of file
function
generateStyles
(
data
)
{
function
traverseStyles
(
data
,
parentSelector
=
''
)
{
let
styles
=
''
;
if
(
data
.
properties
&&
data
.
properties
.
class
&&
data
.
styles
)
{
const
selector
=
parentSelector
?
`
${
parentSelector
}
${
data
.
tagName
}
`
:
data
.
tagName
;
const
classList
=
data
.
properties
.
class
.
split
(
' '
);
styles
+=
`
${
selector
}
{
${
generateStyleProperties
(
data
.
styles
)}
}\n`
;
}
if
(
data
.
children
)
{
data
.
children
.
forEach
(
child
=>
{
styles
+=
traverseStyles
(
child
,
parentSelector
?
`
${
parentSelector
}
${
data
.
tagName
}
`
:
data
.
tagName
);
});
}
return
styles
;
}
function
generateStyleProperties
(
styles
)
{
return
Object
.
entries
(
styles
||
{})
.
map
(([
property
,
value
])
=>
`
${
property
}
:
${
value
}
;`
)
.
join
(
' '
);
}
return
traverseStyles
(
data
);
}
data.json
View file @
9aad39ce
...
@@ -5,6 +5,10 @@
...
@@ -5,6 +5,10 @@
"id"
:
"about"
,
"id"
:
"about"
,
"class"
:
"section section-about section-about-1 pp-scrollable"
"class"
:
"section section-about section-about-1 pp-scrollable"
},
},
"styles"
:
{
"background-color"
:
"#f0f0f0"
,
"padding"
:
"20px"
},
"children"
:
[
"children"
:
[
{
{
"tagName"
:
"assign"
,
"tagName"
:
"assign"
,
...
@@ -39,7 +43,10 @@
...
@@ -39,7 +43,10 @@
{
{
"tagName"
:
"div"
,
"tagName"
:
"div"
,
"properties"
:
{
"properties"
:
{
"class"
:
[
"container"
,
"about-me-text-container"
]
"class"
:
[
"container"
,
"about-me-text-container"
]
},
},
"children"
:
[
"children"
:
[
{
{
...
@@ -50,14 +57,18 @@
...
@@ -50,14 +57,18 @@
"properties"
:
{
"properties"
:
{
"v-if"
:
"user.isAdmin"
"v-if"
:
"user.isAdmin"
},
},
"children"
:
[
"This paragraph will be rendered if the user is an admin."
]
"children"
:
[
"This paragraph will be rendered if the user is an admin."
]
},
},
{
{
"tagName"
:
"div"
,
"tagName"
:
"div"
,
"properties"
:
{
"properties"
:
{
"v-show"
:
"showDetails"
"v-show"
:
"showDetails"
},
},
"children"
:
[
"This div will be shown if showDetails is true."
]
"children"
:
[
"This div will be shown if showDetails is true."
]
},
},
{
{
"tagName"
:
"div"
,
"tagName"
:
"div"
,
...
@@ -67,7 +78,9 @@
...
@@ -67,7 +78,9 @@
"children"
:
[
"children"
:
[
{
{
"tagName"
:
"span"
,
"tagName"
:
"span"
,
"children"
:
[
"{{ item }}"
]
"children"
:
[
"{{ item }}"
]
}
}
]
]
}
}
...
@@ -88,9 +101,10 @@
...
@@ -88,9 +101,10 @@
"user"
:
{
"user"
:
{
"isAdmin"
:
false
"isAdmin"
:
false
},
},
"items"
:
[]
"items"
:
[],
"methods"
:
{},
"created()"
:
{}
}
}
}
}
}
}
}
}
\ No newline at end of file
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