https://github.com/aerogo/pixy
:deciduous_tree: Template compiler similar to Jade/Pug.
https://github.com/aerogo/pixy
go template-engine template-language
Last synced: 3 months ago
JSON representation
:deciduous_tree: Template compiler similar to Jade/Pug.
- Host: GitHub
- URL: https://github.com/aerogo/pixy
- Owner: aerogo
- License: other
- Created: 2016-10-25T01:26:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-09-04T02:27:27.000Z (over 6 years ago)
- Last Synced: 2024-10-29T21:05:51.729Z (over 1 year ago)
- Topics: go, template-engine, template-language
- Language: Go
- Homepage:
- Size: 107 KB
- Stars: 22
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# pixy
[![Godoc][godoc-image]][godoc-url]
[![Report][report-image]][report-url]
[![Tests][tests-image]][tests-url]
[![Coverage][coverage-image]][coverage-url]
[![Sponsor][sponsor-image]][sponsor-url]
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](https://github.com/aerogo/pack).
## Syntax
A pixy template is a collection of components.
```jade
component Hello(person string)
h1= "Hello " + person
```
You can define multiple components in a single file:
```jade
component Hello
h1 Hello
component World
h1 World
```
And combine multiple components in one:
```jade
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 `#`:
```jade
component Hello
h1#greeting Hello World
```
Add classes with the suffix `.`:
```jade
component Hello
h1.greeting Hello World
```
Assign element properties:
```jade
component Hello
h1(title="Greeting") Hello World
```
Use Go code for the text content:
```jade
component Hello
h1= strconv.Itoa(123)
```
Use Go code in values:
```jade
component Hello
h1(title="Greeting " + strconv.Itoa(123)) Hello World
```
Embed HTML with the suffix `!=`:
```jade
component Hello
div!= "
Hello
"
```
Call a parameter-less component:
```jade
component HelloCopy
Hello
component Hello
h1 Hello
```
Call a component that requires parameters:
```jade
component HelloWorld
Hello("World", 42)
component Hello(person string, magicNumber int)
h1= "Hello " + person
p= magicNumber
```
Iterate over a slice:
```jade
component ToDo(items []string)
ul
each item in items
li= item
```
Iterate over a slice in reversed order:
```jade
component ToDo(items []string)
ul
each item in items reversed
li= item
```
For loops (`each` is just syntactical sugar):
```jade
component ToDo(items []string)
ul
for _, item := range items
li= item
```
If conditions:
```jade
component Condition(ok bool)
if ok
h1 Yes!
else
h1 No!
```
## API
```go
components, err := pixy.Compile(src)
```
## Style
Please take a look at the [style guidelines](https://github.com/akyoto/quality/blob/master/STYLE.md) if you'd like to make a pull request.
## Sponsors
| [](https://github.com/cedricfung) | [](https://github.com/soulcramer) | [](https://twitter.com/eduardurbach) |
| --- | --- | --- |
| [Cedric Fung](https://github.com/cedricfung) | [Scott Rayapoullé](https://github.com/soulcramer) | [Eduard Urbach](https://eduardurbach.com) |
Want to see [your own name here?](https://github.com/users/akyoto/sponsorship)
[godoc-image]: https://godoc.org/github.com/aerogo/pixy?status.svg
[godoc-url]: https://godoc.org/github.com/aerogo/pixy
[report-image]: https://goreportcard.com/badge/github.com/aerogo/pixy
[report-url]: https://goreportcard.com/report/github.com/aerogo/pixy
[tests-image]: https://cloud.drone.io/api/badges/aerogo/pixy/status.svg
[tests-url]: https://cloud.drone.io/aerogo/pixy
[coverage-image]: https://codecov.io/gh/aerogo/pixy/graph/badge.svg
[coverage-url]: https://codecov.io/gh/aerogo/pixy
[sponsor-image]: https://img.shields.io/badge/github-donate-green.svg
[sponsor-url]: https://github.com/users/akyoto/sponsorship