Skip to content

Commit

Permalink
Format elements more compactly. (#1485)
Browse files Browse the repository at this point in the history
This moves the generated elements from the form `new Model({ ..., children: { ... } })` to `new Model({...}, ...children)`.

Co-authored-by: Ingo Fischer <[email protected]>
  • Loading branch information
lauckhart and Apollon77 authored Dec 6, 2024
1 parent e2a744d commit b604cfa
Show file tree
Hide file tree
Showing 206 changed files with 30,446 additions and 31,168 deletions.
14 changes: 7 additions & 7 deletions codegen/src/mom/common/generate-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { camelize, serialize } from "../../util/string.js";
export function generateElement(target: Block, importFrom: string, element: Model, prefix = "", suffix = "") {
const factory = camelize(element.tag, true);
target.file.addImport(importFrom, `${factory}Element as ${factory}`);
const block = target.expressions(`${prefix}${factory}({`, `})${suffix}`);
const expr = target.expressions(`${prefix}${factory}(`, `)${suffix}`);
const head = expr.expressions("{", "}");

const fields = element.valueOf() as { [name: string]: any };

Expand Down Expand Up @@ -47,15 +48,15 @@ export function generateElement(target: Block, importFrom: string, element: Mode
for (const property of properties) {
length += property.length + (length ? 2 : 0);
if (row.length && length >= 100) {
block.atom(row.join(", "));
head.atom(row.join(", "));
row = [property];
length = property.length;
} else {
row.push(property);
}
}
if (row.length) {
block.atom(row.join(", "));
head.atom(row.join(", "));
}

// Next row: Details
Expand All @@ -68,20 +69,19 @@ export function generateElement(target: Block, importFrom: string, element: Mode
}
const text = lines.join("\n");
if (text) {
block.atom(text);
head.atom(text);
}
}

// Next row: Cross reference
if (element.xref) {
block.atom("xref", serialize(element.xref));
head.atom("xref", serialize(element.xref));
}

// Children
if (element.children?.length) {
const childBlock = block.expressions(`children: [`, "]");
for (const child of element.children) {
generateElement(childBlock, importFrom, child);
generateElement(expr, importFrom, child);
}
}
}
35 changes: 19 additions & 16 deletions packages/model/src/standard/elements/AcceptedCommandList.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

707 changes: 352 additions & 355 deletions packages/model/src/standard/elements/AccessControl.ts

Large diffs are not rendered by default.

226 changes: 117 additions & 109 deletions packages/model/src/standard/elements/AccountLogin.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b604cfa

Please sign in to comment.