Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/open2b/scriggo
The world’s most powerful template engine and Go embeddable interpreter
https://github.com/open2b/scriggo
cross-platform embedded go interpreter language template vm
Last synced: 3 months ago
JSON representation
The world’s most powerful template engine and Go embeddable interpreter
- Host: GitHub
- URL: https://github.com/open2b/scriggo
- Owner: open2b
- License: bsd-3-clause
- Created: 2019-02-13T07:47:27.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-09-13T13:51:34.000Z (5 months ago)
- Last Synced: 2024-09-15T00:26:04.294Z (5 months ago)
- Topics: cross-platform, embedded, go, interpreter, language, template, vm
- Language: Go
- Homepage: https://scriggo.com
- Size: 7.41 MB
- Stars: 423
- Watchers: 6
- Forks: 19
- Open Issues: 88
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
- Authors: AUTHORS
Awesome Lists containing this project
README
The world’s most powerful template engine and [Go](https://go.dev/) embeddable interpreter.
[![Go Reference](https://pkg.go.dev/badge/github.com/open2b/scriggo/.svg)](https://pkg.go.dev/github.com/open2b/scriggo/)
[![Go Report Card](https://goreportcard.com/badge/github.com/open2b/scriggo)](https://goreportcard.com/report/github.com/open2b/scriggo)[Website](https://scriggo.com/) | [Get Started](https://scriggo.com/get-started) | [Documentation](https://scriggo.com/what-is-scriggo) | [Community](https://github.com/open2b/scriggo/discussions) | [Contributing](https://github.com/open2b/scriggo/blob/main/CONTRIBUTING.md)
## Features
* Fast, a very fast embeddable pure Go language interpreter.
* Modern and powerful template engine with Go as scripting language.
* Native support for Markdown in templates.
* Secure by default. No access to packages unless explicitly enabled.
* Easy to embed and to interop with any Go application.## Get Started with Programs
Execute a Go program embedded in your application:
```go
package mainimport "github.com/open2b/scriggo"
func main() {
// src is the source code of the program to run.
src := []byte(`
package mainfunc main() {
println("Hello, World!")
}
`)// Create a file system with the file of the program to run.
fsys := scriggo.Files{"main.go": src}// Build the program.
program, err := scriggo.Build(fsys, nil)
if err != nil {
panic(err)
}
// Run the program.
err = program.Run(nil)
if err != nil {
panic(err)
}}
```## Get Started with Templates
Scriggo, in templates, supports inheritance, macros, partials, imports and contextual autoescaping but most of all it
uses the Go language as the template scripting language.```
{% extends "layout.html" %}
{% import "banners.html" %}
{% macro Body %}
- {{ product.Name }}
{% for product in products %}
{% end %}
{{ render "pagination.html" }}
{{ Banner() }}
{% end %}
```
Scriggo template files can be written in plain text, HTML, Markdown, CSS, JavaScript and JSON.
### Execute a Scriggo template in your application
```go
// Build and run a Scriggo template.
package main
import (
"os"
"github.com/open2b/scriggo"
"github.com/open2b/scriggo/builtin"
"github.com/open2b/scriggo/native"
)
func main() {
// Content of the template file to run.
content := []byte(`
Hello
Hello, {{ capitalize(who) }}!
`)
// Create a file system with the file of the template to run.
fsys := scriggo.Files{"index.html": content}
// Declare some globals.
var who = "world"
opts := &scriggo.BuildOptions{
Globals: native.Declarations{
"who": &who, // global variable
"capitalize": builtin.Capitalize, // global function
},
}
// Build the template.
template, err := scriggo.BuildTemplate(fsys, "index.html", opts)
if err != nil {
panic(err)
}
// Run the template and print it to the standard output.
err = template.Run(os.Stdout, nil, nil)
if err != nil {
panic(err)
}
}
```
For a complete get started guide see the [Scriggo site](https://scriggo.com/).
## Contributing
Want to help contribute to Scriggo? See [CONTRIBUTING.md](CONTRIBUTING.md).