Goplater is a Go commandline program that helps you template your files
Need help? Come join our Matrix Server!
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" }}
Goplater includes a large selection of built-in functions for use in your templates.
Reads and templates file. ExamplesExample: |
Reads file (without templating). ExamplesExample: |
Reads file and passes arguments to it. ExamplesExample: |
Writes to a file path. ExamplesExample: |
Creates directory at path. ExamplesExample: |
Appends to an existing file. ExamplesExample: |
Returns if a file or folder exists at a given path. ExamplesExample: |
Returns if a file exists at a given path. ExamplesExample: |
Returns if a folder exists at a given path. ExamplesExample: |
Returns all files and folders inside of a given directory. ExamplesExample: Output: |
Returns all files and folders recursively under a given directory. ExamplesExample: Output: |
Removes a file or folder at a given path. ExamplesExample: |
Joins paths together. |
Returns the last element of a path. |
Returns all but the last element of a path. |
Returns the file name extension of a file path. |
Returns an absolute representation of a given path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. |
Returns a relative path that is lexically equivalent to targetPath when joined to basePath with an intervening separator. The returned path will always be relative to basePath, even if basePath and targetPath share no elements. |
Changes the output path for the current file. Errors if path is not allowed. |
Encodes strings with base64. |
Decodes a base64 string. |
Deletes a container entry with the given key. ExamplesExample: Output: |
Set a container entry value with the given key. ExamplesExample: Output: |
Returns if an entry with the given key exists in container. ExamplesExample: |
Appends a value to a slice. ExamplesExample: Output: |
Creates a new slice, optionally with values. ExamplesExample: Output: |
Creates a new map, optionally with key value pairs. Pairs are constructed one by one, a key followed by the given value. Currently only supports string keys! ExamplesExample: Output: |
Returns a given value as string (using fmt.Sprint). |
Attempts to parse a string as int. |
Attempts to parse a string as float64. |
Attempts to parse a string as float32. |
Attempts to parse a string as a bool (using strconv.ParseBool). |
Defines a global value with a key. |
Tries to retrieve a global value with a key. |
Returns whether a given global variable exists. |
Tries to import a template file with func definitions.
Optionally supply an alias for easier access.
The fs resolver is only available as an internal module and does not ship with the ExamplesExample: Output: Example: Output: |
Sets an output value at the given index. |
Appends a value to the output. |
Sets the output object as a whole. ExamplesExample: |
Returns current outputs. |
Outputs data to stdout. |
Decodes html into a document. |
Finds elements in document by selector (using goquery.Find). |
Finds element in document by selector (using goquery.Find). |
Finds elements in element by selector (using goquery.Find). |
Finds element in element by selector (using goquery.Find). |
Returns the elements text content. |
Returns an elements attribute content. |
Returns the elements inner html. |
Fetches a resource from a given url. Outputs errors as string. |
Fetches a resource from a given url. Throws error instead of outputting it. |
Encodes an object into a json string. |
Decodes a json string into an object. |
Decodes markdown into a document. |
Encodes a document into markdown. |
Finds elements in target by selector (using custom). |
Finds element in target by selector (using custom). |
Returns whether node matches selector (using custom). |
Returns html markdown representation. |
Returns all raw markdown text in a node recursively. |
Returns all markdown headings. |
Returns all markdown links. |
Returns the url of a markdown link node. |
Sets a link node's url. |
Sets a link node's title. |
Returns the text of a markdown link node. |
Returns all markdown images. |
Returns the url of a markdown image node. |
Sets a image node's url. |
Sets a image node's alt. |
Returns all markdown paragraphs. |
Returns all markdown code blocks. |
Returns all markdown block quotes. |
Removes a markdown node. |
Appends text to a markdown document. |
Prepends text to a markdown document. |
Returns the abs value of a number. |
Returns the smaller value of two numbers. |
Returns the bigger value of two numbers. |
Clamps a value between a minimum and maximum value. |
Performs pow on base with exponent. |
Returns the square root of a number. |
Rounds a number to the nearest integer. |
Returns the greatest integer value less than or equal to number. |
Returns the least integer value greater than or equal to number. |
Adds numbers together. |
Subtracts numbers from each other. |
Multiplies numbers together. |
Divides numbers from each other. |
Performs modulo on numbers. |
Returns whether a string matches the given regex pattern. |
Returns all matches against the given regex pattern in a string. |
Returns all matches and submatches from the given regex pattern in a string. |
Returns all match and submatch positions from the given regex pattern in a string. |
Replaces all matches from the given regex pattern in a string with the replaceWith param (which allows using '$1', etc.). |
Trims space from a string (leading and trailing). |
Trims all chars defined in the cutset param from a string (leading and trailing). |
Uppercases a string. |
Lowercases a string. |
Returns whether a string contains the given substring. |
Counts all occurences of a substring in the given string. |
Returns whether a string starts with the given prefix. |
Returns whether a string ends with the given suffix. |
Returns whether the given string is empty. |
Replaces all occurences of a substring in the given string with the replaceWith param. |
Split a string by the given seperator. |
Returns the string after the given substring in a string. |
Returns the string before the given substring in a string. |
Returns the substring between the start and end substring. |
Removes a substring at the start of the given string. |
Removes a substring at the end of the given string. |
Slices a string based on start and end index. |
Joins multiple strings together by the given separator. |
Repeat a string n times. |
Decodes a yaml string into an object. |
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.
