view

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2018 License: MIT Imports: 13 Imported by: 5

README

View Engine library by aah framework

Build Status Code Coverage Go Report Card Release Version Godoc

View Engine library provides enhanced Go template engine which supports partial template inheritance, imports, etc.

News

  • v0.9.0 released and tagged on Jul 06, 2018.

Installation

go get -u aahframework.org/view.v0

Visit official website https://aahframework.org to learn more about aah framework.

Documentation

Overview

Package view is implementation of aah framework view engine using Go Template engine. It supports multi-layouts, no-layout, partial inheritance and error pages.

Index

Constants

View Source
const Version = "0.9.0"

Version no. of aah framework view library

Variables

View Source
var (
	// TemplateFuncMap aah framework Go template function map.
	TemplateFuncMap = make(template.FuncMap)

	// DefaultDelimiter template default delimiter
	DefaultDelimiter = "{{.}}"
)
View Source
var (
	ErrTemplateEngineIsNil = errors.New("view: engine value is nil")
	ErrTemplateNotFound    = errors.New("view: template not found")
	ErrTemplateKeyExists   = errors.New("view: template key exists")
)

view error messages

Functions

func AddEngine

func AddEngine(name string, engine Enginer) error

AddEngine method adds the given name and engine to view store.

func AddTemplateFunc

func AddTemplateFunc(funcMap template.FuncMap)

AddTemplateFunc method adds given Go template funcs into function map.

func StripPathPrefixAt added in v0.8.1

func StripPathPrefixAt(str, pathCut string) string

StripPathPrefixAt method strips the given path to path cut position.

For Example:

path := "/Users/jeeva/go/src/github.com/go-aah/tutorials/form/views/common/header.html"
result := StripPrefixAt(path, "views/")

func TrimPathPrefix added in v0.8.1

func TrimPathPrefix(prefix string, fpaths ...string) string

TrimPathPrefix method trims given file paths by prefix and returns comma separated string.

Types

type EngineBase added in v0.8.1

type EngineBase struct {
	CaseSensitive   bool
	IsLayoutEnabled bool

	Name       string
	BaseDir    string
	FileExt    string
	LeftDelim  string
	RightDelim string
	AppConfig  *config.Config
	Templates  map[string]*Templates
	VFS        *vfs.VFS
	// contains filtered or unexported fields
}

EngineBase struct is to create common and repurpose the implementation. Could be used for custom view engine implementation.

func (*EngineBase) AddTemplate added in v0.8.1

func (eb *EngineBase) AddTemplate(layout, key string, tmpl *template.Template) error

AddTemplate method adds the given template for layout and key.

func (*EngineBase) AutoFieldInsertion added in v0.9.0

func (eb *EngineBase) AutoFieldInsertion(name, v string) string

AutoFieldInsertion method processes the aah view's to auto insert the field.

func (*EngineBase) DirsPath added in v0.8.1

func (eb *EngineBase) DirsPath(subDir string) ([]string, error)

DirsPath method returns all sub directories from `<view-base-dir>/<sub-dir-name>`. if it not exists returns error.

func (*EngineBase) FilesPath added in v0.8.1

func (eb *EngineBase) FilesPath(subDir string) ([]string, error)

FilesPath method returns all file path from `<view-base-dir>/<sub-dir-name>`. if it not exists returns error.

func (*EngineBase) Get added in v0.8.1

func (eb *EngineBase) Get(layout, tpath, tmplName string) (*template.Template, error)

Get method returns the template based given name if found, otherwise nil.

func (*EngineBase) Init added in v0.8.1

func (eb *EngineBase) Init(fs *vfs.VFS, appCfg *config.Config, baseDir, defaultEngineName, defaultFileExt string) error

Init method is to initialize the base fields values.

func (*EngineBase) LayoutFiles added in v0.8.1

func (eb *EngineBase) LayoutFiles() ([]string, error)

LayoutFiles method returns the all layout files from `<view-base-dir>/layouts`. If layout directory doesn't exists it returns error.

func (*EngineBase) NewTemplate added in v0.8.1

func (eb *EngineBase) NewTemplate(key string) *template.Template

NewTemplate method return new instance on `template.Template` initialized with key, template funcs and delimiters.

func (*EngineBase) Open added in v0.9.0

func (eb *EngineBase) Open(filename string) (string, error)

Open method reads template from VFS if not found resolve from physical file system. Also does auto field insertion such as Anti-CSRF(anti_csrf_token) and requested page URL (_rt).

func (*EngineBase) ParseErrors added in v0.8.1

func (eb *EngineBase) ParseErrors(errs []error) error

ParseErrors method to parse and log the template error messages.

func (*EngineBase) ParseFile added in v0.9.0

func (eb *EngineBase) ParseFile(filename string) (*template.Template, error)

ParseFile method parses given single file.

func (*EngineBase) ParseFiles added in v0.9.0

func (eb *EngineBase) ParseFiles(t *template.Template, filenames ...string) (*template.Template, error)

ParseFiles method parses given files with given template instance.

func (*EngineBase) SetHotReload added in v0.9.0

func (eb *EngineBase) SetHotReload(r bool)

SetHotReload method set teh view engine mode into hot reload without watcher.

type Enginer

type Enginer interface {
	Init(fs *vfs.VFS, appCfg *config.Config, baseDir string) error
	Get(layout, path, tmplName string) (*template.Template, error)
}

Enginer interface defines a methods for pluggable view engine.

func GetEngine

func GetEngine(name string) (Enginer, bool)

GetEngine method returns the view engine from store by name otherwise nil.

type GoViewEngine

type GoViewEngine struct {
	*EngineBase
}

GoViewEngine implements the partial inheritance support with Go templates.

func (*GoViewEngine) Init

func (e *GoViewEngine) Init(fs *vfs.VFS, appCfg *config.Config, baseDir string) error

Init method initialize a template engine with given aah application config and application views base path.

type Templates

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

Templates hold template reference of lowercase key and case sensitive key with reference to compliled template.

func (*Templates) Add added in v0.8.1

func (t *Templates) Add(key string, tmpl *template.Template) error

Add method adds the given template for the key.

func (*Templates) IsExists added in v0.8.1

func (t *Templates) IsExists(key string) bool

IsExists method returns true if template key exists otherwise false.

func (*Templates) Keys added in v0.8.1

func (t *Templates) Keys() []string

Keys method returns all the template keys.

func (*Templates) Lookup added in v0.8.1

func (t *Templates) Lookup(key string) *template.Template

Lookup method return the template for given key.

Jump to

Keyboard shortcuts

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