sitekit

package
v0.1.1-beta.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 20 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(ctx context.Context, content contenttype.ContentTyper, viewmode string, siteIdentifier string) string

Get content view template, with site setting's template folder todo: support page content(render content) in matchData, eg. "render_field/display_type": "news", "render_contentype": "frontpage" - used like 'section' isolation based on visit page.

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 Load

func Load()

func LoadSite

func LoadSite(ctx context.Context, siteConfig map[string]interface{}) error

Initialize sites setting to memory

func MatchTemplate

func MatchTemplate(ctx context.Context, viewSection string, matchData map[string]interface{}, fileName ...string) (string, []string)

MatchTemplate returns overrided template based on override config(eg. template_override.yaml)

func Output

func Output(w io.Writer, variables map[string]interface{}, viewType string, requestInfo RequestInfo) error

Output proceeds template and output the results If variables includes "content" it will proceed as content, otherwise it process path(eg. email, sms, etc) see sitekit/templates/main.html common variables: debug, error match_data for non-content template matching

func OutputContent

func OutputContent(w io.Writer, content contenttype.ContentTyper, siteIdentifier string, sitePath string, ctx context.Context, templateVars map[string]interface{}) error

Output content using conent template

func OutputContentByID

func OutputContentByID(w io.Writer, id int, siteIdentifier string, sitePath string, ctx context.Context, templateVars map[string]interface{}) error

func OutputString

func OutputString(variables map[string]interface{}, viewType string, requestInfo RequestInfo) (string, error)

OutputString output template result as string See Output

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 TemplateExist

func TemplateExist(path string) bool

check if template exists under web/templates(default) folder

func TemplateFolder

func TemplateFolder() string

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

func WashTemplatePath

func WashTemplatePath(path string, folder string) string

add site template folder to template path if path starts from ~/, use path after ~/

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
	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