Skip to content

A VueJS inspired Templating system written in Pure Go

License

Notifications You must be signed in to change notification settings

titpetric/vuego

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

212 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vuego - A Go based VueJS syntax template engine

Go Reference Coverage

Vuego is a Vue.js-inspired template engine for Go. Render HTML templates with familiar Vue syntax - no JavaScript runtime required.

You can try Vuego:

The Vuego CLI is also available as a docker image and runs the tour.

About

Vuego is a server-side template rendering engine. It provides a template runtime that allows you to modify templates as the application is running. It allows for composition, supports layouts and aims to be an exclusive runtime where Go is used for front and back-end development.

The choices Vuego makes:

  • A largely VueJS compatible syntax with v-if, v-for and interpolation
  • Composition with the usage of the html <template> tag (unique syntax)
  • DOM driven templating, type safety based on generics and reflection
  • YAML/JSON as the default way to provide template view rendering

Especially with using a machine readable data format, vuego aims to support the development lifecycle with the vuego-cli tool. The tool allows you to run a development playground. The process is simple:

  • start vuego-cli serve ./templates
  • edit .json and .vuego files
  • refresh to view changes

Project it in active development. Some changes in API surface are still expected based on feedback and observations. Releases are tagged.

Quick start

You can use vuego by importing it in your project:

import "github.com/titpetric/vuego"

In your service you create a new vuego renderer.

// load your templates from a folder.
// the argument can be swapped for an embed.FS value.
renderer := vuego.NewFS(os.DirFS("templates"))

if err := renderer.File(filename).Fill(data).Render(r.Context(), w); err != nil {
	return err
}

You can provide your own type safe wrappers:

func (v *Views) IndexView(data IndexData) vuego.Template {
	return vuego.View[IndexData](v.renderer, "index.vuego", data)
}

And you don't need to chain the functions:

renderer := vuego.NewFS(embedFS)

tpl := renderer.New()
tpl.Fill(data)
tpl.Assign("meta", meta)
err := tpl.Render(ctx, out)

If you want to render from a string and not a filesystem:

renderer := vuego.New()
err = renderer.New().Fill(data).RenderString(r.Context(), w, `<li v-for="item in items">{{ item.title }}</li>`)

There's more detail around authoring vuego templates, check documentation:

Vuego CLI

With titpetric/vuego-cli you can do the following:

  • vuego-cli serve <folder> - load a development server for templates,
  • vuego-cli tour <folder> - load a learning tour of vuego,
  • vuego-cli docs <folder> - load a documentation server.

In addition to those learning tools, separate commands are provided to fmt, lint and render files.

Documentation

The Template Syntax reference covers four main areas:

  • Values - Variable interpolation, expressions, and filters
  • Directives - Complete reference of all v- directives
  • Components - <template include> and <template> tags
  • Advanced - Template functions, custom filters, and full documents

Additional resources:

Packages

No packages published

Contributors 2

  •  
  •  

Languages