-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema-doc.rb
More file actions
40 lines (30 loc) · 984 Bytes
/
schema-doc.rb
File metadata and controls
40 lines (30 loc) · 984 Bytes
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
## Injects the Squarkup JSON Schema into `docs/squarkup-config.md`.
require "json"
require_relative "../../squarkdown/utils/log"
require_relative "helpers/render-table"
def doc_schema
log "documenting squarkup schema..."
## Load
content = File.read(Routes.root / "squarkdown/resources/squarkup-schema.json")
schema = JSON.parse(content)
schema["properties"].delete("$schema")
## Render
rows = schema["properties"].map do |field, props|
render_table(field:, props:)
end
content = rows.join("\n")
## Inject
pattern = /<!-- #SQUARK inject\? -->.*?<!-- #SQUARK inject. -->/m
repl = """<!-- #SQUARK inject? -->
| Field | Type | Values | Default | Description |
| :---- | :--- | :----- | :------ | :---------- |
#{content}
<!-- #SQUARK inject. -->"""
route = Routes.root / "docs/reference/squarkup-json.md"
existing = File.read(route)
text = existing.sub(pattern, repl)
## Save
File.write(route, text)
## Out
return schema["version"]
end