...

Source file src/github.com/noirbizarre/gonja/exec/config.go

Documentation: github.com/noirbizarre/gonja/exec

     1  package exec
     2  
     3  import (
     4  	"github.com/pkg/errors"
     5  
     6  	"github.com/noirbizarre/gonja/config"
     7  	"github.com/noirbizarre/gonja/nodes"
     8  )
     9  
    10  type EvalConfig struct {
    11  	*config.Config
    12  	Filters    *FilterSet
    13  	Globals    *Context
    14  	Statements *StatementSet
    15  	Tests      *TestSet
    16  	Loader     TemplateLoader
    17  }
    18  
    19  func NewEvalConfig(cfg *config.Config) *EvalConfig {
    20  	return &EvalConfig{
    21  		Config:     cfg,
    22  		Globals:    EmptyContext(),
    23  		Filters:    &FilterSet{},
    24  		Statements: &StatementSet{},
    25  		Tests:      &TestSet{},
    26  	}
    27  }
    28  
    29  func (cfg *EvalConfig) Inherit() *EvalConfig {
    30  	return &EvalConfig{
    31  		Config:     cfg.Config.Inherit(),
    32  		Globals:    cfg.Globals,
    33  		Filters:    cfg.Filters,
    34  		Statements: cfg.Statements,
    35  		Tests:      cfg.Tests,
    36  		Loader:     cfg.Loader,
    37  	}
    38  }
    39  
    40  func (cfg *EvalConfig) GetTemplate(filename string) (*nodes.Template, error) {
    41  	tpl, err := cfg.Loader.GetTemplate(filename)
    42  	if err != nil {
    43  		return nil, errors.Wrapf(err, `Unable to parse template "%s"`, filename)
    44  	}
    45  	return tpl.Root, nil
    46  }
    47  

View as plain text