gorice

package module
Version: v0.0.0-...-e502229 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: MIT Imports: 2 Imported by: 0

README

gorice

A basic dot file templating system. I leverage go's templating engine for functions such as "include" for loading arbitrary variable files.

Having an include system lets me track requirements and reload only the parts that change. This means if you change a variable file that is used in 2 files, it will change those 2 files.

Installing

go install gitlab.com/sj1k/gorice/cmd/grice

Running

grice -d ~/.path/to/dotfile -d ...

This loads ~/.path/to/dotfile.rice as a template and fills the values into the original dotfile.

It appends .rice to the path before evaluating any symlinks, so dotfile is a symlink but dotfile.rice is not. This is useful for making a self contained dots folder with symlinks linking out to the original dotfile locations.

Include

Ill cover the include function here,

Basically its a cached handler for loading arbitrary vars. (See support section below)

It will also keep track of what files include what vars, letting gorice reload only what you've changed (per-file not per-variable).

Ill cover 2 methods, if you're familiar with go's templates this will look familiar.

Method 1 - With

This was not intentional but it works really well with my system.

{{ with include "path/to/vars.yaml" }}
   {{ .variable }}
{{ end }}

Method 2 - $variables

This is less awesome, but way more useful.

{{ $vars := include "path/to/vars.yaml" }}
{{ $vars.variable }}

Include support

Here is a complete list of the file types include can load. Feel free to request more or help me implement more!

  • .json
  • .yaml

Documentation

Index

Constants

View Source
const (
	RiceExt  = ".rice"
	RiceMode = 0664
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Rice

type Rice struct {
	Template *os.File // The template file to read from.
	File     *os.File // The original file to write to.
}

Rice is a struct that contains 2 os.File pointers, It reads from one and writes to the other. Crazy right?

func NewRice

func NewRice(path string) (Rice, error)

NewRice attempts to open path for writing, and path + RiceExt for reading. In other words this opens 2 files, one with a (by default .rice) extension on the same path.

func (Rice) Close

func (r Rice) Close() error

Close closes both of the underlying files.

func (Rice) Read

func (r Rice) Read(p []byte) (int, error)

Read reads from the underlying Template, usually a .rice file in the same directory.

func (Rice) Write

func (r Rice) Write(p []byte) (int, error)

Write writes to the underlying File, the original file.

type SymPath

type SymPath string

func (SymPath) String

func (s SymPath) String() string

Source Files

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL