giter8 alternative in Go

go-giter8

Go

go-giter8 implements a simple library capable of handling giter8 templates.

Using as library

  1. Add to go.mod
module github.com/yourusername/yourproject

go 1.16

require github.com/Gympass/go-giter8 v0.2.0
  1. Use props to parse default.properties:
package foo

import (
	"io"
	"os"

	"github.com/Gympass/go-giter8/props"
)

func parseProperties() props.Pairs {
	f, _ := os.Open("/path/to/your/default.properties")
	data, _ := io.ReadAll(f)
	properties, err := props.ParseProperties(string(data))
	if err != nil {
		panic(err)
    }
    return properties
}
  1. Use parsed properties in a template
package foo

import (
	"io"
	"os"

	"github.com/Gympass/go-giter8/lexer"
	"github.com/Gympass/go-giter8/props"
	"github.com/Gympass/go-giter8/render"
)

func parseProperties() props.Pairs { /* ... */ }

func executeTemplate(path string) (string, error) {
	f, _ := os.Open("/path/to/template/file")
	data, _ := io.ReadAll(f)
	parsed, err := lexer.Tokenize(string(data))
	if err != nil {
		return "", err
	}
	e := render.NewExecutor(parseProperties())
	return e.Exec(parsed)
}

Using as command line

Alternatively, you can use the gg8 CLI to download and execute a template:

$ gg8 Gympass/test.g8 test
Clonning https://github.com/Gympass/test.g8.git...
Executing template:

name [Test project]: <return>
otherValue [Pizza]: <return>
Processing templates... OK

$   

One can also provide all options through command-line parameters:

$ gg8 Gympass/test.g8 test -- name="A name" otherValue="othervalue"
Clonning https://github.com/Gympass/test.g8.git...
Executing template:
name: A name 
otherValue: othervalue

Processing templates... OK

License

MIT License

Copyright (c) 2021 Victor Gama

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Comments
  • [PRT-94] Allow properties used in conditionals to be absent

    [PRT-94] Allow properties used in conditionals to be absent

    This relaxes property checking to allow absent properties to be checked for their presence. This also fixes an inconsistency that prevented properties containing dashes (-) from being used in conditional expressions.

  • [BUG] Conditional nodes leaking to parent scope [PRT-84]

    [BUG] Conditional nodes leaking to parent scope [PRT-84]

    Considering the following input:

    $if(parent.truthy)$
    Parent OK
    $if(child.truthy)$
    Child OK
    $endif$
    $endif$
    

    The parsed AST becomes:

    Conditional
       Expression: parent.truthy
       Then:
        - Literal(Parent OK)
       Else: nil
       ElseIf: nil
    Conditional
       Expression: child.truthy
       Then:
        - Literal(Child OK)
       Else: nil
       ElseIf: nil
    

    When the following is expected, instead:

    Conditional
       Expression: parent.truthy
       Then:
        - Literal(Parent OK)
        - Conditional
          Expression: child.truthy
          Then:
           - Literal(Child OK)
          Else: nil
          ElseIf: nil
       Else: nil
       ElseIf: nil
    
  • [PRT-80] feat(render): Add support to verbatim prop

    [PRT-80] feat(render): Add support to verbatim prop

    This adds support to the verbatim property, allowing files and patterns to be ignored from the parsing and render process, making them be copied as-is.

  • feat(fs): Implement conditional support to FS items

    feat(fs): Implement conditional support to FS items

    This implements support to conditional file items. For instance, considering the following directory structure:

    ├── directory
    │   └── file.txt
    └── $if(foo.truthy)$bar$end$
        └── otherfile.txt
    

    And props as:

    foo = n
    

    Rendering this directory template will yield the following structure:

    └── directory
        └── file.txt
    

    And having foo defined as any truthy value (such as yes, y, or true) yields the following structure:

    ├── directory
    │   └── file.txt
    └── bar
        └── otherfile.txt
    
  • feat(conditionals): Implement conditional support

    feat(conditionals): Implement conditional support

    This implements support for conditionals. Conditionals can now be used with a single truthy helper, just like the following example:

    Given a property pair:

    p := pairs.FromMap(map[string]string{"prop_name": "true"})
    

    and a template:

    $if(prop_name.truthy)$
    foo
    $else$
    bar
    $endif$
    

    the following would be rendered:

    foo
    

    truthy checks for the following values in a case-insensitive manner: yes, y, true. All other values are considered as false.

    Known problems

    1. Empty lines are not stripped within a conditional block. For instance, a block with the following characters: $if(foo.truthy)$\nfoo\n$else$\nbar\n$endif$ would be rendered as \nfoo\n in case foo equals true. ~~2. If-elseif-else orders are not respected. One is able to write an if-else-elseif structure and it will be executed as if-elseif-else.~~ Addressed by 4af06ab8d99ee30ea625259f01d8d50c65cfc434
