mirror of
https://github.com/Dadido3/go-typst.git
synced 2025-11-20 03:49:34 +00:00
Rename Options to OptionsCompile as there will be different options for different Typst commands in the future
This commit is contained in:
parent
24c09dfcbe
commit
a075fb41bf
@ -21,5 +21,5 @@ type Caller interface {
|
||||
|
||||
// Compile takes a Typst document from the supplied input reader, and renders it into the output writer.
|
||||
// The options parameter is optional, and can be nil.
|
||||
Compile(input io.Reader, output io.Writer, options *Options) error
|
||||
Compile(input io.Reader, output io.Writer, options *OptionsCompile) error
|
||||
}
|
||||
|
||||
@ -7,5 +7,5 @@ package typst
|
||||
|
||||
// CLIOptions contains all parameters that can be passed to a Typst CLI.
|
||||
//
|
||||
// Deprecated: Use typst.Options instead.
|
||||
type CLIOptions = Options
|
||||
// Deprecated: Use typst.OptionsCompile instead.
|
||||
type CLIOptions = OptionsCompile
|
||||
|
||||
10
cli.go
10
cli.go
@ -89,13 +89,13 @@ func (c CLI) Fonts() ([]string, error) {
|
||||
}
|
||||
|
||||
// Compile takes a Typst document from input, and renders it into the output writer.
|
||||
// The options parameter is optional.
|
||||
func (c CLI) Compile(input io.Reader, output io.Writer, options *Options) error {
|
||||
// The options parameter is optional, and can be nil.
|
||||
func (c CLI) Compile(input io.Reader, output io.Writer, options *OptionsCompile) error {
|
||||
args := []string{"c"}
|
||||
if options != nil {
|
||||
args = append(args, options.Args()...)
|
||||
}
|
||||
args = append(args, "--diagnostic-format", "human", "-", "-") // TODO: Move these default arguments into Options
|
||||
args = append(args, "--diagnostic-format", "human", "-", "-") // TODO: Move these default arguments into OptionsCompile
|
||||
|
||||
// Get path of executable.
|
||||
execPath := ExecutablePath
|
||||
@ -127,12 +127,12 @@ func (c CLI) Compile(input io.Reader, output io.Writer, options *Options) error
|
||||
}
|
||||
|
||||
// CompileWithVariables takes a Typst document from input, and renders it into the output writer.
|
||||
// The options parameter is optional.
|
||||
// The options parameter is optional, and can be nil.
|
||||
//
|
||||
// Additionally this will inject the given map of variables into the global scope of the Typst document.
|
||||
//
|
||||
// Deprecated: You should use typst.InjectValues in combination with the normal Compile method instead.
|
||||
func (c CLI) CompileWithVariables(input io.Reader, output io.Writer, options *Options, variables map[string]any) error {
|
||||
func (c CLI) CompileWithVariables(input io.Reader, output io.Writer, options *OptionsCompile, variables map[string]any) error {
|
||||
varBuffer := bytes.Buffer{}
|
||||
|
||||
if err := InjectValues(&varBuffer, variables); err != nil {
|
||||
|
||||
@ -49,7 +49,7 @@ func TestCLI_Compile(t *testing.T) {
|
||||
|
||||
#lorem(5)`)
|
||||
|
||||
opts := typst.Options{
|
||||
opts := typst.OptionsCompile{
|
||||
Format: typst.OutputFormatPNG,
|
||||
PPI: ppi,
|
||||
}
|
||||
|
||||
@ -95,8 +95,8 @@ func (d Docker) Fonts() ([]string, error) {
|
||||
}
|
||||
|
||||
// Compile takes a Typst document from input, and renders it into the output writer.
|
||||
// The options parameter is optional.
|
||||
func (d Docker) Compile(input io.Reader, output io.Writer, options *Options) error {
|
||||
// The options parameter is optional, and can be nil.
|
||||
func (d Docker) Compile(input io.Reader, output io.Writer, options *OptionsCompile) error {
|
||||
image := DockerDefaultImage
|
||||
if d.Image != "" {
|
||||
image = d.Image
|
||||
|
||||
@ -48,7 +48,7 @@ func TestDocker_Compile(t *testing.T) {
|
||||
|
||||
#lorem(5)`)
|
||||
|
||||
opts := typst.Options{
|
||||
opts := typst.OptionsCompile{
|
||||
Format: typst.OutputFormatPNG,
|
||||
PPI: ppi,
|
||||
}
|
||||
@ -84,7 +84,7 @@ func TestDocker_CompileWithWorkingDir(t *testing.T) {
|
||||
#show: doc => template()`)
|
||||
|
||||
var w bytes.Buffer
|
||||
err := typstCaller.Compile(r, &w, &typst.Options{Root: "/markup"})
|
||||
err := typstCaller.Compile(r, &w, &typst.OptionsCompile{Root: "/markup"})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to compile document: %v.", err)
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ func TestErrors1(t *testing.T) {
|
||||
func TestErrors2(t *testing.T) {
|
||||
cli := typst.CLI{}
|
||||
|
||||
opts := typst.Options{
|
||||
opts := typst.OptionsCompile{
|
||||
Pages: "a",
|
||||
}
|
||||
|
||||
|
||||
@ -45,8 +45,8 @@ const (
|
||||
PDFStandardUA_1 PDFStandard = "ua-1" // PDF/UA-1 (Available since Typst 0.14.0)
|
||||
)
|
||||
|
||||
// Options contains all parameters that can be passed to a Typst CLI.
|
||||
type Options struct {
|
||||
// OptionsCompile contains all parameters for the compile command.
|
||||
type OptionsCompile struct {
|
||||
Root string // Configures the project root (for absolute paths).
|
||||
Input map[string]string // String key-value pairs visible through `sys.inputs`.
|
||||
FontPaths []string // Adds additional directories that are recursively searched for fonts.
|
||||
@ -77,7 +77,7 @@ type Options struct {
|
||||
}
|
||||
|
||||
// Args returns a list of CLI arguments that should be passed to the executable.
|
||||
func (c *Options) Args() (result []string) {
|
||||
func (c *OptionsCompile) Args() (result []string) {
|
||||
if c.Root != "" {
|
||||
result = append(result, "--root", c.Root)
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestOptions(t *testing.T) {
|
||||
o := typst.Options{
|
||||
o := typst.OptionsCompile{
|
||||
FontPaths: []string{"somepath/to/somewhere", "another/to/somewhere"},
|
||||
}
|
||||
args := o.Args()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user