planett-server-parser
v1.0.5
Published
planett server parser
Downloads
18
Readme
Planett Server Parser
You can save the construct of your website to database. Then, you can get construct from db and save construct to db with this parser.
Usage
- Install:
npm install planett-server-parser
Get construct from db
import { GetFromDb } from 'planett-server-parser';
let components = {
"Page": "PageComponent",
"Layout": "LayoutComponent",
"Null": "NullComponent",
"Logo": "LogoComponent",
"HeaderRight": "LogoHeaderRight"
};
let data = {"Page":[{"id":"\"1\"","style":"{\"color\":\"white\"}","components":["Layout","Layout","Null"]},{"id":"\"2\"","style":"{\"color\":\"red\"}"}],"Layout":[{"noSpacing":"\"true\"","id":"\"1-1\"","components":["Logo","HeaderRight"]},{"id":"\"2\"","style":"{\"color\":\"black\"}"}],"Logo":[{"id":"\"1-1-1\"","data":"{\"link\":\"./\"}"}],"HeaderRight":[{"id":"\"1-1-2\"","desktop":"\"3\""}],"Null":[{"id":"\"3\""}]};
let output = GetFromDb(data, components);
// output is your website construct
// output = [{"__name__":"Page","__component__":"PageComponent","id":"1","style":{"color":"white"},"__components__":[{"__name__":"Layout","__component__":"LayoutComponent","noSpacing":"true","id":"1-1","__components__":[{"__name__":"Logo","__component__":"LogoComponent","id":"1-1-1","data":{"link":"./"}},{"__name__":"HeaderRight","__component__":"LogoHeaderRight","id":"1-1-2","desktop":"3"}]},{"__name__":"Layout","__component__":"LayoutComponent","id":"2","style":{"color":"black"}},{"__name__":"Null","__component__":"NullComponent","id":"3"}]},{"__name__":"Page","__component__":"PageComponent","id":"2","style":{"color":"red"}}]
- One component, one table.
- You need to collect your data of component to an object like
data
.
Save construct to db
import { SaveToDb } from 'planett-server-parser';
let data = [
{
"__name__": "Page",
"__component__": "PageComponent",
"id": "1",
"style": {"color": "white"},
"__components__": [
{
"__name__": "Layout",
"__component__": "LayoutComponent",
"noSpacing": "true",
"id": "1-1",
"__components__": [
{
"__name__": "Logo",
"__component__": "LogoComponent",
"id": "1-1-1",
"data": {
"link": "./"
}
},
{
"__name__": "HeaderRight",
"__component__": "HeaderRightComponent",
"id": "1-1-2",
"desktop": "3"
}
]
},
{
"__name__": "Layout",
"__component__": "LayoutComponent",
"id": "2",
"style": {"color": "black"}
},
{
"__name__": "Null",
"__component__": "NullComponent",
"id": "3"
}
]
},
{
"__name__": "Page",
"__component__": "PageComponent",
"id": "2",
"style": {"color": "red"}
}
];
let output = SaveToDb(data);
// output will be an object that you can save to database.
// output = {"Page":[{"id":"\"1\"","style":"{\"color\":\"white\"}","components":["Layout","Layout","Null"]},{"id":"\"2\"","style":"{\"color\":\"red\"}"}],"Layout":[{"noSpacing":"\"true\"","id":"\"1-1\"","components":["Logo","HeaderRight"]},{"id":"\"2\"","style":"{\"color\":\"black\"}"}],"Logo":[{"id":"\"1-1-1\"","data":"{\"link\":\"./\"}"}],"HeaderRight":[{"id":"\"1-1-2\"","desktop":"\"3\""}],"Null":[{"id":"\"3\""}]}
data
is the construct of your website