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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址