[add] object:link [add] object:code [add] object:table [add] misc:conv [mod] example:polyhedra
This commit is contained in:
parent
f751b57ab9
commit
19f045e25b
21
misc/conv
Executable file
21
misc/conv
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
function main(args)
|
||||
{
|
||||
// args
|
||||
const path_transform = ((args.length >= 0) ? args.shift() : "transform.js");
|
||||
const path_data = ((args.length >= 0) ? args.shift() : "data.json");
|
||||
|
||||
// exec
|
||||
const _fs = require("fs");
|
||||
const data = JSON.parse(_fs.readFileSync(path_data).toString());
|
||||
const transformation_code = _fs.readFileSync(path_transform).toString()
|
||||
const sd = eval(transformation_code)(data);
|
||||
|
||||
// output
|
||||
const output = (JSON.stringify(sd, undefined, "\t") + "\n");
|
||||
process.stdout.write(output);
|
||||
}
|
||||
|
||||
|
||||
main(process.argv.slice(2));
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"group": {
|
||||
"attributes": [
|
||||
"members"
|
||||
]
|
||||
},
|
||||
"section": {
|
||||
"attributes": [
|
||||
"title",
|
||||
"content"
|
||||
]
|
||||
},
|
||||
"list": {
|
||||
"attributes": [
|
||||
"items"
|
||||
]
|
||||
},
|
||||
"text": {
|
||||
"attributes": [
|
||||
"content"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
# Polyhedra
|
||||
|
||||
## Tetrahedron
|
||||
|
||||
- vertices: 4
|
||||
- faces: 4
|
||||
- edges: 6
|
||||
|
||||
|
||||
## Hexahedron
|
||||
|
||||
- vertices: 8
|
||||
- faces: 6
|
||||
- edges: 12
|
||||
|
||||
|
||||
## Octahedron
|
||||
|
||||
- vertices: 6
|
||||
- faces: 8
|
||||
- edges: 12
|
||||
|
||||
|
||||
## Dodecahedron
|
||||
|
||||
- vertices: 20
|
||||
- faces: 12
|
||||
- edges: 30
|
||||
|
||||
|
||||
## Icosahedron
|
||||
|
||||
- vertices: 12
|
||||
- faces: 20
|
||||
- edges: 30
|
||||
|
||||
|
|
@ -1,207 +0,0 @@
|
|||
{
|
||||
"definitions": {
|
||||
"tetrahedron": {
|
||||
"kind": "section",
|
||||
"data": {
|
||||
"title": "Tetrahedron",
|
||||
"content": {
|
||||
"kind": "list",
|
||||
"data": {
|
||||
"items": [
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "vertices: 4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "faces: 4"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "edges: 6"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"hexahedron": {
|
||||
"kind": "section",
|
||||
"data": {
|
||||
"title": "Hexahedron",
|
||||
"content": {
|
||||
"kind": "list",
|
||||
"data": {
|
||||
"items": [
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "vertices: 6"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "faces: 8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "edges: 12"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"octahedron": {
|
||||
"kind": "section",
|
||||
"data": {
|
||||
"title": "Octahedron",
|
||||
"content": {
|
||||
"kind": "list",
|
||||
"data": {
|
||||
"items": [
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "vertices: 6"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "faces: 8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "edges: 12"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"dodecahedron": {
|
||||
"kind": "section",
|
||||
"data": {
|
||||
"title": "Dodecahedron",
|
||||
"content": {
|
||||
"kind": "list",
|
||||
"data": {
|
||||
"items": [
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "vertices: 20"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "faces: 12"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "edges: 30"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"icosahedron": {
|
||||
"kind": "section",
|
||||
"data": {
|
||||
"title": "Icosahedron",
|
||||
"content": {
|
||||
"kind": "list",
|
||||
"data": {
|
||||
"items": [
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "vertices: 12"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "faces: 20"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "edges: 30"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"content": {
|
||||
"title": "Polyhedra",
|
||||
"main": {
|
||||
"kind": "section",
|
||||
"data": {
|
||||
"title": "Polyhedra",
|
||||
"content": {
|
||||
"kind": "group",
|
||||
"data": {
|
||||
"members": [
|
||||
{
|
||||
"kind": "reference",
|
||||
"data": {
|
||||
"name": "tetrahedron"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "reference",
|
||||
"data": {
|
||||
"name": "hexahedron"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "reference",
|
||||
"data": {
|
||||
"name": "octahedron"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "reference",
|
||||
"data": {
|
||||
"name": "dodecahedron"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "reference",
|
||||
"data": {
|
||||
"name": "icosahedron"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"kind": "group",
|
||||
"data": {
|
||||
"members": [
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "foo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "bar"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
41
misc/examples/polyhedra/data.json
Normal file
41
misc/examples/polyhedra/data.json
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"stock": {
|
||||
"tetrahedron": {
|
||||
"name": "Tetrahedron",
|
||||
"vertices": 4,
|
||||
"faces": 4,
|
||||
"edges": 6
|
||||
},
|
||||
"hexahedron": {
|
||||
"name": "Hexahedron",
|
||||
"vertices": 8,
|
||||
"faces": 6,
|
||||
"edges": 12
|
||||
},
|
||||
"octahedron": {
|
||||
"name": "Octahedron",
|
||||
"vertices": 6,
|
||||
"faces": 8,
|
||||
"edges": 12
|
||||
},
|
||||
"dodecahedron": {
|
||||
"name": "Dodecahedron",
|
||||
"vertices": 20,
|
||||
"faces": 12,
|
||||
"edges": 30
|
||||
},
|
||||
"icosahedron": {
|
||||
"name": "Icosahedron",
|
||||
"vertices": 12,
|
||||
"faces": 20,
|
||||
"edges": 30
|
||||
}
|
||||
},
|
||||
"order": [
|
||||
"tetrahedron",
|
||||
"hexahedron",
|
||||
"octahedron",
|
||||
"dodecahedron",
|
||||
"icosahedron"
|
||||
]
|
||||
}
|
||||
51
misc/examples/polyhedra/transform-default.js
Normal file
51
misc/examples/polyhedra/transform-default.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
(data) => ({
|
||||
"definitions": {
|
||||
},
|
||||
"content": {
|
||||
"title": "Polyhedra",
|
||||
"main": {
|
||||
"kind": "section",
|
||||
"data": {
|
||||
"title": "Polyhedra",
|
||||
"content": {
|
||||
"kind": "group",
|
||||
"data": {
|
||||
"members": data.order.map(
|
||||
name => ({
|
||||
"kind": "section",
|
||||
"data": {
|
||||
"title": data.stock[name].name,
|
||||
"content": {
|
||||
"kind": "list",
|
||||
"data": {
|
||||
"items": [
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": ("vertices: " + data.stock[name].vertices.toFixed(0)),
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": ("faces: " + data.stock[name].faces.toFixed(0)),
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": ("edges: " + data.stock[name].edges.toFixed(0)),
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
72
misc/examples/polyhedra/transform-table.js
Normal file
72
misc/examples/polyhedra/transform-table.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
(data) => ({
|
||||
"definitions": {
|
||||
},
|
||||
"content": {
|
||||
"title": "Polyhedra",
|
||||
"main": {
|
||||
"kind": "section",
|
||||
"data": {
|
||||
"title": "Polyhedra",
|
||||
"content": {
|
||||
"kind": "table",
|
||||
"data": {
|
||||
"head": [
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "name"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "vertices"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "faces"
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": "edges"
|
||||
}
|
||||
}
|
||||
],
|
||||
"rows": data.order.map(
|
||||
name => ([
|
||||
{
|
||||
"kind": "text",
|
||||
"data": {
|
||||
"content": data.stock[name].name
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"data": {
|
||||
"content": data.stock[name].vertices.toFixed(0)
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"data": {
|
||||
"content": data.stock[name].faces.toFixed(0)
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"data": {
|
||||
"content": data.stock[name].edges.toFixed(0)
|
||||
}
|
||||
}
|
||||
])
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
- coproduct `element`
|
||||
- group
|
||||
- section
|
||||
- list
|
||||
- …
|
||||
- coproduct `output`
|
||||
- (markdown)
|
||||
- html
|
||||
- tex
|
||||
- odt
|
||||
- …
|
||||
- coproduct `input`
|
||||
- markdown
|
||||
|
||||
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
declare var console;
|
||||
|
||||
async function main(args_raw : Array<string>) : Promise<void>
|
||||
{
|
||||
// args
|
||||
const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler(
|
||||
{
|
||||
/*
|
||||
"input": lib_plankton.args.class_argument.positional({
|
||||
"index": 0,
|
||||
"type": lib_plankton.args.enum_type.string,
|
||||
|
|
@ -11,6 +14,7 @@ async function main(args_raw : Array<string>) : Promise<void>
|
|||
"info": "path to input file",
|
||||
"name": "input",
|
||||
}),
|
||||
*/
|
||||
"output": lib_plankton.args.class_argument.volatile({
|
||||
"indicators_long": ["output"],
|
||||
"indicators_short": ["o"],
|
||||
|
|
@ -46,7 +50,8 @@ async function main(args_raw : Array<string>) : Promise<void>
|
|||
}
|
||||
else
|
||||
{
|
||||
const document_raw : string = lib_plankton.json.decode(await lib_plankton.file.read(args.input))
|
||||
const document_raw : string = lib_plankton.json.decode(await lib_plankton.file/*.read(args.input)*/.read_stdin());
|
||||
|
||||
const document : type_document = type_document.from_raw(document_raw);
|
||||
// let object : type_object = object_make(document_raw["content"]["main"]);
|
||||
|
||||
|
|
|
|||
30
source/objects/implementations/code.ts
Normal file
30
source/objects/implementations/code.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
/**
|
||||
*/
|
||||
type type_object_code_data = {
|
||||
content : string;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
class type_object_code implements type_object
|
||||
{
|
||||
public readonly kind : string = "code";
|
||||
public readonly data : type_object_code_data;
|
||||
public constructor(data : type_object_code_data) {this.data = data;}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
object_kind_register(
|
||||
"code",
|
||||
(data) => (
|
||||
new type_object_code(
|
||||
{
|
||||
"content": data["content"],
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
32
source/objects/implementations/link.ts
Normal file
32
source/objects/implementations/link.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
/**
|
||||
*/
|
||||
type type_object_link_data = {
|
||||
target : string;
|
||||
label : (null | string);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
class type_object_link implements type_object
|
||||
{
|
||||
public readonly kind : string = "link";
|
||||
public readonly data : type_object_link_data;
|
||||
public constructor(data : type_object_link_data) {this.data = data;}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
object_kind_register(
|
||||
"link",
|
||||
(data) => (
|
||||
new type_object_link(
|
||||
{
|
||||
"target": data["target"],
|
||||
"label": (data["label"] ?? null),
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
33
source/objects/implementations/table.ts
Normal file
33
source/objects/implementations/table.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
/**
|
||||
*/
|
||||
type type_object_table_data = {
|
||||
head : (null | Array<type_object>);
|
||||
rows : Array<Array<type_object>>;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @todo check sanity (length of head and rows)
|
||||
*/
|
||||
class type_object_table implements type_object
|
||||
{
|
||||
public readonly kind : string = "table";
|
||||
public readonly data : type_object_table_data;
|
||||
public constructor(data : type_object_table_data) {this.data = data;}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
object_kind_register(
|
||||
"table",
|
||||
(data) => (
|
||||
new type_object_table(
|
||||
{
|
||||
"head": data["head"],
|
||||
"rows": data["rows"],
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
@ -36,6 +36,27 @@ class type_output_html implements type_output<string>
|
|||
new lib_plankton.xml.class_node_text(content),
|
||||
]
|
||||
),
|
||||
"code": ({"content": content}) => new lib_plankton.xml.class_node_complex(
|
||||
"code",
|
||||
{
|
||||
"class": "sd-code",
|
||||
},
|
||||
[
|
||||
new lib_plankton.xml.class_node_text(content),
|
||||
]
|
||||
),
|
||||
"link": ({"target": target, "label": label}) => new lib_plankton.xml.class_node_complex(
|
||||
"a",
|
||||
{
|
||||
"class": "sd-link",
|
||||
"href": target,
|
||||
},
|
||||
(
|
||||
(label === null)
|
||||
? []
|
||||
: [new lib_plankton.xml.class_node_text(label)]
|
||||
)
|
||||
),
|
||||
"group": ({"members": members}) => new lib_plankton.xml.class_node_complex(
|
||||
"div",
|
||||
{
|
||||
|
|
@ -100,6 +121,81 @@ class type_output_html implements type_output<string>
|
|||
)
|
||||
),
|
||||
),
|
||||
"table": ({"head": head, "rows": rows}) => new lib_plankton.xml.class_node_complex(
|
||||
"table",
|
||||
{
|
||||
"class": "sd-table",
|
||||
},
|
||||
(
|
||||
[]
|
||||
.concat(
|
||||
(head === null)
|
||||
? []
|
||||
: [
|
||||
new lib_plankton.xml.class_node_complex(
|
||||
"thead",
|
||||
{},
|
||||
[
|
||||
new lib_plankton.xml.class_node_complex(
|
||||
"tr",
|
||||
{},
|
||||
(
|
||||
head.map(
|
||||
cell => new lib_plankton.xml.class_node_complex(
|
||||
"th",
|
||||
{},
|
||||
[
|
||||
this.render_object_internal(
|
||||
cell,
|
||||
{
|
||||
"level": options.level,
|
||||
"depth": (options.depth + 1),
|
||||
}
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
]
|
||||
),
|
||||
]
|
||||
)
|
||||
.concat(
|
||||
[
|
||||
new lib_plankton.xml.class_node_complex(
|
||||
"tbody",
|
||||
{},
|
||||
(
|
||||
rows.map(
|
||||
row => new lib_plankton.xml.class_node_complex(
|
||||
"tr",
|
||||
{},
|
||||
(
|
||||
row.map(
|
||||
cell => new lib_plankton.xml.class_node_complex(
|
||||
"td",
|
||||
{},
|
||||
[
|
||||
this.render_object_internal(
|
||||
cell,
|
||||
{
|
||||
"level": options.level,
|
||||
"depth": (options.depth + 1),
|
||||
}
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
),
|
||||
),
|
||||
},
|
||||
{
|
||||
"fallback": (object) => new lib_plankton.xml.class_node_complex(
|
||||
|
|
|
|||
|
|
@ -26,9 +26,12 @@ ${dir_temp}/sd-unlinked.js: \
|
|||
${dir_source}/base.ts \
|
||||
${dir_source}/objects/base.ts \
|
||||
${dir_source}/objects/implementations/text.ts \
|
||||
${dir_source}/objects/implementations/code.ts \
|
||||
${dir_source}/objects/implementations/link.ts \
|
||||
${dir_source}/objects/implementations/group.ts \
|
||||
${dir_source}/objects/implementations/section.ts \
|
||||
${dir_source}/objects/implementations/list.ts \
|
||||
${dir_source}/objects/implementations/table.ts \
|
||||
${dir_source}/document.ts \
|
||||
${dir_source}/outputs/base.ts \
|
||||
${dir_source}/outputs/implementations/json.ts \
|
||||
|
|
|
|||
Loading…
Reference in a new issue