An alternative syntax to generate YAML (or JSON) from commandline

yo An alternative syntax to generate YAML (or JSON) from commandline. The ultimate commanline YAML (or JSON) generator! ... I'm kidding of course! but

Jul 30, 2022
🐘 Cross-platform, neofetch alternative for fetching system info.
 🐘 Cross-platform, neofetch alternative for fetching system info.

elefetch ?? Cross-platform, neofetch alternative for fetching system info. Installation go get: go get -u github.com/burntcarrot/elefetch Binaries Bin

Jan 23, 2022
💾 A visual du(1) alternative for human beings

dux A disk usage analyzer. Like du(1), but displays the results as an interactive treemap. testdata 111B (8 files) (4) ┌testdata/ 111B────────────

Sep 6, 2022
archy is an static binary to determine current kernel and machine architecture, with backwards compatible flags to uname, and offers alternative output format of Go runtime (i.e. GOOS, GOARCH).

archy archy is an simple binary to determine current kernel and machine architecture, which wraps uname and alternatively can read from Go runtime std

Mar 18, 2022
:key: Secure alternative to JWT. Authenticated Encrypted API Tokens for Go.

branca branca is a secure alternative to JWT, This implementation is written in pure Go (no cgo dependencies) and implements the branca token specific

Dec 29, 2022
Concurrent task runner, developer's routine tasks automation toolkit. Simple modern alternative to GNU Make 🧰
Concurrent task runner, developer's routine tasks automation toolkit. Simple modern alternative to GNU Make 🧰

taskctl - concurrent task runner, developer's routine tasks automation toolkit Simple modern alternative to GNU Make. taskctl is concurrent task runne

Dec 14, 2022
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.

koanf (pronounced conf; a play on the Japanese Koan) is a library for reading configuration from different sources in different formats in Go applicat

Jan 8, 2023
A fast and powerful alternative to grep

sift A fast and powerful open source alternative to grep. Features sift has a slightly different focus than most other grep alternatives. Code search,

Jan 3, 2023
Alternative archiving tool with fast performance for huge numbers of small files

fast-archiver fast-archiver is a command-line tool for archiving directories, and restoring those archives written in [Go](http://golang.org). fast-ar

Nov 22, 2022
Alternative sync library for Go
Alternative sync library for Go

Alternative sync library for Go. Overview Future - A placeholder object for a value that may not yet exist. Promise - While futures are defined as a t

Dec 23, 2022
Glue - Robust Go and Javascript Socket Library (Alternative to Socket.io)

Glue - Robust Go and Javascript Socket Library Glue is a real-time bidirectional socket library. It is a clean, robust and efficient alternative to so

Nov 25, 2022
Glue - Robust Go and Javascript Socket Library (Alternative to Socket.io)

Glue - Robust Go and Javascript Socket Library Glue is a real-time bidirectional socket library. It is a clean, robust and efficient alternative to so

Nov 25, 2022
An extremely fast UUID alternative written in golang

Overview WUID is a globally unique number generator, while it is NOT a UUID implementation. WUID is 10-135 times faster than UUID and 4600 times faste

Dec 9, 2022
An extremely fast UUID alternative written in golang

Overview WUID is a globally unique number generator, while it is NOT a UUID implementation. WUID is 10-135 times faster than UUID and 4600 times faste

May 10, 2021
Germanium is an alternative to Carbon and Silicon implemented in Go.
Germanium is an alternative to Carbon and Silicon implemented in Go.

Germanium is an alternative to Carbon and Silicon implemented in Go. Germanium can work without browser and internet like Silicon.

Dec 5, 2022
Automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio.
Automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio.

Mesh RPC MeshRPC provides automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio. In a nutshell

Aug 22, 2022
Lightweight selfhosted Firefox Send alternative without public upload
Lightweight selfhosted Firefox Send alternative without public upload

Gokapi Available for: Bare Metal Docker About Gokapi is a lightweight server to share files, which expire after a set amount of downloads or days. It

Jan 5, 2023
Disk Usage/Free Utility - a better 'df' alternative
Disk Usage/Free Utility - a better 'df' alternative

duf Disk Usage/Free Utility (Linux, BSD, macOS & Windows) Features User-friendly, colorful output Adjusts to your terminal's width Sort the results ac

Jan 9, 2023
One of the fastest alternative JSON parser for Go that does not require schema

Alternative JSON parser for Go (10x times faster standard library) It does not require you to know the structure of the payload (eg. create structs),

Jan 2, 2023
A task runner / simpler Make alternative written in Go
A task runner / simpler Make alternative written in Go

Task Task is a task runner / build tool that aims to be simpler and easier to use than, for example, GNU Make. See taskfile.dev for the documentation.

Jan 8, 2023