htmlengine

package
v0.0.0-...-ecdd364 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 10 Imported by: 1

README

htmlengine

Package htmlengine is an Ambient plugin that provides a HTML template engine.

Import: github.com/ambientkit/plugin/templateengine/htmlengine

Version: 1.0.0

Plugin Type

The plugin can be used as the following core types:

  • Logger: false
  • Storage System: false
  • Router: false
  • Template Engine: true
  • Session Manager: false

Grants

The plugin does not request any grants.

Settings

The plugin does not have any settings.

Routes

The plugin does not have any routes.

Middleware

The plugin does not have any middleware.

FuncMap

The plugin does not have a FuncMap.

Assets

The plugin does not inject any assets.

Embedded Files

The plugin does not have any embedded files.

Example Usage

package main

import (
	"log"

	"github.com/ambientkit/ambient"
	"github.com/ambientkit/ambient/pkg/ambientapp"
	"github.com/ambientkit/plugin/logger/zaplogger"
	"github.com/ambientkit/plugin/storage/memorystorage"
	"github.com/ambientkit/plugin/templateengine/htmlengine"
)

func main() {
	plugins := &ambient.PluginLoader{
		// Core plugins are implicitly trusted.
		Router:         nil,
		TemplateEngine: htmlengine.New(),
		SessionManager: nil,
		// Trusted plugins are those that are typically needed to boot so they
		// will be enabled and given full access.
		TrustedPlugins: map[string]bool{},
		Plugins:        []ambient.Plugin{},
		Middleware:     []ambient.MiddlewarePlugin{
			// Middleware - executes top to bottom.
		},
	}
	_, _, err := ambientapp.NewApp("myapp", "1.0",
		zaplogger.New(),
		ambient.StoragePluginGroup{
			Storage: memorystorage.New(),
		},
		plugins)
	if err != nil {
		log.Fatalln(err.Error())
	}
}

Docgen by Ambient

Documentation

Overview

Package htmlengine is an Ambient plugin that provides a HTML template engine.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine represents a HTML template engine.

func NewTemplateEngine

func NewTemplateEngine(logger ambient.Logger, assetInjector ambient.AssetInjector) *Engine

NewTemplateEngine returns a HTML template engine.

func (*Engine) Body

func (te *Engine) Body(t *template.Template, content string, fm template.FuncMap, data map[string]interface{}) (*template.Template, error)

Body -

func (*Engine) Error

func (te *Engine) Error(w http.ResponseWriter, r *http.Request, content string, statusCode int, fm func(r *http.Request) template.FuncMap, vars map[string]interface{}) (err error)

Error renders HTML to a response writer and returns a 404 status code and an error if one occurs.

func (*Engine) Footer

func (te *Engine) Footer(t *template.Template, content string, fm template.FuncMap, data map[string]interface{}) (*template.Template, error)

Footer -

func (*Engine) Head

func (te *Engine) Head(t *template.Template, content string, fm template.FuncMap, data map[string]interface{}) (*template.Template, error)

Head -

func (*Engine) Header

func (te *Engine) Header(t *template.Template, content string, fm template.FuncMap, data map[string]interface{}) (*template.Template, error)

Header -

func (*Engine) Main

func (te *Engine) Main(t *template.Template, content string, fm template.FuncMap, data map[string]interface{}) (*template.Template, error)

Main -

func (*Engine) Page

func (te *Engine) Page(w http.ResponseWriter, r *http.Request, assets ambient.FileSystemReader, partialTemplate string, fm func(r *http.Request) template.FuncMap, vars map[string]interface{}) (err error)

Page renders using the page layout.

func (*Engine) PageContent

func (te *Engine) PageContent(w http.ResponseWriter, r *http.Request, content string, fm func(r *http.Request) template.FuncMap, vars map[string]interface{}) (err error)

PageContent renders using the page content.

func (*Engine) Post

func (te *Engine) Post(w http.ResponseWriter, r *http.Request, assets ambient.FileSystemReader, partialTemplate string, fm func(r *http.Request) template.FuncMap, vars map[string]interface{}) (err error)

Post renders using the post layout.

func (*Engine) PostContent

func (te *Engine) PostContent(w http.ResponseWriter, r *http.Request, content string, fm func(r *http.Request) template.FuncMap, vars map[string]interface{}) (err error)

PostContent renders using the post content.

type Plugin

type Plugin struct{}

Plugin represents an Ambient plugin.

func New

func New() *Plugin

New returns an Ambient plugin that provides a HTML template engine.

Example
package main

import (
	"log"

	"github.com/ambientkit/ambient"
	"github.com/ambientkit/ambient/pkg/ambientapp"
	"github.com/ambientkit/plugin/logger/zaplogger"
	"github.com/ambientkit/plugin/storage/memorystorage"
	"github.com/ambientkit/plugin/templateengine/htmlengine"
)

func main() {
	plugins := &ambient.PluginLoader{
		// Core plugins are implicitly trusted.
		Router:         nil,
		TemplateEngine: htmlengine.New(),
		SessionManager: nil,
		// Trusted plugins are those that are typically needed to boot so they
		// will be enabled and given full access.
		TrustedPlugins: map[string]bool{},
		Plugins:        []ambient.Plugin{},
		Middleware:     []ambient.MiddlewarePlugin{
			// Middleware - executes top to bottom.
		},
	}
	_, _, err := ambientapp.NewApp("myapp", "1.0",
		zaplogger.New(),
		ambient.StoragePluginGroup{
			Storage: memorystorage.New(),
		},
		plugins)
	if err != nil {
		log.Fatalln(err.Error())
	}
}
Output:

func (*Plugin) PluginName

func (p *Plugin) PluginName() string

PluginName returns the plugin name.

func (*Plugin) PluginVersion

func (p *Plugin) PluginVersion() string

PluginVersion returns the plugin version.

func (*Plugin) TemplateEngine

func (p *Plugin) TemplateEngine(logger ambient.Logger, injector ambient.AssetInjector) (ambient.Renderer, error)

TemplateEngine returns a template engine.

Jump to

Keyboard shortcuts

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