Skip to content

Commit

Permalink
Support tags for concepts in track config
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed Oct 6, 2023
1 parent 38780f1 commit d9d898d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/fmt/track_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ func addKeyFeatures(result: var string; val: KeyFeatures; indentLevel = 1) =
result.addNewlineAndIndent(indentLevel)
result.add "],"

func addConceptTags(result: var string; val: ConceptTags; indentLevel = 2) =
result.addNewlineAndIndent(indentLevel)
escapeJson("tags", result)
result.add ": {"
if val.all.len > 0:
result.addArray("all", val.all, indentLevel + 1)
if val.`any`.len > 0:
result.addArray("any", val.`any`, indentLevel + 1)
if val.`not`.len > 0:
result.addArray("not", val.`not`, indentLevel + 1)
result.removeComma()
result.addNewlineAndIndent(indentLevel)
result.add "},"

func addConcept(result: var string; val: Concept; indentLevel = 1) =
## Appends the pretty-printed JSON for a `concept` object with value `val` to
## `result`.
Expand All @@ -129,6 +143,10 @@ func addConcept(result: var string; val: Concept; indentLevel = 1) =
result.addString("uuid", val.uuid, indentLevel + 1)
result.addString("slug", val.slug, indentLevel + 1)
result.addString("name", val.name, indentLevel + 1)
if val.tags.isSome():
let tags = val.tags.get()
if tags.all.len + tags.`any`.len + tags.`not`.len > 0:
result.addConceptTags(tags, indentLevel + 1)
result.removeComma()
result.addNewlineAndIndent(indentLevel)
result.add "},"
Expand Down
6 changes: 6 additions & 0 deletions src/types_track_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ type
indentSize*: int
highlightjsLanguage*: string

ConceptTags* = object
all*: seq[string]
`any`*: seq[string]
`not`*: seq[string]

Concept* = object
name*: string
slug*: string
uuid*: string
tags*: Option[ConceptTags]

Concepts* = seq[Concept]

Expand Down

0 comments on commit d9d898d

Please sign in to comment.