All Projects → zbysir → vpl

zbysir / vpl

Licence: MIT license
Vuejs-syntax like template-engine for Go

Programming Languages

go
31211 projects - #10 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to vpl

Jte
jte is a secure and lightweight template engine for Java.
Stars: ✭ 228 (+1100%)
Mutual labels:  template-engine
abell-renderer
A template engine that lets you write variables, loops, and conditions in HTML using JavaScript Syntax.
Stars: ✭ 42 (+121.05%)
Mutual labels:  template-engine
CodegenCS
C# Toolkit for Code Generation (T4 alternative!)
Stars: ✭ 119 (+526.32%)
Mutual labels:  template-engine
Himl
HTML-based Indented Markup Language for Ruby
Stars: ✭ 236 (+1142.11%)
Mutual labels:  template-engine
Jade
Jade.go - pug template engine for Go (golang)
Stars: ✭ 251 (+1221.05%)
Mutual labels:  template-engine
liquid
A Python engine for the Liquid template language.
Stars: ✭ 40 (+110.53%)
Mutual labels:  template-engine
Fatfree
A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
Stars: ✭ 2,504 (+13078.95%)
Mutual labels:  template-engine
jinja.dart
Jinja2 template engine port for Dart.
Stars: ✭ 38 (+100%)
Mutual labels:  template-engine
sempare-delphi-template-engine
Sempare Template Engine for Delphi allows for flexible dynamic text generation. It can be used for generating email, html, source code, xml, configuration, etc.
Stars: ✭ 79 (+315.79%)
Mutual labels:  template-engine
htmldoom
An intuitive, high performance HTML rendering framework
Stars: ✭ 36 (+89.47%)
Mutual labels:  template-engine
Eta
Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript
Stars: ✭ 233 (+1126.32%)
Mutual labels:  template-engine
Sailfish
Simple, small, and extremely fast template engine for Rust
Stars: ✭ 242 (+1173.68%)
Mutual labels:  template-engine
lua-template
The simplest Lua template engine
Stars: ✭ 33 (+73.68%)
Mutual labels:  template-engine
Pupa
Simple micro templating
Stars: ✭ 231 (+1115.79%)
Mutual labels:  template-engine
tale-pug
Tale Pug is the popular JavaScript Template Engine Pug, formerly Jade, for PHP!
Stars: ✭ 32 (+68.42%)
Mutual labels:  template-engine
Flexml
🚀基于Litho的Android高性能动态业务容器。
Stars: ✭ 225 (+1084.21%)
Mutual labels:  template-engine
picocog
A tiny code generation library (< 8 KB) written in Java, useful for any purpose, but ideal for JSR-269
Stars: ✭ 82 (+331.58%)
Mutual labels:  template-engine
Velocity
🚀Velocity template engine for JavaScript and PHP.
Stars: ✭ 33 (+73.68%)
Mutual labels:  template-engine
html-contextual-autoescaper-java
Prevents XSS by figuring out how to escape untrusted values in templates
Stars: ✭ 15 (-21.05%)
Mutual labels:  template-engine
Kvantum
An intellectual (HTTP/HTTPS) web server with support for server side templating (Crush, Apache Velocity and JTwig)
Stars: ✭ 17 (-10.53%)
Mutual labels:  template-engine

Vpl

Go Report Card

Vpl is a Vuejs-syntax like template-engine for Golang.

  • Componentization
  • Powerful template syntax for the modern html
  • Supports Js(Es5) expressions
  • A little faster (I tried my best to optimize :)

Installation

go get github.com/zbysir/vpl

Getting Started

Write the main.go file as follows

package main

import (
	"context"
	"github.com/zbysir/vpl"
)

func main() {
	v := vpl.New()

	err := v.ComponentTxt("app", `
<!DOCTYPE html>
<html :lang="lang">
<head>
  <meta charset="UTF-8">
  <title>{{title}}</title>
</head>
<body>

<div :id="id" style="font-size: 20px" :style="{color: color}">
  <span v-if="color=='red'">
    color is red
  </span>
  <span v-else>
    color is {{color}}
  </span>
</div>

</body>
</html>
`)
	if err != nil {
		panic(err)
	}

	props := vpl.NewProps()
	props.AppendMap(map[string]interface{}{
		"title": "hello vpl",
		"color": "red",
		"id": "content",
		"lang": "en",
	})

	html, err := v.RenderComponent("app", &vpl.RenderParam{
		Global: nil,
		Ctx:    context.Background(),
		Props:  props,
	})
	if err != nil {
		panic(err)
	}

	print(html)
	// Output: <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>hello vpl</title></head><body><div style="color: red; font-size: 20px;"><span>color is red</span></div></body></html>
}

Then run it.

More examples in /example and /test

Description of the parameters

You only need to understand a few parameters.

vpl.Props

props := vpl.NewProps()
// use Append to add a variable
props.Append("lang", "en")

// use AppendMap to add multiple variables 
props.AppendMap(map[string]interface{}{
    "title": "hello vpl",
    "color": "red",
})

vpl.RenderParam

vpl.RenderParam{
    Global: nil, // Defined Global Variable in this rendering.
    Props:  props, // Parameters of the rendering component.
}

Admonition

All data used by Vpl must be a golang base types, such as int64, int, float32, float64, []interface, map[string]interface{}.

The following example is wrong:

props.Append("list", [3]int{1, 2, 3})

You should use []interface type instead of [3]int:

props.Append("list", []interface{}{1, 2, 3})

For convenience, vpl provides vpl.Copy function to convert a complex structure to a structure containing only basic types.

props.Append("list", vpl.Copy([3]int{1, 2, 3}))

Don't worry too much about performance, it is only executed once in each render.

With Go features

Let's add some go features to vpl.

Parallel

The advantage of go is concurrency, can vpl use it?

YES! Use the <parallel> component.

Let's see this example:

<div>
    <div>
        <!-- Some things took 1s -->
        {{ sleep(1) }} 
    </div>
    <div>
        <!-- Some things took 2s -->
        {{ sleep(2) }} 
    </div>
</div>

It will take 3s if the template is executed in order. You can wrap them with parallel component to parallel them.

<div>
    <parallel>
        <div>
            <!-- Some things took 1s -->
            {{ sleep(1) }} 
        </div>
    </parallel>
    <parallel>
        <div>
            <!-- Some things took 2s -->
            {{ sleep(2) }} 
        </div>
    </parallel>
</div>

It only takes 2s now.

Docs

IntelliJ Plugin

Just use the Vuejs plugin.

Dependencies

  • github.com/robertkrimen/otto: It is used to parse Js expression.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].