gin_pongo2

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

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

Go to latest
Published: Aug 5, 2016 License: MIT Imports: 6 Imported by: 0

README

gin_pongo2

pongo2 middleware for Gin framework.

##Example:

package main

import (
    "os"

    "github.com/gin-gonic/gin"
    "github.com/stepan-perlov/gin_pongo2"
    "github.com/flosch/pongo2"
)

func main() {
    switch os.Getenv("MODE") {
    case "RELEASE":
        gin.SetMode(gin.ReleaseMode)

    case "DEBUG":
        gin.SetMode(gin.DebugMode)

    case "TEST":
        gin.SetMode(gin.TestMode)

    default:
        gin.SetMode(gin.ReleaseMode)
    }

    engine := gin.New()
    engine.Use(gin.Recovery())

    if gin.IsDebugging() {
        engine.HTMLRender = gin_pongo2.NewDebug("resources")
    } else {
        engine.HTMLRender = gin_pongo2.NewProduction("resources")
    }

    engine.Static("/static", "resources/static")
    engine.GET("/", func(c *gin.Context) {
        c.HTML(http.StatusOK, "index.tpl", pongo2.Context{"title": "Gin-pongo2!"})
    })
    engine.GET("/other", func(c *gin.Context) {
        # if key not exists in second paramter
        # copy data from c.Keys to pongo2.Context
        c.HTML(http.StatusOK, "other.tpl", gin_pongo2.MakeContext(c, map[string]interface{}{}))
    })

    engine.Run(":3000")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pongo

type Pongo struct {
	Template *pongo2.Template
	Name     string
	Data     interface{}
}

func (Pongo) Render

func (p Pongo) Render(w http.ResponseWriter) error

type PongoDebug

type PongoDebug struct {
	Path string
}

func NewDebug

func NewDebug(path string) *PongoDebug

func (PongoDebug) Instance

func (p PongoDebug) Instance(name string, data interface{}) render.Render

type PongoProduction

type PongoProduction struct {
	Templates map[string]*pongo2.Template
	Path      string
}

func NewProduction

func NewProduction(path string) *PongoProduction

func (PongoProduction) Instance

func (p PongoProduction) Instance(name string, data interface{}) render.Render

Jump to

Keyboard shortcuts

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