Skip to content

Commit

Permalink
chore: better format
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed May 30, 2024
1 parent c6663ff commit e616620
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/views/components/TemplateBuilder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
</script>

<div class="modal-form flex flex-col gap-2">
<div class="flex">
<div class="flex gap-2">
<div class="flex gap-1 flex-col">
<h3>Fields to exclude</h3>
{#each $fields as field}
<div>
<label
>{field.name}
<label class="flex gap-1">
<input
type="checkbox"
value={field.omit}
on:input={(v) =>
model.setField(field.name, { omit: v.currentTarget.checked })}
/>
<span>{field.name}</span>
</label>
</div>
{/each}
Expand All @@ -33,8 +33,7 @@
{#each $fields as field}
{#if field.omit === false}
<div>
<label
>{field.name}
<label class="flex gap-1">
<input
type="checkbox"
value={field.onFrontmatter}
Expand All @@ -43,6 +42,7 @@
onFrontmatter: v.currentTarget.checked,
})}
/>
<span>{field.name}</span>
</label>
</div>
{/if}
Expand Down
19 changes: 12 additions & 7 deletions src/views/components/TemplateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,31 @@ function compileOpenForm(formName: string, fieldsToOmit: string[], usesGlobal: b
const args = `"${formName}"${omitOptions}`;
console.log({ args });
if (usesGlobal) {
return `const result = await MF.openForm(${args});`;
return [`const result = await MF.openForm(${args});`];
}
return `
const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm(${args});`;
const result = await modalForm.openForm(${args});`
.trim()
.split("\n")
.map((x) => x.trim());
}

function compileTemplaterTemplate(formName: string) {
return (fields: Field[]) => {
const fieldsToInclude = fields.filter((field): field is FieldOption => !field.omit);
const fieldsToOmit = fields.filter((field): field is OmitedFieldOption => field.omit);
const openTheform = compileOpenForm(
formName,
fieldsToOmit.map((x) => x.name),
).join("\n ");
console.log(openTheform);

return [
`<% "---" %>`,
`<%*`,
`${compileOpenForm(
formName,
fieldsToOmit.map((x) => x.name),
)}`,
` ${compileFrontmatter(fieldsToInclude)} `,
` ${openTheform}`,
` ${compileFrontmatter(fieldsToInclude)}`,
`-%>`,
`<% "---" -%>`,
].join("\n");
Expand Down

0 comments on commit e616620

Please sign in to comment.