Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/mavolin/corgi
- Owner: mavolin
- License: mit
- Created: 2022-05-21T21:32:50.000Z (over 2 years ago)
- Default Branch: v1
- Last Pushed: 2024-07-06T18:50:39.000Z (6 months ago)
- Last Synced: 2024-09-30T07:40:12.203Z (3 months ago)
- Topics: code-generator, html, html-template, pug, template-engine, template-language
- Language: Go
- Homepage:
- Size: 3.48 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
[![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).