job

package
v0.11.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compiler

type Compiler string

Compiler represents the various compilers that are available

var (
	CC_PDFLatex Compiler = "pdflatex"
	CC_Latexmk  Compiler = "latexmk"
	CC_Default  Compiler = CC_Latexmk
)

func (Compiler) IsValid

func (c Compiler) IsValid() bool

type Delimiters

type Delimiters struct {
	Left  string
	Right string
}

Delimiters holds the left and right delimiters for a template

var BadDefaultDelimiters Delimiters = Delimiters{
	Left:  "{{",
	Right: "}}",
}
var DefaultDelimiters Delimiters = Delimiters{
	Left:  "#!",
	Right: "!#",
}
var EmptyDelimiters Delimiters = Delimiters{
	Left:  "",
	Right: "",
}

type Job

type Job struct {
	recon.Dir
	Template *template.Template
	Details  map[string]interface{}
	Opts     Options
}

Job represents the request for constructing a tex file from the template and details and then compiling that into a PDF.

func NewJob

func NewJob(root string, sc recon.SourceChain) *Job

func (*Job) AddResource

func (j *Job) AddResource(files ...string)

AddResource adds resource files to the Job that should be available in the root/working directory.

func (*Job) Compile

func (j *Job) Compile(ctx context.Context) (string, error)

Compile creates a tex file by filling in the template with the details and then compiles the results and returns the location of the resulting PDF.

func (*Job) GetDetails

func (j *Job) GetDetails(id string) error

GetDetails looks for a details file named id in the SourceChain and stores the results for later.

func (*Job) GetTemplate

func (j *Job) GetTemplate(id string) error

GetTemplate looks for a template named id in the SourceChain and parses it, storing the results for later use.

func (*Job) ParseQuery

func (j *Job) ParseQuery(q url.Values, cache *TemplateCache) error

ParseQuery takes url.Values and loads the template and resources referenced in q into the root directory.

type MissingKeyOpt

type MissingKeyOpt string

MissingKeyOpt controls how missing keys are handled when filling in a template

var (
	// MK_Error will cause an error if details is missing a key used in the template
	MK_Error MissingKeyOpt = "error"
	// MK_Zero will cause values whose keys are missing from details to be replace with a zero value.
	MK_Zero MissingKeyOpt = "zero"
	// MK_Nothing will cause missing keys to be ignored.
	MK_Nothing MissingKeyOpt = "nothing"
)

func (MissingKeyOpt) IsValid

func (mko MissingKeyOpt) IsValid() bool

func (MissingKeyOpt) Val

func (mko MissingKeyOpt) Val() string

type Options

type Options struct {
	// CC is the LaTeX compiler to use
	CC Compiler
	// N controls the number of compilations/passes.
	N uint
	// OnMissingKey controls how missing keys are handled when filling in the template
	OnMissingKey MissingKeyOpt
	// Delims holds the left and right delimiters to use for the template
	Delims Delimiters
}

Options holds the user settable options for a compilation job

var DefaultOptions Options = Options{
	CC:           CC_Default,
	N:            1,
	OnMissingKey: MK_Error,
	Delims:       DefaultDelimiters,
}

type Request

type Request struct {
	Template string `json:"template"`

	Details map[string]interface{} `json:"details"`

	Resources map[string]string `json:"resources"`

	Delimiters   Delimiters    `json:"delimiters"`
	OnMissingKey MissingKeyOpt `json:"onMissingKey"`
	Compiler     Compiler      `json:"compiler"`
	Count        uint          `json:"count"`
}

func (*Request) NewJob

func (r *Request) NewJob(root string, sc recon.SourceChain, cache *TemplateCache) (*Job, error)

type TemplateCache

type TemplateCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewTemplateCache

func NewTemplateCache(n int) (*TemplateCache, error)

func (*TemplateCache) Add

func (tc *TemplateCache) Add(key string, val interface{}) bool

func (*TemplateCache) Get

func (tc *TemplateCache) Get(key string) (interface{}, bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL