...

Package loaders

import "github.com/noirbizarre/gonja/loaders"
Overview
Index

Overview ▾

type FilesystemLoader

FilesystemLoader represents a local filesystem loader with basic BaseDirectory capabilities. The access to the local filesystem is unrestricted.

type FilesystemLoader struct {
    // contains filtered or unexported fields
}

func MustNewFileSystemLoader

func MustNewFileSystemLoader(root string) *FilesystemLoader

MustNewFileSystemLoader creates a new FilesystemLoader instance and panics if there's any error during instantiation. The parameters are the same like NewFileSystemLoader.

func NewFileSystemLoader

func NewFileSystemLoader(root string) (*FilesystemLoader, error)

NewFileSystemLoader creates a new FilesystemLoader and allows templatesto be loaded from disk (unrestricted). If any base directory is given (or being set using SetBaseDir), this base directory is being used for path calculation in template inclusions/imports. Otherwise the path is calculated based relatively to the including template's path.

func (*FilesystemLoader) Get

func (fs *FilesystemLoader) Get(path string) (io.Reader, error)

Get reads the path's content from your local filesystem.

func (*FilesystemLoader) Path

func (fs *FilesystemLoader) Path(name string) (string, error)

Path resolves a filename relative to the base directory. Absolute paths are allowed. When there's no base dir set, the absolute path to the filename will be calculated based on either the provided base directory (which might be a path of a template which includes another template) or the current working directory.

func (*FilesystemLoader) SetBaseDir

func (fs *FilesystemLoader) SetBaseDir(path string) error

SetBaseDir sets the template's base directory. This directory will be used for any relative path in filters, tags and From*-functions to determine your template. See the comment for NewFileSystemLoader as well.

type Loader

TemplateLoader allows to implement a virtual file system.

type Loader interface {

    // Get returns an io.Reader where the template's content can be read from.
    Get(path string) (io.Reader, error)
}

type SandboxedFilesystemLoader

SandboxedFilesystemLoader is still WIP.

type SandboxedFilesystemLoader struct {
    *FilesystemLoader
}

func NewSandboxedFilesystemLoader

func NewSandboxedFilesystemLoader(root string) (*SandboxedFilesystemLoader, error)

NewSandboxedFilesystemLoader creates a new sandboxed local file system instance.