diff --git a/docs/schema.typ b/docs/schema.typ index 48d539e..c2aa221 100644 --- a/docs/schema.typ +++ b/docs/schema.typ @@ -1,5 +1,6 @@ /// Loads a schema from a file or a raw block. -/// This function returns a dictionary of structures +/// This function returns a dictionary of structures\ +/// See the #link()[Loading] chapter for examples of schema loading for each supported format /// /// Supported formats: #schema.valid-extensions.map(e => raw("." + e)).join(", ") /// - path-or-schema (str, raw, dictionary): @@ -12,7 +13,6 @@ #let load(path-or-schema) = {} /// Renders the given schema -/// This functions /// - schema (dictionary): A schema dictionary, as returned by @@load() /// - config (auto, dictionary): The configuration parameters, as returned by #doc-ref("config.config") /// - width (ratio, length): The width of the generated figure diff --git a/gallery/example1.pdf b/gallery/example1.pdf index a7422f5..96dbf60 100644 Binary files a/gallery/example1.pdf and b/gallery/example1.pdf differ diff --git a/gallery/example2.pdf b/gallery/example2.pdf index 25e87fe..ee09bba 100644 Binary files a/gallery/example2.pdf and b/gallery/example2.pdf differ diff --git a/gallery/example3.pdf b/gallery/example3.pdf index 349db38..0cb441b 100644 Binary files a/gallery/example3.pdf and b/gallery/example3.pdf differ diff --git a/gallery/test.pdf b/gallery/test.pdf index b321250..c8d4a11 100644 Binary files a/gallery/test.pdf and b/gallery/test.pdf differ diff --git a/manual.pdf b/manual.pdf index b99f8db..35debf3 100644 Binary files a/manual.pdf and b/manual.pdf differ diff --git a/manual.typ b/manual.typ index 5faedb7..6445fa4 100644 --- a/manual.typ +++ b/manual.typ @@ -84,22 +84,26 @@ This is a port of the #link("https://git.kb28.ch/HEL/rivet")[homonymous Python s = Usage -Simply import `schema` from #link("src/lib.typ") and call `schema.load` to parse a schema description. Then use `schema.render` to render it, et voilĂ  ! -#pad(left: 1em)[```typ -#import "@preview/rivet:0.1.0": schema -#let doc = schema.load("path/to/schema.yaml") +#let import-stmt = "#import \"@preview/rivet:" + str(lib.version) + "\"" + +Simply import the `schema` module and call `schema.load` to parse a schema description. Then use `schema.render` to render it, et voilĂ  ! +#raw(block: true, lang: "typ", ```typ +$import: schema +#let doc = schema.load(yaml("path/to/schema.yaml")) #schema.render(doc) -```] +```.text.replace("$import", import-stmt)) + +Please read the #link()[Loading] chapter for more detailed explanations on how to load schema descriptions. = Format This section describes the structure of a schema definition. The examples given use the JSON syntax. For examples in different formats, see #link("https://git.kb28.ch/HEL/rivet-typst/src/branch/main/gallery/test.yaml")[test.yaml], #link("https://git.kb28.ch/HEL/rivet-typst/src/branch/main/gallery/test.json")[test.json] and #link("https://git.kb28.ch/HEL/rivet-typst/src/branch/main/gallery/test.xml")[test.xml]. You can also directly define a schema using Typst dictionaries and arrays. -Since the XML format is quite different from the other, you might find it helpful to look at the examples on GitHub to get familiar with it. +Since the XML format is quite different from the other, you might find it helpful to look at the examples in the #link("https://git.kb28.ch/HEL/rivet-typst/src/branch/main/gallery/")[Gitea repo] to get familiar with it. == Main layout -A schema contains a dictionary of structures. The must be at least one defined structure named "main". +A schema contains a dictionary of structures. There must be at least one defined structure named "main". It can also optionnaly contain a "colors" dictionary. More details about this in #link()[Colors] @@ -177,7 +181,7 @@ For values depending on other ranges, see #link()[Dependenc The structure of one range may depend on the value of another. To represent this situation, first indicate on the child range the range on which it depends. -Then, in its values, indicate which structure to use. A description can also be added (displayed above the horizontal dependency arrow) +Then, in its values, indicate which structure to use. A description can also be added (displayed below the horizontal dependency arrow) ```json "7-4": { @@ -270,6 +274,81 @@ Valid color formats are: #pagebreak(weak: true) += Loading + +Due to current limitations of the Typst compiler, the package can only access its own files, unless directly included in your project. For this reason, rivet cannot load a schema from a path, and you will need to read the files yourself to pass their contents to the package. + +Here are a number of ways you can load your schemas: + +== JSON Format + +````typ +// From file (ONLY IF PACKAGE INSTALLED IN PROJECT) +#let s = schema.load("schema.json") +// From file +#let s = schema.load(json("schema.json")) +// Raw block +#let s = schema.load(```json +{ + "structures": { + "main": { + ... + } + } +} +```) +```` + +== YAML Format + +````typ +// From file (ONLY IF PACKAGE INSTALLED IN PROJECT) +#let s = schema.load("schema.yaml") +// From file +#let s = schema.load(yaml("schema.yaml")) +// Raw block +#let s = schema.load(```yaml +structures: + main: + ... +```) +```` + +== Typst Format + +```typ +#let s = schema.load(( + structures: ( + main: ( + ... + ) + ) +)) +``` + +#pagebreak(weak: true) + +== XML Format + +````typ +// From file (ONLY IF PACKAGE INSTALLED IN PROJECT) +#let x = schema.xml-loader.load("schema.xml") +#let s = schema.load(x) +// From file +#let x = schema.xml-loader.parse(yaml("schema.yaml").first()) +#let s = schema.load(x) +// Raw block +#let s = schema.load(```xml + + + ... + + +```) +```` + +#pagebreak(weak: true) + = Config presets Aside from the default config, some example presets are also provided: diff --git a/src/lib.typ b/src/lib.typ index 6d7aa1d..ed44ea6 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -1,4 +1,4 @@ -#let version = version(0,2,0) +#let version = version(0,3,0) #import "config.typ" #import "schema.typ" \ No newline at end of file diff --git a/typst.toml b/typst.toml index a0c5417..878fc30 100644 --- a/typst.toml +++ b/typst.toml @@ -1,7 +1,7 @@ [package] name = "rivet" -version = "0.2.0" -compiler = "0.13.0" +version = "0.3.0" +compiler = "0.13.1" repository = "https://git.kb28.ch/HEL/rivet-typst" entrypoint = "src/lib.typ" authors = [