hot

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

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

Go to latest
Published: Jun 30, 2016 License: MIT Imports: 10 Imported by: 0

README

Hot Build Status

Hot is a library for rendering hot golang templates. This means with hot you won't need to reload your application everytime you edit your templates.Hot watches for file changes in your templates directory and reloads everytime you make changes to your files.

hot renders go templates using html/template package.

Installation

go get github.com/gernest/hot

Usage

Just pass the configuration object to hot.New

package main

import (
    "os"

    "github.com/gernest/hot"
)

func main() {
    config := &hot.Config{
        Watch:          true,
        BaseName:       "hot",
        Dir:            "fixtures",
        FilesExtension: []string{".tpl", ".html", ".tmpl"},
    }

    tpl, err := hot.New(config)
    if err != nil {
        panic(err)
    }

    // execute the template named "hello.tpl
    tpl.Execute(os.Stdout, "hello.tpl", nil)
}

Note that the fixtures directory should exist and there is a template file hello.tpl in it , hot will be watching any changes to the files inside this directory.

configuration

The hot.Config object is used to configure the hot template

property details
Watch If set to true, the hot reload is enabled
BaseName Is the root template name, e.g "base", "hot" etc
Dir The directory in which you keep your templates
FilesExtension Supported file extensions. These are the ones parsed in the template.
Funcs (optional) A map of names to functions that can be used inside your templates. (more information)
LeftDelim left template delimiter e.g {{
RightDelim rignt template delimiter e.g }}

Contributing

Start with clicking the star button to make the author and his neighbors happy. Then fork the repository and submit a pull request for whatever change you want to be added to this project.

If you have any questions, just open an issue.

Author

Geofrey Ernest

Twitter : @gernesti

Licence

This project is released under the MIT licence. See LICENCE for more details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Watch          bool
	BaseName       string
	Dir            string
	Funcs          template.FuncMap
	LeftDelim      string
	RightDelim     string
	FilesExtension []string
	Log            io.Writer
}

type Template

type Template struct {
	Out io.Writer
	// contains filtered or unexported fields
}

func New

func New(cfg *Config) (*Template, error)

func (*Template) Execute

func (t *Template) Execute(w io.Writer, name string, ctx interface{}) error

func (*Template) Init

func (t *Template) Init()

func (*Template) Load

func (t *Template) Load(dir string) error

func (*Template) Reload

func (t *Template) Reload()

Jump to

Keyboard shortcuts

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