sitekit

package
v0.1.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 17 Imported by: 1

README

DM Sitekit

Sitekit is a toolkit which is used to build sites in a 'template way'.

Core features
  • easy templating
  • multi sites support
  • load multi sites from yaml config file or api, or both.
  • powerful template override based on content conditions
  • nice url(from niceurl package) and extendable
  • extend site router with templating
  • customize template functions, filters, macro
Template engine

The template engine used is pongo2 https://github.com/flosch/pongo2.

Demosite

See Demosite for example use.

Template Functions

Examples:

Fetch content by id:

{%set content = dm.fetch_byid(8)%}

Fetch children:

{%set children = dm.children( content, "article" )%}
Filters

Output variable:

{{var|dmshow}}

Format time to local:

{{timestamp|dm_format_time}}
Template Override

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetContentTemplate

func GetContentTemplate(content contenttype.ContentTyper, viewmode string, settings SiteSettings, ctx context.Context) string

Get content view template.

func GetSitePath

func GetSitePath(r *http.Request) string

remove / if path has / in the end

func GetSiteRouters

func GetSiteRouters(r *mux.Router) (SiteRouters, SiteRouters)

func GetSites

func GetSites() []string

func HandleContent

func HandleContent(w http.ResponseWriter, r *http.Request)

Handle content, given mux variables: site: <site>, path: <site path>, id: <content id>

func InitRequest

func InitRequest(next http.Handler) http.Handler

func LoadSite

func LoadSite(siteConfig map[string]interface{}) error

Initialize sites setting to memory

func MatchTemplate

func MatchTemplate(source string, matchData map[string]interface{}, overrideFile string) (string, []string)

MatchTemplate returns overrided template based on override rule in template_override.yaml

func Output

func Output(w io.Writer, variables map[string]interface{}, ctx context.Context) error

Output using template

func OutputContent

func OutputContent(w io.Writer, id int, siteIdentifier string, sitePath string, ctx context.Context) error

Output content using conent template

func RegisterFunctions

func RegisterFunctions(name string, implementation func() TemplateFunctions)

Register a set of functions name: 'namespace' of functions

func RouteContent

func RouteContent(siteRouters SiteRouters, defaultRouters SiteRouters)

Handle contents after initialization

func SetSiteSettings

func SetSiteSettings(identifier string, settings SiteSettings)

func TemplateFolder

func TemplateFolder() string

TemplateFolder() returns folder of templates. eg. under "templates" or "web/templates"

Types

type NewFunctions

type NewFunctions = func() TemplateFunctions

type RequestInfo

type RequestInfo struct {
	Context  context.Context
	Site     string
	SitePath string
}

type SiteRouters

type SiteRouters map[string]*mux.Router

type SiteSettings

type SiteSettings struct {
	Site            string
	TemplateBase    string
	TemplateFolders []string
	RootContent     contenttype.ContentTyper
	DefaultContent  contenttype.ContentTyper
	Host            string
	Path            string
}

a basic setting to run a site.

func GetSiteSettings

func GetSiteSettings(identifier string) SiteSettings

type TemplateFunctions

type TemplateFunctions interface {
	GetMap() map[string]interface{}
	SetInfo(ctx RequestInfo)
}

TemplateFunctions represents a set of functions To register a new set of function, first implement this interface and then invoke RegisterFunctions in init()

Directories

Path Synopsis
Package niceurl provides nice url feature for dm framework
Package niceurl provides nice url feature for dm framework

Jump to

Keyboard shortcuts

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