page

package
v0.0.0-...-dc37515 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BasePage is the main page template.
	BasePage = template.Must(template.New("BasePage").Parse(`<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<meta charset="utf8" />
	<link rel="stylesheet" href="/assets/style.css" />
	<link rel="author" href="/humans.txt" />
	<title>{{.Title}}</title>
    <script type="text/javascript" nonce="{{.Nonce}}">
        window.CSRF_TOKEN = "{{.CSRFToken}}";
    </script>
</head>
<body>
	<header>
		<nav>
			<ul>
				<li class="home"><a href="/">Home</a></li>
				<li class="posts"><a href="/posts">Posts</a></li>
				{{if .LoggedIn}}
				<li class="logout"><a href="/logout?token={{.CSRFToken}}">Logout</a></li>
				{{else}}
				<li class="login"><a href="/login">Log In</a></li>
				<li class="register"><a href="/register">Register</a></li>
				{{end}}
			</ul>
		</nav>
	</header>
	<div id="body">{{block "body" .Body}}{{end}}</div>
</body>
</html>
{{define "secondary-menu"}}	
<nav>
	<ul>
		{{block "secondary-menu-items" .}}{{end}}
	</ul>
</nav>
{{end}}
`))
)

Functions

func EntityLoaderMiddleware

func EntityLoaderMiddleware(loader EntityLoader) negroni.Handler

EntityLoaderMiddleware creates a middleware that loads an entity from the URL.

func GetEntity

func GetEntity(r *http.Request) (interface{}, error)

GetEntity returns the current entity that is referenced in the URL.

func SubPage

func SubPage(text string, extra ...string) *template.Template

SubPage creates a template that uses the base page.

Types

type AccessChecker

type AccessChecker interface {
	Has(name string) bool
}

AccessChecker checks if the current account has a permission.

type Data

type Data struct {
	Title     string
	Nonce     string
	CSRFToken string
	LoggedIn  bool
	Access    AccessChecker
	Body      interface{}
}

Data is the page data for BasePage.

func (Data) Has

func (d Data) Has(name string) bool

type EntityLoader

type EntityLoader interface {
	Load(r *http.Request) (interface{}, error)
}

EntityLoader loads an entity.

type EntityLoaderFunc

type EntityLoaderFunc func(r *http.Request) (interface{}, error)

EntityLoaderFunc is a single function implementation of EntityLoader.

func (EntityLoaderFunc) Load

func (f EntityLoaderFunc) Load(r *http.Request) (interface{}, error)

Jump to

Keyboard shortcuts

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