Skip to content
/ pixy Public

🌳 Template compiler similar to Jade/Pug.

License

Notifications You must be signed in to change notification settings

aerogo/pixy

Repository files navigation

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?