Add better documentation
This commit is contained in:
59
README.md
59
README.md
@@ -1,5 +1,4 @@
|
||||
# Templateless
|
||||
|
||||
A lightweight, logicless templating library for the
|
||||
[Odin programming language](https://odin-lang.org/). This library allows you to
|
||||
define templates using placeholder variables within strings and replace them
|
||||
@@ -11,67 +10,23 @@ with values from a provided dictionary.
|
||||
- Designed to integrate easily into Odin projects
|
||||
- No errors returns
|
||||
|
||||
## Limitations
|
||||
|
||||
- No support for nested templates or conditionals.
|
||||
- Only basic string replacement — not a full-featured template engine.
|
||||
## Non Featureas
|
||||
- No conditionals nor nested templates.
|
||||
- Not a full-featured template engine.
|
||||
|
||||
## Usage
|
||||
For library usage and more information run:
|
||||
|
||||
```odin
|
||||
import "template"
|
||||
|
||||
main :: proc() {
|
||||
fmt := "Hello, {{name}}! Welcome to {{place}}."
|
||||
values := map[string]string{
|
||||
"name": "Alice",
|
||||
"place": "Odinland",
|
||||
}
|
||||
defer delete(values)
|
||||
|
||||
result := template.template(fmt, values)
|
||||
defer delete(result)
|
||||
|
||||
fmt.println(result) // Output: Hello, Alice! Welcome to Odinland.
|
||||
}
|
||||
```sh
|
||||
odin doc .
|
||||
```
|
||||
|
||||
## Installation
|
||||
Clone or copy the template module into your Odin project directory:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/nviam/odin-templateless.git
|
||||
````
|
||||
|
||||
Or copy `template.odin` into your source tree.
|
||||
|
||||
## Interface
|
||||
|
||||
```odin
|
||||
template :: proc(fmt: string, dict: map[string]string) -> string
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `fmt`: A string with placeholders in the form `{{key}}`.
|
||||
* `dict`: A map from string to string, where each key corresponds to a placeholder in the format string.
|
||||
|
||||
### Returns
|
||||
|
||||
A new string with all placeholders replaced by their corresponding values from
|
||||
the dictionary. If a key is missing in the dictionary, the placeholder is
|
||||
replaces with an empty string.
|
||||
|
||||
## Placeholder Format
|
||||
|
||||
Use `{{key}}` to indicate a variable placeholder in the format string.
|
||||
Keys must exactly match the strings in the dictionary.
|
||||
Clone or copy the template module into your Odin project directory.
|
||||
|
||||
## License
|
||||
|
||||
1-Clause BSD NON-AI License. See [LICENSE](./LICENSE) for details.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Feel free to submit issues or pull requests.
|
||||
For every issue please add a test
|
||||
|
||||
Reference in New Issue
Block a user