docTemp

package module
v0.0.0-...-dc8b9ba Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: CC0-1.0 Imports: 6 Imported by: 1

README

Simple Google Go (golang) library for building templates for generic content

Go Report Card

func main() {
	funcMap := template.FuncMap{"title": strings.Title}
	docTemp, _ := GetTemplate("docx/fixtures/test.docx")
	docTemp.AddFunctions(funcMap)
	docTemp.Parse()
	docTemp.Execute("test.docx", nil)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DocTemplate

type DocTemplate struct {
	Template *template.Template
	Document Document
}

DocTemplate struct combines data and methods from both the Document interface and golang's templating library

func GetTemplate

func GetTemplate(filePath string) (*DocTemplate, error)

GetTemplate uses the file extension to determine the correct document struct to use

func (*DocTemplate) AddFunctions

func (docTemplate *DocTemplate) AddFunctions(funcMap template.FuncMap)

AddFunctions adds functions to the template

func (*DocTemplate) Execute

func (docTemplate *DocTemplate) Execute(exportPath string, data interface{}) error

Execute func runs the template and sends the output to the export path

func (*DocTemplate) Parse

func (docTemplate *DocTemplate) Parse()

Parse parses the template

type Document

type Document interface {
	ReadFile(string) error
	UpdateContent(string)
	GetContent() string
	WriteToFile(string, string) error
	Close() error
}

Document interface is a combintation of methods use for generic data files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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