templates

package
v0.0.0-...-6c293db Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: BSD-2-Clause Imports: 5 Imported by: 0

README

Templates

  • Code must go between <% and %>
  • Expressions can appear between <%= and %>
  • Unescaped output can appear whith <%== and %>
  • Functions can be included with a header tag "<%@" at the beginning of the template

It also generates a sourcemap for errors.

For example:

<body>
    <%
        a := "John"
        b := a + " Doe"
    %>

    <h1>Hello <%= a %></h1>

    <h1>Hello <%== b %></h1>

</body>

Will generate:

w.write(html.encode(`<body>
    `))

        a := "John"
        b := a + " Doe"

w.write(html.encode(`

    <h1>Hello `))
w.write(a)
w.write(html.encode(`</h1>

    <h1>Hello `))
w.write(html.encode(b))
w.write(html.encode(`</h1>

</body>`))

Functions at the beginning of the template:

<%@
    func myFunc() {

    }
%>

Documentation

Overview

Package templates generates source code for templates.

  • Code must go into <% and %>
  • Expressions can appear into <%= and %>
  • Unescaped output can appear whith <%== and %>
  • Functions can be included with a header tag "<%@" at the beginning of the template

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(source string) ([]byte, []int, error)

Compile returns the generated renderer code and a sourcemap slice in which each index contains the original line.

func CompileHtml

func CompileHtml(source string) ([]byte, []int, error)

CompileHtml returns the generated renderer code and a sourcemap slice in which each index contains the original line. htmlEncode makes <%= %> blocks html encoded and <%== %> not encoded.

Types

type Error

type Error struct {
	Pos     position
	Message string
	Token   string
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Position

func (e *Error) Position() position

Jump to

Keyboard shortcuts

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