compiler

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

Close handles stoping the compiler and clearing the cache

func Compile

func Compile(path string, opts map[string]interface{}, compressOutput uint8) ([]byte, error)

Compile handles the final output and returns valid html/xhtml that can be passed to the user

this method will automatically call preCompile if needed, and can read the cache file while its being written for an extra performance boost

@compressOutput: 0 = none, 1 = gzip, 2 = brotli

func GetOpt

func GetOpt(arg []byte, opts *map[string]interface{}, pre bool, addVars *[]KeyVal) (interface{}, bool)

GetOpt is used to handle grabing an option from the user options that were passed

this method accepts the arg as a simple text like []byte("myOption")

this method can also handle complex options like {{this|'that'}} (with optional or statements) and even {{class="myClass"}} vars

func HasPreCompile

func HasPreCompile(path string, optExt string) bool

HasPreCompile returns true if a file has been pre compiled in the cache and is not expired

func NewFunc

func NewFunc(name string, fn func(args *map[string][]byte, cont *[]byte, opts *map[string]interface{}, pre bool, addVars *[]KeyVal) (interface{}, error)) error

NewFunc can be used to create custom functions for the compiler

these user defined functions will only run after the default functions have been resolved

func PreCompile

func PreCompile(path string, opts map[string]interface{}) error

preCompile generates a new pre-compiled file for the cache

this compiles markdown and handles other complex methods

this function is useful if you need to update any constand vars, defined with a "$" as the first char in their key name

func SetConfig

func SetConfig(config Config) error

SetConfig can be used to set change the config options provided in the Config struct

this method will also clear the cache

Types

type Config

type Config struct {
	// Root is the root directory for your html/markdown files to be compiled
	//
	// default: views
	Root string

	// Components is an optional directory that can be used to organize components
	//
	// if a component is not found within the components directory first, it will then be checked for in the root directory you chose for the compiler
	//
	// default: components
	//
	// note: this file is relative to your chosen Root for the compiler
	Components string

	// Layout is the main template that all other files will be placed inside of
	//
	// default: layout
	//
	// pass "!" to disable
	//
	// pass "*" to set to default
	//
	// note: this file is relative to your chosen Root for the compiler
	Layout string

	// Ext is the file extention for your files to be compiled
	//
	// default: .md
	Ext string

	// Public is an optional path you can use if you have a public directory with client side scripts and stylesheets
	//
	// the compiller will use this directory to auto upgrade to .min files
	//
	// note: the compiler will Not make this directory public, it will simply read from it
	Public string

	// Cache sets the amount of time before the cache will expire
	Cache string

	// ConstOpts is an optional list of constant options you would like to make default
	//
	// note: for an option to be read by the pre-compiler, all keys must start with a "$" in there name
	ConstOpts map[string]interface{}
}

Config is used in the SetConfig method to simplify the args and make them optional

type KeyVal

type KeyVal struct {
	Key []byte
	Val interface{}
}

KeyVal is used to allow key:value lists to be sorted in an array

Jump to

Keyboard shortcuts

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