Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mavolin/corgi

πŸ“ A code-generated template engine for Go.
https://github.com/mavolin/corgi

code-generator html html-template pug template-engine template-language

Last synced: 2 months ago
JSON representation

πŸ“ A code-generated template engine for Go.

Awesome Lists containing this project

README

        


corgi

[![GitBook](https://img.shields.io/badge/docs-GitBook-blue)](https://mavolin.gitbook.io/corgi)
[![Test](https://github.com/mavolin/corgi/actions/workflows/test.yml/badge.svg)](https://github.com/mavolin/corgi/actions)
[![Code Coverage](https://codecov.io/gh/mavolin/corgi/branch/develop/graph/badge.svg?token=ewFEQGgMES)](https://codecov.io/gh/mavolin/corgi)
[![Go Report Card](https://goreportcard.com/badge/github.com/mavolin/corgi)](https://goreportcard.com/report/github.com/mavolin/corgi)
[![License MIT](https://img.shields.io/github/license/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).