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
291358d5
Commit
291358d5
authored
Nov 22, 2023
by
Amulya Nagesh Jilla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feature branch initial commit
parent
a9217ba7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
184 additions
and
244 deletions
+184
-244
GeneratedComponent.vue
GeneratedComponent.vue
+8
-11
convertingjsontovue.js
convertingjsontovue.js
+35
-171
data.json
data.json
+88
-62
sample.ftl
sample.ftl
+22
-0
sample.json
sample.json
+31
-0
No files found.
GeneratedComponent.vue
View file @
291358d5
<
template
>
<
template
>
<section
id=
"about"
class=
"section section-about section-about-1 pp-scrollable"
><div
class=
"full-screen"
><div
class=
"display-center"
><div
class=
"section-title-1"
><div
class=
"container,about-me-text-container"
><div></div>
<section
id=
"about"
class=
"section section-about section-about-1 pp-scrollable"
><assign
name=
"user anme"
></assign>
<assign
htmlstring=
"user anme"
></assign>
<div
class=
"full-screen"
><div
class=
"display-center"
><div
class=
"section-title-1"
><div
class=
"container,about-me-text-container"
><div></div>
<p
v-if=
"user.isAdmin"
>
This paragraph will be rendered if the user is an admin.
</p>
<p
v-if=
"user.isAdmin"
>
This paragraph will be rendered if the user is an admin.
</p>
<div
v-show=
"showDetails"
>
This div will be shown if showDetails is true.
</div>
<div
v-show=
"showDetails"
>
This div will be shown if showDetails is true.
</div>
<div
v-for=
"(item, index) in items"
><span>
{{
item
}}
</span></div></div></div></div></div></section>
<div
v-for=
"(item, index) in items"
><span>
{{
item
}}
</span></div></div></div></div></div></section>
...
@@ -8,18 +10,13 @@
...
@@ -8,18 +10,13 @@
<
script
>
<
script
>
export
default
{
export
default
{
data
()
{
data
()
{
return
{
return
{
data
:
{
showDetails
:
false
,
user
:
{
isAdmin
:
false
},
items
:
[]}}
class
:
"full-screen"
,
},
tagName
:
"section"
,
// Add other Vue component options here
properties
:
{
"id"
:
"about"
,
"class"
:
"section section-about section-about-1 pp-scrollable"
},
children
:
[
],
};
}
};
};
</
script
>
</
script
>
<
style
scoped
>
<
style
scoped
>
...
...
convertingjsontovue.js
View file @
291358d5
// const fs = require('fs');
// const path = require('path');
// const jsonDataPath = path.join(__dirname, 'data.json');
// const jsonData = require(jsonDataPath);
// const templateContent = generateTemplate(jsonData);
// const componentCode = `
// <template>
// ${templateContent}
// </template>
// <script>
// export default {
// data() {
// return {
// };
// }
// };
// </script>
// <style scoped>
// </style>
// `;
// const outputFilePath = path.join(__dirname, 'GeneratedComponent.vue');
// fs.writeFileSync(outputFilePath, componentCode);
// console.log(`Vue component generated successfully at ${outputFilePath}`);
// function generateTemplate(jsonData) {
// function generateTemplateRecursive(data) {
// if (typeof data === 'string') {
// return data;
// } else if (Array.isArray(data)) {
// return data.map(generateTemplateRecursive).join('\n');
// } else if (typeof data === 'object') {
// const tagName = data.tagName || 'div';
// const properties = data.properties
// ? ' ' + Object.entries(data.properties)
// .map(([key, value]) => `${key}="${value}"`)
// .join(' ')
// : '';
// const directives = [];
// if (data.vIf && shouldIncludeDirective(data.vIf)) {
// directives.push(`v-if="${data.vIf}"`);
// }
// if (data.vShow && shouldIncludeDirective(data.vShow)) {
// directives.push(`v-show="${data.vShow}"`);
// }
// if (data.vFor && shouldIncludeDirective(data.vFor)) {
// directives.push(`v-for="${data.vFor}"`);
// }
// const directiveString = directives.length > 0 ? ` ${directives.join(' ')}` : '';
// const children = data.children ? generateTemplateRecursive(data.children) : '';
// return `<${tagName}${properties}${directiveString}>${children}</${tagName}>`;
// } else {
// return String(data);
// }
// }
// function shouldIncludeDirective(directive) {
// return true;
// }
// return `${generateTemplateRecursive(jsonData)}`;
// }
const
fs
=
require
(
'fs'
);
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
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
,
scriptContent
}
=
generateTemplate
(
jsonData
);
const
templateContent
=
generateTemplate
(
jsonData
);
const
componentCode
=
`
const
componentCode
=
`
<template>
<template>
...
@@ -109,7 +13,9 @@ const componentCode = `
...
@@ -109,7 +13,9 @@ const componentCode = `
</template>
</template>
<script>
<script>
${
scriptContent
}
export default {
${
generateScriptContent
(
jsonData
.
script
)}
};
</script>
</script>
<style scoped>
<style scoped>
...
@@ -122,8 +28,7 @@ fs.writeFileSync(outputFilePath, componentCode);
...
@@ -122,8 +28,7 @@ fs.writeFileSync(outputFilePath, componentCode);
console
.
log
(
`Vue component generated successfully at
${
outputFilePath
}
`
);
console
.
log
(
`Vue component generated successfully at
${
outputFilePath
}
`
);
function
generateTemplate
(
jsonData
)
{
function
generateTemplate
(
data
)
{
function
generateTemplateRecursive
(
data
)
{
function
generateTemplateRecursive
(
data
)
{
if
(
typeof
data
===
'string'
)
{
if
(
typeof
data
===
'string'
)
{
return
data
;
return
data
;
...
@@ -137,16 +42,9 @@ function generateTemplate(jsonData) {
...
@@ -137,16 +42,9 @@ function generateTemplate(jsonData) {
.
join
(
' '
)
.
join
(
' '
)
:
''
;
:
''
;
const
directives
=
[];
const
directives
=
Object
.
entries
(
data
)
if
(
data
.
vIf
&&
shouldIncludeDirective
(
data
.
vIf
))
{
.
filter
(([
key
])
=>
key
.
startsWith
(
'v-'
))
directives
.
push
(
`v-if="
${
data
.
vIf
}
"`
);
.
map
(([
key
,
value
])
=>
`
${
key
}
="
${
value
}
"`
);
}
if
(
data
.
vShow
&&
shouldIncludeDirective
(
data
.
vShow
))
{
directives
.
push
(
`v-show="
${
data
.
vShow
}
"`
);
}
if
(
data
.
vFor
&&
shouldIncludeDirective
(
data
.
vFor
))
{
directives
.
push
(
`v-for="
${
data
.
vFor
}
"`
);
}
const
directiveString
=
directives
.
length
>
0
?
`
${
directives
.
join
(
' '
)}
`
:
''
;
const
directiveString
=
directives
.
length
>
0
?
`
${
directives
.
join
(
' '
)}
`
:
''
;
const
children
=
data
.
children
?
generateTemplateRecursive
(
data
.
children
)
:
''
;
const
children
=
data
.
children
?
generateTemplateRecursive
(
data
.
children
)
:
''
;
...
@@ -157,67 +55,33 @@ function generateTemplate(jsonData) {
...
@@ -157,67 +55,33 @@ function generateTemplate(jsonData) {
}
}
}
}
function
shouldIncludeDirective
(
directive
)
{
return
`
${
generateTemplateRecursive
(
data
.
template
)}
`
;
}
return
true
;
}
function
generateScriptContent
(
data
)
{
let
scriptData
=
`export default {\n data() {\n`
;
function
processScriptProperties
(
data
)
{
if
(
typeof
data
===
'object'
)
{
scriptData
+=
' return {
\
n'
;
if
(
data
.
children
)
{
function
generateScriptContent
(
scriptData
)
{
data
.
children
.
forEach
(
child
=>
{
console
.
log
(
'scriptData:'
,
scriptData
);
if
(
child
.
properties
&&
typeof
child
.
properties
===
'object'
)
{
// const scriptProperties = generateDataProperties(scriptData.exportDefault);
Object
.
entries
(
child
.
properties
).
forEach
(([
key
,
value
])
=>
{
const
scriptProperties
=
scriptData
.
exportDefault
?
generateDataProperties
(
scriptData
.
exportDefault
)
:
'{}'
;
if
(
!
scriptData
.
includes
(
`
${
key
}
:`
))
{
scriptData
+=
`
${
key
}
:
${
JSON
.
stringify
(
value
)}
,\n`
;
}
});
}
});
}
Object
.
entries
(
data
).
forEach
(([
key
,
value
])
=>
{
if
(
key
===
'children'
)
{
scriptData
+=
`
${
key
}
:
${
generateChildrenScript
(
value
)}
,\n`
;
}
else
{
if
(
!
scriptData
.
includes
(
`
${
key
}
:`
))
{
scriptData
+=
`
${
key
}
:
${
JSON
.
stringify
(
value
)}
,\n`
;
}
}
});
scriptData
+=
' };
\
n'
;
return
`
}
else
{
data() {
scriptData
+=
` return
${
JSON
.
stringify
(
data
)}
;\n`
;
return
${
scriptProperties
}
}
},
}
// Add other Vue component options here
`
;
}
function
generateChildrenScript
(
children
)
{
function
generateDataProperties
(
data
)
{
if
(
Array
.
isArray
(
children
))
{
const
properties
=
Object
.
entries
(
data
)
const
processedChildren
=
children
.
map
(
child
=>
processScriptProperties
(
child
)).
join
(
',
\
n'
);
.
map
(([
key
,
value
])
=>
{
return
`[\n
${
processedChildren
}
\n]`
;
if
(
typeof
value
===
'object'
&&
!
Array
.
isArray
(
value
))
{
return
`
${
key
}
:
${
generateDataProperties
(
value
)}
`
;
}
else
{
}
else
{
return
'[]'
;
return
`
${
key
}
:
${
JSON
.
stringify
(
value
)}
`
;
}
}
}
})
.
join
(
', '
);
processScriptProperties
(
data
);
scriptData
+=
' }
\
n};
\
n'
;
return
scriptData
;
}
return
{
return
`{
${
properties
}
}`
;
templateContent
:
generateTemplateRecursive
(
jsonData
),
scriptContent
:
generateScriptContent
(
jsonData
),
};
}
}
\ No newline at end of file
data.json
View file @
291358d5
{
{
"template"
:
{
"tagName"
:
"section"
,
"tagName"
:
"section"
,
"properties"
:
{
"properties"
:
{
"id"
:
"about"
,
"id"
:
"about"
,
"class"
:
"section section-about section-about-1 pp-scrollable"
"class"
:
"section section-about section-about-1 pp-scrollable"
},
},
"children"
:
[
"children"
:
[
{
"tagName"
:
"assign"
,
"properties"
:
{
"name"
:
"user anme"
}
},
{
"tagName"
:
"assign"
,
"properties"
:
{
"htmlstring"
:
"user anme"
}
},
{
{
"tagName"
:
"div"
,
"tagName"
:
"div"
,
"properties"
:
{
"properties"
:
{
...
@@ -67,4 +80,17 @@
...
@@ -67,4 +80,17 @@
]
]
}
}
]
]
},
"script"
:
{
"exportDefault"
:
{
"data"
:
{
"showDetails"
:
false
,
"user"
:
{
"isAdmin"
:
false
},
"items"
:
[]
}
}
}
}
}
sample.ftl
0 → 100644
View file @
291358d5
<section id="about" class="section section-about section-about-1 pp-scrollable">
<#assign userName = "user anme">
<#assign htmlString = "user anme">
<div class="full-screen">
<div class="display-center">
<div class="section-title-1">
<div class="container about-me-text-container">
<div></div>
<#if user.isAdmin>
<p>This paragraph will be rendered if the user is an admin.</p>
</#if>
<#if showDetails>
<div>This div will be shown if showDetails is true.</div>
</#if>
<#list items as item>
<div><span>${item}</span></div>
</#list>
</div>
</div>
</div>
</div>
</section>
sample.json
0 → 100644
View file @
291358d5
{
"type"
:
"object"
,
"properties"
:
[
{
"type"
:
"string"
,
"name"
:
"paths"
,
"value"
:
{
"type"
:
"object"
,
"properties"
:
[
{
"type"
:
"string"
,
"name"
:
"favorites"
,
"value"
:
"M140,20C 73,20 20,74 20,140 20,275 156,310 248,443 336,311 477,270 477,140 477,74 423,20 357,20 309,20 267,48 248,89 229,48 188,20 140,20Z"
}
]
}
},
{
"type"
:
"string"
,
"name"
:
"favorites"
,
"value"
:
"<svg class=
\"
favorites-icon
\"
viewBox=
\"
0 0 490 490
\"
>
\n
<title>Favorite</title>
\n
<use role=
\"
presentation
\"
xlink:href=
\"
#icons-svg-favorites
\"
/>
\n
</svg>"
},
{
"type"
:
"function"
,
"name"
:
"svgDefs"
,
"params"
:
[],
"body"
:
"<svg class=
\"
svg-defs hidden
\"
viewBox=
\"
0 0 0 0
\"
>
\n
<defs>
\n
<#list paths?keys as icon>
\n
<path role=
\"
presentation
\"
id=
\"
icons-svg-${icon}
\"
d=
\"
${paths[icon]}"
/>\n</#list>\n</defs>\n</svg>
"
}
]
}
\ 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