printer/templateprinter.go
changeset 85 a4464c0b0c36
parent 83 57afac822019
child 89 3758bb5f0979
equal deleted inserted replaced
84:5a894a10304c 85:a4464c0b0c36
    34 
    34 
    35 // NewPrinterTemplate returns a Template ResourcePrinter
    35 // NewPrinterTemplate returns a Template ResourcePrinter
    36 // For TemplatePrinter, the options parameter contains the template string.
    36 // For TemplatePrinter, the options parameter contains the template string.
    37 func NewPrinterTemplate(options Options) (*TemplatePrinter, error) {
    37 func NewPrinterTemplate(options Options) (*TemplatePrinter, error) {
    38 	tmpl := options["template"]
    38 	tmpl := options["template"]
       
    39 	if tmpl == "" {
       
    40 		return nil, fmt.Errorf("empty template")
       
    41 	}
    39 	t, err := template.New("output").Funcs(template.FuncMap{
    42 	t, err := template.New("output").Funcs(template.FuncMap{
    40 		"fromhtml": html2string,
    43 		"fromhtml": html2string,
    41 		"fromunix": unix2string,
    44 		"fromunix": unix2string,
    42 		"color":    ansiColor,
    45 		"color":    ansiColor,
    43 	}).Parse(tmpl)
    46 	}).Parse(tmpl)