templatizer

module
Version: v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2022 License: GPL-3.0

README

Keep a Changelog GitHub Release Go Reference go.mod LICENSE Build Status Go Report Card Codecov CodeQL

{{.Templatizer}}

The intention of Templatizer is to provide a handy and powerful mechanism to create custom projects from templates.

Gir repositories engines such as Github or Gitlab claim that they support repositories as templates. Actually, they only permit us to tag repositories as templates; but we will need to replace the "dynamic values" after copying/clonnig the templates. Sincerely, this is far to be a teamplate mechanism from my point of view.

Getting started

Templatizer takes advantage of existing template engines. So far, Templatizer supports Go Template but It's on the roadmap to provide other flavours such as Jinja.

Templatizer is meant to be executed as an executable file from your local machine. Thus, the communication with the repositories will be established on your own machine and the credentials won't be sent over the Internet.

Template

The template is the main piece used by Tempaltizer. A template is a Git repository hosted on any web repositories. The templates will contain values tp be dynamically replaced (variables). The varibales can be used in the content of the files but also in the name of folders and files.

To define the variables in the templates we will use the specified format by Go Template. Variables are defined as {{.variable}}. See the following example taken from a Go file.

package main

import (
	"embed"
	"io/fs"
	"net/http"
	log "{{.logger}}"
)

//go:embed {{.sitePath}}
var content embed.FS

func clientHandler() http.Handler {
	fsys := fs.FS(content)
	contentStatic, _ := fs.Sub(fsys, "{{.sitePath}}")
	return http.FileServer(http.FS(contentStatic))
}

func main() {
	mux := http.NewServeMux()
	mux.Handle("/", clientHandler())
	if err := http.ListenAndServe(":{{.serverPort}}", mux); err != nil {
		log.Fatal(err)
	}
}

The below screenshot shows an example of how we can use variabls in the name of the folders and the files.

Templatizer

Templatizer requires that the Tempalte reqpository host a file with the specification of the variables. This is not rocket science, we just need to enum the variables as shown in the below example::

version: v1
mode: goTemplate
variables:
  - name: logger
    default: github.com/sirupsen/logrus
  - name: serverPort
    default: 3000
  - name: sitePath
    description: Path to the static embedded foler
  - name: organization
    description: Name of the GH organization

The attributes version and mode could be omited since they are ignored in this version of Templatizer. Regarding the variables, only the attribute name. Anyway, the usage of the attributes description and default will help us to create handier and more useful templates.

By convection the name of this files is .templatizer.yml and It's in the root of your repository.

Installation

Download the artifact

Brew tap

From source code

Contributing

Contributions are welcome, but before doing it I hardly recommend you to have a look at the CONTRIBUTING.md and the CODE_OF_CONDUCT.md.

Pre-requisites

if you work with MacOS you can take advantage of homebrew o setup your environment. You just need to run make setup.

In other case you would need to setup manually the following tools:

Directories

Path Synopsis
cmd
pkg
api
internal

Jump to

Keyboard shortcuts

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