-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.data.ts
43 lines (36 loc) · 954 Bytes
/
block.data.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { brightMagenta } from "./deps.ts"
import { _replace } from "./shared.ts"
import { presets } from "./templates/tailwind.ts"
import {
block_exist,
create_block_file,
create_dir,
insert_content,
stdOut,
} from "./actions.ts"
export const fns = {
create_dir,
create_block_file,
insert_content,
block_exist,
stdOut,
}
// eslint-disable-next-line max-lines-per-function
export function create_data_block(name: string, insert = true) {
const { templates: t } = presets["tailwind"]
fns.create_dir("blocks")
if (fns.block_exist(name)) {
fns.stdOut(brightMagenta("Already Created Block: " + name))
return
}
fns.create_block_file(
`blocks/${name}.data.html`,
_replace(t, "data.view", { name }),
)
fns.create_block_file(
`blocks/${name}.model.json`,
_replace(t, "data.model", { name }),
)
if (!insert) return
fns.insert_content(`{% include "blocks/${name}.data.html" %}`, "index.html")
}