gonocular

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

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

Go to latest
Published: Aug 9, 2014 License: Apache-2.0 Imports: 9 Imported by: 1

README

gonocular

Build Status Coverage Status GoDoc

Gonocular

Extremely lightweight wrapper for go's html/template package with dev-time friendly error messages (originally inspired by revel's template support). If gonocular.ProductionMode() is called the package falls back to the standard behavior of causing a panic if the template cannot be parsed with no friendly error messages.

Example Usage

package home

import (
	"github.com/CoreyKaylor/gonocular"
	"net/http"
)

var (
	homeTemplate = gonocular.TemplateFiles("../templates/layout.html", "index.html").Template()
)

func Index(rw http.ResponseWriter, r *http.Request) {
	homeTemplate.RenderHTML(rw, nil)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DevMode

func DevMode()

DevMode changes the template behavior to include error details. This is the default behavior.

func ProductionMode

func ProductionMode()

ProductionMode makes the template behavior panic only when there is an error. This is equivalent to calling template.Must(...

Types

type DevModeRenderer

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

DevModeRenderer is responsible for rendering templates and when an error occurs will output the error details

func (*DevModeRenderer) RenderHTML

func (r *DevModeRenderer) RenderHTML(wr http.ResponseWriter, data interface{})

RenderHTML will render an html/template or in the case of an error will display an errorpage with the error details.

type ParseError

type ParseError struct {
	FileName     string
	ErrorMessage string
	LineNumber   int
}

ParseError is details the error template uses to render the error page

func (*ParseError) SourceLines

func (p *ParseError) SourceLines() []*SourceLine

SourceLines will parse out the error details of a template error.

type ProductionRenderer

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

ProductionRenderer is responsible for only rendering the template and will panic in the occurrence of an error. This is equivalent to template.Must(...

func (*ProductionRenderer) RenderHTML

func (r *ProductionRenderer) RenderHTML(wr http.ResponseWriter, data interface{})

RenderHTML will render an html/template file and panic if there is an error

type Renderer

type Renderer interface {
	RenderHTML(wr http.ResponseWriter, data interface{})
}

Renderer is the template rendering interface

type SourceLine

type SourceLine struct {
	Line     int
	HasError bool
	Text     string
}

SourceLine is the detail about a single line in a template file used for rendering the error page.

type TemplateBuilder

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

TemplateBuilder is responsible for building the collection of template files.

func TemplateFiles

func TemplateFiles(filenames ...string) *TemplateBuilder

TemplateFiles is the list of file paths relative from the callers code file.

func (*TemplateBuilder) Template

func (v *TemplateBuilder) Template() Renderer

Template will return the Dev or Production Renderer implementation based on current settings

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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