https://github.com/mavolin/corgi
๐ A code-generating template engine for Go.
https://github.com/mavolin/corgi
code-generator html html-template pug template-engine template-language
Last synced: 27 days ago
JSON representation
๐ A code-generating template engine for Go.
- Host: GitHub
- URL: https://github.com/mavolin/corgi
- Owner: mavolin
- License: mit
- Created: 2022-05-21T21:32:50.000Z (almost 3 years ago)
- Default Branch: v1
- Last Pushed: 2025-04-09T21:30:45.000Z (27 days ago)
- Last Synced: 2025-04-09T22:28:07.919Z (27 days ago)
- Topics: code-generator, html, html-template, pug, template-engine, template-language
- Language: Go
- Homepage:
- Size: 3.74 MB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
corgi
[](https://mavolin.gitbook.io/corgi)
[](https://github.com/mavolin/corgi/actions)
[](https://codecov.io/gh/mavolin/corgi)
[](https://goreportcard.com/report/github.com/mavolin/corgi)
[](./LICENSE)---
## About
Corgi is an HTML template language for Go, inspired by pug (hence the name).
Just like pug, corgi also uses code generation to generate its templates.## Main Features
* ๐ Highly readable syntax that models HTML, not just replacing placeholders
* โ Mixinsโfunctions that render repeated pieces of corgi
* ๐ Conditional classes that are actually readable
* ๐ Import other files to use their mixins
* ๐ Split large templates into multiple files
* ๐ช Support for inheritance
* โจ Import any Go package and use any of its types, functions and constantsโno need for `FuncMap`s
* ๐ค Generates compile-time minified HTML, CSS, and JS
* ๐ Context-aware auto-escaping and filtering of HTML, CSS, JS, and special HTML attributes
* ๐ก๏ธ Script CSP nonce injection
* โ ๏ธ Descriptive, Rust-style errors## Example
First impressions matter, so here is an example of a simple template:
```jade
import "strings"// corgi has a stdlib with a handful of useful mixins
use "fmt"// These are the name and params of the function that corgi will generate.
// Besides the params you specify here, corgi will also add an io.Writer that
// it'll write the output to, and an error return, that returns any errors
// it encounters when writing to the io.Writer.
//
// The real signature will look like this:
// func LearnCorgi(w io.Writer, name string, knowsPug bool, friends []string) error
func LearnCorgi(name string, knowsPug bool, friends []string)mixin greet(name string) Hello, #{name}!
doctype html
html(lang="en")
head
title Learn Corgi
body
h1 Learn Corgi
p#greeting.greeting
// the & allows you to add additional attributes to an element
if strings.HasPrefix(name, "M"): &.font-size--big
+greet(name=name)p
if knowsPug
> #{name}, since you already know pug,
learning corgi will be even more of #strong[a breeze] for you!#[ ]> Head over to #a(href="https://mavolin.gitbook.io/corgi")[GitBook]
to learn it.p And make sure to tell #+fmt.List(val=friends) about corgi too!
```Pretty-Printed output:
```html
Learn Corgi
Learn Corgi
Hello, Maxi!
Maxi, since you already know pug,
learning corgi will be even more of a breeze for you! Head over to
GitBook to learn it.And make sure to tell Huey, Dewey, and Louie about corgi too!
```
> If you're interested in the generated code, have a look at the `examples` directory.
## Want to know more?
Have a look at the guide on [GitBook](https://mavolin.gitbook.io/corgi).
## License
Built with โค by [Maximilian von Lindern](https://github.com/mavolin).
Available under the [MIT License](./LICENSE).