mirror of
https://github.com/Dadido3/go-typst.git
synced 2025-04-11 12:13:16 +00:00
Rename CLI.Render to CLI.Compile
This commit is contained in:
parent
d65ae34abb
commit
1458dc5db7
@ -33,7 +33,7 @@ You can install it by following [the instructions in the typst repository].
|
|||||||
|
|
||||||
## Usage
|
## 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
|
```go
|
||||||
func main() {
|
func main() {
|
||||||
@ -58,8 +58,8 @@ A library to generate documents and reports by utilizing the command line versio
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
if err := typstCLI.Render(r, f, nil); err != nil {
|
if err := typstCLI.Compile(r, f, nil); err != nil {
|
||||||
t.Fatalf("Failed to render document: %v.", err)
|
t.Fatalf("Failed to compile document: %v.", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
12
cli.go
12
cli.go
@ -46,11 +46,9 @@ func (c CLI) VersionString() (string, error) {
|
|||||||
return output.String(), nil
|
return output.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rename Render to Compile
|
// Compile takes a typst document from input, and renders it into the output writer.
|
||||||
|
|
||||||
// Render takes a typst document from input, and renders it into the output writer.
|
|
||||||
// The options parameter is optional.
|
// 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"}
|
args := []string{"c"}
|
||||||
if options != nil {
|
if options != nil {
|
||||||
args = append(args, options.Args()...)
|
args = append(args, options.Args()...)
|
||||||
@ -82,11 +80,11 @@ func (c CLI) Render(input io.Reader, output io.Writer, options *CLIOptions) erro
|
|||||||
return nil
|
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.
|
// The options parameter is optional.
|
||||||
//
|
//
|
||||||
// Additionally this will inject the given map of variables into the global scope of the typst document.
|
// 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{}
|
varBuffer := bytes.Buffer{}
|
||||||
|
|
||||||
// TODO: Use io.pipe instead of a 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)
|
reader := io.MultiReader(&varBuffer, input)
|
||||||
|
|
||||||
return c.Render(reader, output, options)
|
return c.Compile(reader, output, options)
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ func TestCLI_VersionString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test basic render functionality.
|
// Test basic compile functionality.
|
||||||
func TestCLI_Render(t *testing.T) {
|
func TestCLI_Compile(t *testing.T) {
|
||||||
const inches = 1
|
const inches = 1
|
||||||
const ppi = 144
|
const ppi = 144
|
||||||
|
|
||||||
@ -42,8 +42,8 @@ func TestCLI_Render(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var w bytes.Buffer
|
var w bytes.Buffer
|
||||||
if err := cli.Render(r, &w, &opts); err != nil {
|
if err := cli.Compile(r, &w, &opts); err != nil {
|
||||||
t.Fatalf("Failed to render document: %v.", err)
|
t.Fatalf("Failed to compile document: %v.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
imgConf, imgType, err := image.DecodeConfig(&w)
|
imgConf, imgType, err := image.DecodeConfig(&w)
|
||||||
|
@ -19,8 +19,8 @@ func TestErrors0(t *testing.T) {
|
|||||||
r := bytes.NewBufferString(`This is a test!`)
|
r := bytes.NewBufferString(`This is a test!`)
|
||||||
|
|
||||||
var w bytes.Buffer
|
var w bytes.Buffer
|
||||||
if err := cli.Render(r, &w, nil); err != nil {
|
if err := cli.Compile(r, &w, nil); err != nil {
|
||||||
t.Fatalf("Failed to render document: %v", err)
|
t.Fatalf("Failed to compile document: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ func TestErrors1(t *testing.T) {
|
|||||||
#assert(1 < 1, message: "Test")`)
|
#assert(1 < 1, message: "Test")`)
|
||||||
|
|
||||||
var w bytes.Buffer
|
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")
|
t.Fatalf("Expected error, but got nil")
|
||||||
} else {
|
} else {
|
||||||
var errWithPath *typst.ErrorWithPath
|
var errWithPath *typst.ErrorWithPath
|
||||||
@ -65,7 +65,7 @@ func TestErrors2(t *testing.T) {
|
|||||||
r := bytes.NewBufferString(`This is a test!`)
|
r := bytes.NewBufferString(`This is a test!`)
|
||||||
|
|
||||||
var w bytes.Buffer
|
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")
|
t.Fatalf("Expected error, but got nil")
|
||||||
} else {
|
} else {
|
||||||
var errTypst *typst.Error
|
var errTypst *typst.Error
|
||||||
|
@ -39,7 +39,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
if err := typstCLI.RenderWithVariables(r, f, nil, map[string]any{"Data": TestData}); err != nil {
|
if err := typstCLI.CompileWithVariables(r, f, nil, map[string]any{"Data": TestData}); err != nil {
|
||||||
log.Panicf("Failed to render document: %v.", err)
|
log.Panicf("Failed to compile document: %v.", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ A library to generate documents and reports by utilizing the command line versio
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
if err := typstCLI.Render(r, f, nil); err != nil {
|
if err := typstCLI.Compile(r, f, nil); err != nil {
|
||||||
t.Fatalf("Failed to render document: %v.", err)
|
t.Fatalf("Failed to compile document: %v.", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,8 +184,8 @@ func TestVariableEncoder(t *testing.T) {
|
|||||||
typstCLI := typst.CLI{}
|
typstCLI := typst.CLI{}
|
||||||
input := strings.NewReader("#" + result.String())
|
input := strings.NewReader("#" + result.String())
|
||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
if err := typstCLI.Render(input, &output, nil); err != nil {
|
if err := typstCLI.Compile(input, &output, nil); err != nil {
|
||||||
t.Errorf("Compilation failed: %v", err)
|
t.Errorf("Failed to compile generated typst markup: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user