pixy

package module
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: MIT Imports: 13 Imported by: 1

README

pixy

Godoc Report Tests Coverage Sponsor

Pixy compiles .pixy templates to native Go code to profit from type system checks and high performance DOM rendering. The generated code usually renders templates 300-400% faster than Jade/Pug due to byte buffer pooling and streaming.

CLI

If you're looking for the official compiler, please install pack.

Syntax

A pixy template is a collection of components.

component Hello(person string)
	h1= "Hello " + person

You can define multiple components in a single file:

component Hello
	h1 Hello

component World
	h1 World

And combine multiple components in one:

component Layout
	html
		head
			Title("Website title.")
		body
			Content("This is the content.")
			Sidebar("This is the sidebar.")

component Title(title string)
	title= title

component Content(text string)
	main= text

component Sidebar(text string)
	aside= text

Add IDs with the suffix #:

component Hello
	h1#greeting Hello World

Add classes with the suffix .:

component Hello
	h1.greeting Hello World

Assign element properties:

component Hello
	h1(title="Greeting") Hello World

Use Go code for the text content:

component Hello
	h1= strconv.Itoa(123)

Use Go code in values:

component Hello
	h1(title="Greeting " + strconv.Itoa(123)) Hello World

Embed HTML with the suffix !=:

component Hello
	div!= "<h1>Hello</h1>"

Call a parameter-less component:

component HelloCopy
	Hello

component Hello
	h1 Hello

Call a component that requires parameters:

component HelloWorld
	Hello("World", 42)

component Hello(person string, magicNumber int)
	h1= "Hello " + person
	p= magicNumber

Iterate over a slice:

component ToDo(items []string)
	ul
		each item in items
			li= item

Iterate over a slice in reversed order:

component ToDo(items []string)
	ul
		each item in items reversed
			li= item

For loops (each is just syntactical sugar):

component ToDo(items []string)
	ul
		for _, item := range items
			li= item

If conditions:

component Condition(ok bool)
	if ok
		h1 Yes!
	else
		h1 No!

API

components, err := pixy.Compile(src)

Style

Please take a look at the style guidelines if you'd like to make a pull request.

Sponsors

Cedric Fung Scott Rayapoullé Eduard Urbach
Cedric Fung Scott Rayapoullé Eduard Urbach

Want to see your own name here?

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCompiler = NewCompiler("components")

DefaultCompiler is the default compiler used by the interface.

Functions

This section is empty.

Types

type Compiler

type Compiler struct {
	// PackageName contains the package name used in the generated .go files.
	PackageName string
}

Compiler is a Pixy file compiler.

func NewCompiler

func NewCompiler(packageName string) *Compiler

NewCompiler constructs a new Pixy compiler.

func (*Compiler) Compile

func (compiler *Compiler) Compile(reader io.Reader) ([]*Component, error)

Compile compiles a Pixy template as a string and returns a slice of components.

func (*Compiler) CompileBytes

func (compiler *Compiler) CompileBytes(src []byte) ([]*Component, error)

CompileBytes compiles a Pixy template as a byte slice and returns a slice of components.

func (*Compiler) CompileFile

func (compiler *Compiler) CompileFile(fileIn string) ([]*Component, error)

CompileFile compiles a Pixy template read from a file and returns a slice of components.

func (*Compiler) CompileString added in v1.2.0

func (compiler *Compiler) CompileString(src string) ([]*Component, error)

CompileString compiles a Pixy template as a string and returns a slice of components.

func (*Compiler) GetFileHeader

func (compiler *Compiler) GetFileHeader() string

GetFileHeader returns the file header.

func (*Compiler) GetUtilities

func (compiler *Compiler) GetUtilities() string

GetUtilities returns the file header and utility functions that are available for components.

func (*Compiler) SaveUtilities

func (compiler *Compiler) SaveUtilities(filePath string) error

SaveUtilities adds the file with required function definitions to the directory.

type Component

type Component struct {
	Name string
	Code string
}

Component represents a single, reusable template.

func Compile

func Compile(reader io.Reader) ([]*Component, error)

Compile compiles a Pixy template as a reader and returns a slice of components.

func CompileBytes

func CompileBytes(src []byte) ([]*Component, error)

CompileBytes compiles a Pixy template as a byte slice and returns a slice of components.

func CompileFile

func CompileFile(fileIn string) ([]*Component, error)

CompileFile compiles a Pixy template read from a file and returns a slice of components.

func CompileString added in v1.2.0

func CompileString(src string) ([]*Component, error)

CompileString compiles a Pixy template as a byte slice and returns a slice of components.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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