jaderender

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

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

Go to latest
Published: Feb 12, 2016 License: MIT Imports: 5 Imported by: 0

README

jaderender

Package jaderender is a Jade template renderer that can be used with the Gin web framework.
It uses the gojade template library.

Usage

To use jaderender you need to set your router.HTMLRenderer to a new renderer instance, this is done after creating the Gin router when the Gin application starts up. You can use jaderender.Default() to create a new renderer with default options, this assumes templates will be located in the "views" directory, or you can use jaderender.New() to specify a custom location. This jaderender implementation also comes with build-in LRU cache of adjustable size.

To render templates from a route, call c.HTML just as you would with regular Gin templates.

Basic Example

import (
    "github.com/gin-gonic/gin"
    "github.com/MAD-GooZe/jaderender"
)

func main() {
    router := gin.Default()

    // Use jaderender.Default() for default options or jaderender.New()
    // if you need to use custom RenderOptions.
    router.HTMLRender = jaderender.Default()

    router.GET("/", func(c *gin.Context) {
        c.HTML(200, "hello.html", gin.H{"name": "world"})
    })

    router.Run(":8080")
}

RenderOptions

When calling jaderender.New() instead of jaderender.Default() you can use these custom RenderOptions:

type RenderOptions struct {
    TemplateDir string  // location of the template directory; default "views"
    Beautify    bool    // beautify the resulting HTML; default false
    CacheSize   int     // LRU cache maximum size (in pages); zero value turns off caching; default: 128
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomFunction

type CustomFunction struct {
	Name     string
	Function interface{}
}

type JadeRender

type JadeRender struct {
	Template     *gojade.Engine
	Context      interface{}
	TemplateName string
	// contains filtered or unexported fields
}

JadeRender is a custom Gin template renderer using gojade.

func Default

func Default() *JadeRender

Default creates a JadeRender instance with default options.

func New

func New(options RenderOptions) *JadeRender

New creates a new JadeRender instance with custom Options.

func (*JadeRender) Instance

func (this *JadeRender) Instance(templateName string, data interface{}) render.Render

Instance should return a new JadeRender struct per request

func (JadeRender) Render

func (this JadeRender) Render(w http.ResponseWriter) error

Render should render the template to the response.

type RenderOptions

type RenderOptions struct {
	TemplateDir string
	Beautify    bool
	CacheSize   int

	CustomFunctions []CustomFunction
}

RenderOptions is used to configure the renderer.

Jump to

Keyboard shortcuts

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