jetrenderer

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2020 License: MIT Imports: 4 Imported by: 5

README

Renderer implementation of Jet template engine

Build Status Coverage Status Go.Dev reference Go Report Card Release Downloads Chat Community

Usage

See example.

package main

import (
	"io"
	"net/http"
	"strings"

	"github.com/CloudyKit/jet/v5"
	"clevergo.tech/clevergo"
	"clevergo.tech/jetrenderer"
)

func main() {
	renderer := jetrenderer.New(jet.NewHTMLSet("./views"))
	renderer.SetBeforeRender(func(w io.Writer, name string, vars jet.VarMap, data interface{}, ctx *clevergo.Context) error {
		// populate variables and functions
		// vars.Set("user", user) // user instance.
		// vars.SetFunc("T", translate) // i18n translator.
		return nil
	})

	app := clevergo.New()
	app.Renderer = renderer
	app.Get("/", func(ctx *clevergo.Context) error {
		return ctx.Render(http.StatusOK, "index.tmpl", map[string]interface{}{
			"message": "hello world",
		})
	})
	app.Run(":8080")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BeforeRender

type BeforeRender func(w io.Writer, name string, vars jet.VarMap, data interface{}, ctx *clevergo.Context) error

BeforeRender is a listener that listen the event which trigger before rendering.

type Renderer

type Renderer struct {
	*jet.Set
	// contains filtered or unexported fields
}

Renderer implementation of clevergo.Renderer for Jet template engine.

func New

func New(set *jet.Set) *Renderer

New returns a renderer with the given set.

func (*Renderer) Render

func (r *Renderer) Render(w io.Writer, name string, data interface{}, ctx *clevergo.Context) error

Render implements clevergo.Renderer.Render.

func (*Renderer) SetBeforeRender

func (r *Renderer) SetBeforeRender(fn BeforeRender)

SetBeforeRender sets before render listener.

Jump to

Keyboard shortcuts

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