Commit 9aad39ce authored by Amulya Nagesh Jilla's avatar Amulya Nagesh Jilla

style chnages

parent db5922f3
...@@ -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);
}
...@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment