Goplater is a Go commandline programm that helps you template your files
Download the latest binary from the Release page.
Make it executable with chmod +x goplater and run it for the first time.
Use the goplater template command to template files:
./goplater template TEMPLATE.md -o README.mdThis will create a new file called README.md in your current working directory.
Goplater uses Go's builtin templating library therefor the syntax should be consistent with other projects.
Example:
File Content: ${{{ read "./myfile.txt" }}}
As you saw in the example above read is used for reading and output file contents.
But there are more as you will see in the following…
Reads from absolute or relative file path (depending on input), where relative paths are relative to the invoker.
read "path"
Same as read but with another parameter for additional arguments:
| Short | Long | Type | Note |
|---|---|---|---|
-r |
--recursive |
bool |
tries templating read files |
read "path" "--flag1" "--flag2"
Performs a get http request to the specified url.
fetch "url"
Parses json string as dictionary (map[string]any).
Parses yaml string as dictionary (map[string]any).
Parses html string as html document.
Query element by selector in html document.
htmlDocFind ( html "html_string" ) "h3:contains['xyz']"
Query element by selector within another element.
htmlFind ( htmlDocFind document ) "h3:contains['xyz']"
Outputs inner text of a html element.
htmlText ( htmlDocFind document "selector" )
Outputs the value of the specified elements attribute.
htmlAttr ( htmlDocFind document "selector" ) "attribute"
Outputs element's inner html string.
htmlInner ( htmlDocFind document "selector" )
Outputs trimmed string.
Outputs uppercased string.
Outputs lowercased string.
Returns wether string contains substring.
contains "Sunflower" "flower"
Replaces substring with new string in old string.
replace "Sunflower" "flower" "shine"
Split string by separator and return array of all parts.
split "Apple, Banana, Strawberry" ", "
Joins strings with separator.
join "Apple" "Banana" "Strawberry" ", "
Appends another string to string.
append "Hello " "World!"
Outputs wether string matches regex.
regexMatch "[0-9]" "0123456789"
Returns a list of all regex matches.
index ( regexFind "[1-36-9]" "01234 56789" ) 0
Returns a nested list ([][]string) of all regex submatches (groups (.*)).
index ( index ( regexFindGroups "(_*)(\S+)(_*)" "__xyz__" 0 ) 0 )
Replaces substring via regex in string.
regexReplace "string" "replace_regex" "replace_with"
Deletes an entry from a dictionary or array.
delete map "key"
delete array 0
Sets key in dictionary or array to value.
set map "key" value
set array 0 value
Pushes value onto top of array.
push array value
In addition to the function in the Simple Functions section, there are also some functions for advanced usage.
Imports a file and executes it as template, output is discarded.
import "functions.inc.gtmpl"
Sets key globally to value.
globalSet "key" value
Returns global value at key.
Defines a global function.
funcDefine "name" "{{{ return 0 "Hello World" }}}"
The second argument is the template body, notice the {{{ ... }}} instead of ${{{ ... }}}.
Warning
You may need to escape some characters like " with \
Raw output is discarded only output via return persists.
Warning
This function is only accessible from within functions!
Sets return argument at index to value.
funcDefine "helloWorld" "{{{ return 0 "Hello World!" }}}"
Overwriting previous return arguments is possible.
Same as return, but appends to output.
Shorthand for:
return i+1 value
returnNext value
Sets return output array directly with multiple arguments.
returnAll out1 out2 out3
Sets return output array directly with one array.
returnOutputs array
Returns the whole output array.
Calls a global function by its name (without passing any arguments).
funcCall "name"
Returns list of return outputs in order of index.
Same as funcCall, but arguments can be passed.
funcCallArgs "name" arg1 arg2
Arguments are accessible in function body with {{{ index .args 0 }}}.
Found a bug or just want to change or add something? Feel free to open up an issue or a PR!
Like this Project? Or just want to help? Why not ⭐️ this Repo? :)
This Project is licensed under the MIT License.
Logo designed by @CodeShellDev — All Rights Reserved. Go gopher mascot originally created by Renée French, used under the CC BY 4.0 license.
