corgi

module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2022 License: MIT

README

corgi

GitBook Test Code Coverage Go Report Card License MIT


About

Corgi is an HTML and XML 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, not just replacing placeholders
  • 👪 Support for inheritance
  • ➕ Mixins—functions (with parameters) that render repeated pieces of corgi
  • 🗄 Import mixins from other files
  • 🖇 Split large templates into multiple files
  • ✨ Import any Go package and use its constants, variables, types, and functions—no need for FuncMaps or the like
  • 🤏 Generates minified HTML (and through the use of filters also minified CSS and JS)
  • 🔒 Automatically escapes HTML/XML, and in HTML mode also interpolated CSS and JS

Examples

First impressions matter, so here is an example of a simple template:

import "strings"

//- 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.
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#features.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.

    switch len(friends)
      case 0
      case 1
        p And make sure to tell #{friends[0]} about corgi too!
      case 2
        p And make sure to tell #{friends[0]} and #{friends[1]} about corgi too!
      default
        p.
          And make sure to tell
          #{strings.Join(friends[:len(friends)-1], ", ")},
          and #{friends[len(friends)-1]} about corgi too!
<!-- LearnCorgi("Maxi", true, []string{"Huey", "Dewey", "Louie"}) -->

<!doctype html>
<html lang="en">
<head>
    <title>Learn Corgi</title>
</head>
<body>
<h1>Learn Corgi</h1>
<p id="features" class="font-size--big">Hello, Maxi!</p>
<p>
    Maxi, since you already know pug,
    learning corgi will be even more of <strong>a breeze</strong> for you!
    Head over to <a href="https://mavolin.gitbook.io/corgi">GitBook</a> to
    learn it.
</p>
<p>And make sure to tell Huey, Dewey, and Louie about corgi too!</p>
</body>
</html>

Want to know more?

Have a look at the guide on GitBook. If you already know pug, you can also find a detailed list of differences there.

License

Built with ❤️ by Maximilian von Lindern. Available under the MIT License.

Directories

Path Synopsis
cmd
Package corgi provides parsing for corgi files.
Package corgi provides parsing for corgi files.
file
Package file provides structs that represent the structure of a corgi file.
Package file provides structs that represent the structure of a corgi file.
file/minify
Package minify implements a utility to reduce the number of items in the file.
Package minify implements a utility to reduce the number of items in the file.
lex
Package lex provides the lexer for corgi.
Package lex provides the lexer for corgi.
link
Package link links implements a linker for corgi files.
Package link links implements a linker for corgi files.
link/element
Package element provides checkers to check correct usage of &s and self-closing elements.
Package element provides checkers to check correct usage of &s and self-closing elements.
link/imports
Package imports provides a resolver for imports.
Package imports provides a resolver for imports.
link/mixin
Package mixin provides a Checker, a CallChecker, and CallLinker for mixins.
Package mixin provides a Checker, a CallChecker, and CallLinker for mixins.
link/use
Package use provides a NamespaceChecker that checks for namespace collisions in use directives.
Package use provides a NamespaceChecker that checks for namespace collisions in use directives.
parse
Package parse implements a parser for corgi files.
Package parse implements a parser for corgi files.
resource
Package resource provides abstractions for accessing resources.
Package resource provides abstractions for accessing resources.
internal
meta
Package meta contains metadata about the compiler.
Package meta contains metadata about the compiler.
require
Package require provides a type to express optionality.
Package require provides a type to express optionality.
pkg
stack
Package stack provides a stack datatype built using a resized slice.
Package stack provides a stack datatype built using a resized slice.
voidelem
Package voidelem provides utilities for working with HTML void elements.
Package voidelem provides utilities for working with HTML void elements.
test
internal/compile
Package compile provides an utility function to compile files in preparation tests.
Package compile provides an utility function to compile files in preparation tests.
internal/extra
Package extra provides variables, constants, types, and function to be imported by corgi files.
Package extra provides variables, constants, types, and function to be imported by corgi files.
internal/outcheck
Package outcheck provides a utility to check if the output of a template function matches a file.
Package outcheck provides a utility to check if the output of a template function matches a file.
Package writer provides a writer that allows converting a file.File to Go code.
Package writer provides a writer that allows converting a file.File to Go code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL