templates

package
Version: v0.0.0-...-0c1db29 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2017 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LTrace   = log.New(ioutil.Discard, "TRACE:\t\t", log.Ldate|log.Ltime|log.Lshortfile)
	LInfo    = log.New(os.Stdout, "INFO:\t\t", log.Ldate|log.Ltime|log.Lshortfile)
	LWarning = log.New(os.Stdout, "WARNING:\t", log.Ldate|log.Ltime|log.Lshortfile)
	LError   = log.New(os.Stderr, "ERROR:\t\t", log.Ldate|log.Ltime|log.Lshortfile)

	ErrorPage string
)
View Source
var HttpMux = httprouter.New()

Functions

func BadRequest

func BadRequest(w http.ResponseWriter, r *http.Request)

func Execute

func Execute(w http.ResponseWriter, r *http.Request, templateName string, p *Page)

ExecuteTemplate executes the given template using the Page given, setting Cache-Control if unset

func ExecuteTemplateStatus

func ExecuteTemplateStatus(w http.ResponseWriter, r *http.Request, templateName string, p *Page, status int)

func Forbidden

func Forbidden(w http.ResponseWriter, r *http.Request)

func GET

func GET(url string, handler httprouter.Handle)

func GetLocale

func GetLocale(r *http.Request) int

GetLocale accesses the locale-integer set by LanguageHandler, and returning it - panics on failure.

func GetUrl

func GetUrl(r *http.Request, index int) string

GetUrl returns the localised-url for the given request

func GetUrlByLocale

func GetUrlByLocale(locale int, index int) string

GetUrlByLocale returns the localised-url for the given locale and url

func Init

func Init(c *Config)

Init makes sure all variables are set up correctly before any function can be used

func InternalServerError

func InternalServerError(w http.ResponseWriter, r *http.Request, e error)

func MakeMap

func MakeMap(keyValue ...interface{}) myMap

MakeMap allows the initialization of a myMap-instance, { key1, value1, key2, value2, ... }

func NotFound

func NotFound(w http.ResponseWriter, r *http.Request)

func NotImplemented

func NotImplemented(w http.ResponseWriter, r *http.Request)

func POST

func POST(url string, handler httprouter.Handle)

func PreloadTemplate

func PreloadTemplate(templateName ...string)

PreloadTemplate adds the given template names to the queue to be preloaded

func PreloadTemplates

func PreloadTemplates()

PreloadTemplates actually preloads the queued template names

func Render

func Render(c *iris.Context, tmpl string, p *Page)

func RenderWithStatus

func RenderWithStatus(c *iris.Context, templateName string, p *Page, status int)

func WriteInternalError

func WriteInternalError(w http.ResponseWriter, err string)

WriteInternalError writes the given error to the ResponseWriter as plaintext, and logs the error.

func WritePlain

func WritePlain(w http.ResponseWriter, status int, msg string)

WritePlain writes the given message to the ResponseWriter, with Status code 'status'

Types

type Alternative

type Alternative struct {
	Locale string
	Url    string
}

type Config

type Config struct {
	Locales       *map[string]int
	URLs          *map[int]map[int]string
	Language      *map[int]map[string]string
	ProjectView   string
	Handler       PageHandler
	DefaultLocale string
	Minify        bool
}

type Language

type Language struct {
	Nr    string
	Index int
	Name  string
}

type LazyInterface

type LazyInterface interface {
	String(loc int) string
}

type Page

type Page struct {
	Data   myMap
	Locale int
	Url    string

	Start time.Time
	// contains filtered or unexported fields
}

Page is a struct allowing data to be passed to the template

func NewPage

func NewPage(keyValue ...interface{}) *Page

func (*Page) ActiveLanguage

func (p *Page) ActiveLanguage() string

func (*Page) Alternatives

func (p *Page) Alternatives() []*Alternative

func (*Page) BenchNanoseconds

func (p *Page) BenchNanoseconds() int64

func (*Page) DefaultLanguage

func (p *Page) DefaultLanguage() string

func (*Page) DivideInt64

func (p *Page) DivideInt64(a, b int64) int64

func (*Page) Flush

func (p *Page) Flush() string

Flush allows the page to flush whatever can be flushed if SPDY is not used

func (*Page) FormatCurrency

func (p *Page) FormatCurrency(f float64) string

TODO: make efficient?

func (*Page) Get

func (p *Page) Get(key string) interface{}

func (*Page) GetUrl

func (p *Page) GetUrl(key int) string

func (*Page) IsSet

func (p *Page) IsSet(something interface{}) bool

func (*Page) Lang

func (p *Page) Lang(s string) string

func (*Page) Languages

func (p *Page) Languages() []Language

func (*Page) Lazy

func (p *Page) Lazy(lazy LazyInterface) string

func (*Page) Plus

func (p *Page) Plus(a, b int) int

func (*Page) Times

func (p *Page) Times(a, b float64) float64

func (*Page) Tuple

func (p *Page) Tuple(somethings ...interface{}) *Tuple

type PageHandler

type PageHandler interface {
	Handle(http.ResponseWriter, *http.Request, *Page)
}

func DefaultHandler

func DefaultHandler() PageHandler

type Tuple

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

func (*Tuple) Get

func (t *Tuple) Get(number int) interface{}

Jump to

Keyboard shortcuts

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