jetfunc

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: MIT Imports: 8 Imported by: 0

README

Jetfunc

Template functions for Jet templating engine

Documentation

Overview

Package jetfunc provides provides set of functions, which can be used along with the Jet templating engine. It supports jet v6. See the templating engine itself, on address https://github.com/CloudyKit/jet.

Usage in templates

All functions can be accessed from template using both camelCase name, or PascalCase name. For example, both of these forms will work:

{{ leftPad('what',10) }}
{{ LeftPad('what',10  }}

Usage in go code

 package main
 import (
     "https://github.com/CloudyKit/jet/v6"
     "gitlab.com/Herout/jetfunc"
 )

 func main() {
   dir := "path/to/template/dir"
	  set := jet.NewSet(jet.NewOSFileSystemLoader(dir), jet.WithSafeWriter(nil))
   jetfunc.AddFunctionsToSet(set)
   // ... and now, do something with the set
 }

Disclaimer

This is an alpha release. API is unstable. Should this break your code, you get to keep both pieces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFunctionsToSet

func AddFunctionsToSet(v *jet.Set)

AddFunctionsToSet registers all functions to jet.Set.

func Default

func Default(a jet.Arguments) reflect.Value

Default takes one or more parameters, and returns first non-empty string from these parameters, or empty string.

{{ default(a,b,c,'return this if all are empty') }}

func EqualFold

func EqualFold(a jet.Arguments) reflect.Value

EqualFold is a wrapper over strings.EqualFold.

func IfFirst

func IfFirst(a jet.Arguments) reflect.Value

IfFirst accepts two, or three parameters.

{{ ifFirst(aNumber,wantFirst,wantElse)}}

The function:

  • returns wantFirst string, if first parameter (aNumber) is integer, and also aNumber == 0
  • else returns wantElse string; if wantElse is not provided, returns empty string.

func IsAmongStrings added in v0.0.6

func IsAmongStrings(a jet.Arguments) reflect.Value

InStrings returns true if the first parameter is contained within a set of other strings.

func LeftPad

func LeftPad(a jet.Arguments) reflect.Value

LeftPad returns string padded left by spaces, or by the third parameter, if such is provided. Input parametewrs are:

  • toPad - mandatory string, which will be padded
  • toLen - mandatory integer, pad to which length
  • padChar - optional string, defaults to space

func QQUote

func QQUote(a jet.Arguments) reflect.Value

QQUote accepts one, or two parameters.

  • want - string, will be returned quoted by double qoute, all inside doubleqoutes will be doubled.
  • ie: {{ doubleQuote('this') }} renders as "this"
  • ie: {{ doubleQuote('this "is" Sparta') }} renders as "this ""is"" Sparta"
  • orElse - string, optional; this will be returned 'as is' if want == ""
  • ie: {{ doubleQuote(”,'NULL') }} renderes as NULL

func Quote

func Quote(a jet.Arguments) reflect.Value

Quote accepts one, or two parameters.

  • want - string, will be returned quoted, all inside quotes will be doubled.
  • ie: {{ doubleQuote('this') }} renders as 'this'
  • ie: {{ doubleQuote('this ”is” Sparta') }} renders as 'this ”is” Sparta'
  • orElse - string, optional; this will be returned as-is, if want == ""
  • ie: {{ doubleQuote(”,'NULL') }} renderes as NULL

func RightPad

func RightPad(a jet.Arguments) reflect.Value

RightPad returns string padded right by spaces, or by the third parameter, if such is provided. Input parametewrs are:

  • toPad - mandatory string, which will be padded
  • toLen - mandatory integer, pad to which length
  • padChar - optional string, defaults to space

func StashGet

func StashGet(a jet.Arguments) reflect.Value

StashGet retrieves string from global stash.

func StashReset

func StashReset(a jet.Arguments) reflect.Value

StashReset creates an empty global stash. The global stash is mutex protected map[string]string, which can later on be accessed via StashSet and StashGet functions. The function takes one oprional parameter. If the value provided is string "true", then StashGet WILL panic if you attempt to access key which was nat yet stored using StashSet.

func StashSet

func StashSet(a jet.Arguments) reflect.Value

StashSet stores a string value in the stash, and returns an empty string.

func Substring

func Substring(a jet.Arguments) reflect.Value

Substring returns a substring, based on following three parameters.

  • what - string, which we want to get substring from.
  • startAt - integer, starting position from which we want to get substring
  • wantRunes - optional, integer, number of runes we want to get; if not provided, gets the rest of the string.

On any error, Substring returns whole "what" parameter.

func TrimPrefix

func TrimPrefix(a jet.Arguments) reflect.Value

TrimPrefix is a wrapper over strings.TrimPrefix.

func TrimSuffix

func TrimSuffix(a jet.Arguments) reflect.Value

TrimSuffix is a wrapper over strings.TrimSuffix.

Types

This section is empty.

Jump to

Keyboard shortcuts

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