From 1458dc5db782910753c8c38886a26b3e9f5c8c37 Mon Sep 17 00:00:00 2001 From: David Vogel Date: Thu, 19 Dec 2024 17:18:11 +0100 Subject: [PATCH] Rename CLI.Render to CLI.Compile --- README.md | 6 +++--- cli.go | 12 +++++------- cli_test.go | 8 ++++---- errors_test.go | 8 ++++---- examples/passing-objects/main.go | 4 ++-- readme_test.go | 4 ++-- variable-encoder_test.go | 4 ++-- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 93476f0..407fb19 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ You can install it by following [the instructions in the typst repository]. ## Usage -Here we will create a simple PDF document by passing a reader with typst markup into `typstCLI.Render` and then let it write the resulting PDF data into a file: +Here we will create a simple PDF document by passing a reader with typst markup into `typstCLI.Compile` and then let it write the resulting PDF data into a file: ```go func main() { @@ -58,8 +58,8 @@ A library to generate documents and reports by utilizing the command line versio } defer f.Close() - if err := typstCLI.Render(r, f, nil); err != nil { - t.Fatalf("Failed to render document: %v.", err) + if err := typstCLI.Compile(r, f, nil); err != nil { + t.Fatalf("Failed to compile document: %v.", err) } } ``` diff --git a/cli.go b/cli.go index 68f08ac..bad70ac 100644 --- a/cli.go +++ b/cli.go @@ -46,11 +46,9 @@ func (c CLI) VersionString() (string, error) { return output.String(), nil } -// TODO: Rename Render to Compile - -// Render takes a typst document from input, and renders it into the output writer. +// Compile takes a typst document from input, and renders it into the output writer. // The options parameter is optional. -func (c CLI) Render(input io.Reader, output io.Writer, options *CLIOptions) error { +func (c CLI) Compile(input io.Reader, output io.Writer, options *CLIOptions) error { args := []string{"c"} if options != nil { args = append(args, options.Args()...) @@ -82,11 +80,11 @@ func (c CLI) Render(input io.Reader, output io.Writer, options *CLIOptions) erro return nil } -// Render takes a typst document from input, and renders it into the output writer. +// Compile takes a typst document from input, and renders it into the output writer. // The options parameter is optional. // // Additionally this will inject the given map of variables into the global scope of the typst document. -func (c CLI) RenderWithVariables(input io.Reader, output io.Writer, options *CLIOptions, variables map[string]any) error { +func (c CLI) CompileWithVariables(input io.Reader, output io.Writer, options *CLIOptions, variables map[string]any) error { varBuffer := bytes.Buffer{} // TODO: Use io.pipe instead of a bytes.Buffer @@ -102,5 +100,5 @@ func (c CLI) RenderWithVariables(input io.Reader, output io.Writer, options *CLI reader := io.MultiReader(&varBuffer, input) - return c.Render(reader, output, options) + return c.Compile(reader, output, options) } diff --git a/cli_test.go b/cli_test.go index 85ef8c7..7b93aff 100644 --- a/cli_test.go +++ b/cli_test.go @@ -24,8 +24,8 @@ func TestCLI_VersionString(t *testing.T) { } } -// Test basic render functionality. -func TestCLI_Render(t *testing.T) { +// Test basic compile functionality. +func TestCLI_Compile(t *testing.T) { const inches = 1 const ppi = 144 @@ -42,8 +42,8 @@ func TestCLI_Render(t *testing.T) { } var w bytes.Buffer - if err := cli.Render(r, &w, &opts); err != nil { - t.Fatalf("Failed to render document: %v.", err) + if err := cli.Compile(r, &w, &opts); err != nil { + t.Fatalf("Failed to compile document: %v.", err) } imgConf, imgType, err := image.DecodeConfig(&w) diff --git a/errors_test.go b/errors_test.go index 25dae60..adacf21 100644 --- a/errors_test.go +++ b/errors_test.go @@ -19,8 +19,8 @@ func TestErrors0(t *testing.T) { r := bytes.NewBufferString(`This is a test!`) var w bytes.Buffer - if err := cli.Render(r, &w, nil); err != nil { - t.Fatalf("Failed to render document: %v", err) + if err := cli.Compile(r, &w, nil); err != nil { + t.Fatalf("Failed to compile document: %v", err) } } @@ -32,7 +32,7 @@ func TestErrors1(t *testing.T) { #assert(1 < 1, message: "Test")`) var w bytes.Buffer - if err := cli.Render(r, &w, nil); err == nil { + if err := cli.Compile(r, &w, nil); err == nil { t.Fatalf("Expected error, but got nil") } else { var errWithPath *typst.ErrorWithPath @@ -65,7 +65,7 @@ func TestErrors2(t *testing.T) { r := bytes.NewBufferString(`This is a test!`) var w bytes.Buffer - if err := cli.Render(r, &w, &opts); err == nil { + if err := cli.Compile(r, &w, &opts); err == nil { t.Fatalf("Expected error, but got nil") } else { var errTypst *typst.Error diff --git a/examples/passing-objects/main.go b/examples/passing-objects/main.go index 3c5c93e..407a441 100644 --- a/examples/passing-objects/main.go +++ b/examples/passing-objects/main.go @@ -39,7 +39,7 @@ func main() { } defer f.Close() - if err := typstCLI.RenderWithVariables(r, f, nil, map[string]any{"Data": TestData}); err != nil { - log.Panicf("Failed to render document: %v.", err) + if err := typstCLI.CompileWithVariables(r, f, nil, map[string]any{"Data": TestData}); err != nil { + log.Panicf("Failed to compile document: %v.", err) } } diff --git a/readme_test.go b/readme_test.go index 0cd0c52..f352232 100644 --- a/readme_test.go +++ b/readme_test.go @@ -30,7 +30,7 @@ A library to generate documents and reports by utilizing the command line versio } defer f.Close() - if err := typstCLI.Render(r, f, nil); err != nil { - t.Fatalf("Failed to render document: %v.", err) + if err := typstCLI.Compile(r, f, nil); err != nil { + t.Fatalf("Failed to compile document: %v.", err) } } diff --git a/variable-encoder_test.go b/variable-encoder_test.go index d66f06a..05965f8 100644 --- a/variable-encoder_test.go +++ b/variable-encoder_test.go @@ -184,8 +184,8 @@ func TestVariableEncoder(t *testing.T) { typstCLI := typst.CLI{} input := strings.NewReader("#" + result.String()) var output bytes.Buffer - if err := typstCLI.Render(input, &output, nil); err != nil { - t.Errorf("Compilation failed: %v", err) + if err := typstCLI.Compile(input, &output, nil); err != nil { + t.Errorf("Failed to compile generated typst markup: %v", err) } } })