gintemplater

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2019 License: MIT Imports: 8 Imported by: 0

README

Gin Templater

A specialized gin gonic framework's templating system. It allows you to use multi level folders for the sake of your convenience and provide you with the ability to Hot Reload your HTML Code without restarting your Gin Web Server. Useful if you don't like to wait to recompile your Gin instance and get your web interface response imediately.

Usage

By default Gin Templater will read from "view" directory and will output it's build to "cache/view" but can be overriden in the config. You can also disable the Hot Reload feature in the directory.

Here is the directory structure for the view :

view/
    -home/
        -deep.html
    -part/
        -greetings.html
        -who.html
    -home.html

And here is the minimum working code to use Gin Templater :

engine := gin.Default()
config := gintemplater.NewConfig()
templater := gintemplater.NewTemplater(engine, config)
templater.Run()

engine.GET("/", func(ctx *gin.Context) {
    ctx.HTML(http.StatusOK, "home.html", gin.H{
        "message": "Hello!",
        "who":     "A Message",
    })
})

engine.GET("/deep", func(ctx *gin.Context) {
    ctx.HTML(http.StatusOK, "home.deep.html", gin.H{
        "message": "Hello!",
        "who":     "A Deeper Message",
    })
})

engine.Run()

Example

For more information please see Example.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	AutoReload bool
	InputDir   string
	OutputDir  string
}

Config hold configuration for Templater

func NewConfig

func NewConfig() *Config

NewConfig return a new instance of Config with following properties AutoReload set to true InputDir set to view OutputDir set to cache/view

type Templater

type Templater struct {
	// contains filtered or unexported fields
}

Templater instance to perform hot reload on Gin Web Framework

func NewTemplater

func NewTemplater(engine *gin.Engine, conf *Config) *Templater

NewTemplater will return a new and ready to use Templater instance

func (*Templater) Run

func (t *Templater) Run()

func (*Templater) Stop

func (t *Templater) Stop()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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