jetrenderer

package module
Version: v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: MIT Imports: 4 Imported by: 0

README

Renderer implementation of Jet template engine

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

JetRenderer Jet
v1 v5
v2 v6

Usage

See example.

package main

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

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

func main() {
	renderer := jetrenderer.New(jet.New(jet.NewOSFileSystemLoader("./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.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto