loader

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2022 License: MIT Imports: 4 Imported by: 2

README

pongo2-embed-loader

Build Status Coverage Status Go Report Card Go Reference MIT License

pongo2 provides Django-like templates for Go applications. However, it does not provide native support for the new embed directive introduced in Go 1.16. This package aims to fill that gap by providing a TemplateLoader for embedded files.

Usage

The package is extremely easy to use.

Assuming you have a directory named templates in the current source directory, you can create a template set with:

import "github.com/nathan-osman/pongo2-embed-loader"

//go:embed templates/*
var content embed.FS

templateSet := pongo2.NewSet("", &loader.Loader{Content: content})

You can then retrieve a template with:

t, err := templateSet.FromFile("templates/file.tpl")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

type Loader struct {
	Content fs.FS
}

Loader implements pongo2's TemplateLoader interface for templates stored in a fs.FS (such as an embed.FS).

func (*Loader) Abs

func (l *Loader) Abs(base, name string) string

Abs returns the absolute path for the specified template.

func (*Loader) Get

func (l *Loader) Get(path string) (io.Reader, error)

Get creates a reader for the specified template.

Jump to

Keyboard shortcuts

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