Skip to content

Commit

Permalink
Update README and Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
fallsimply committed Mar 16, 2020
1 parent d2ca221 commit bca2c15
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# IDE Config
.vscode/launch.json
.idea
.idea
.DS_Store
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Bilit
[![Try it on Go Playground](https://img.shields.io/static/v1?label=Go%20Playground&message=Try%20It&color=00addc&style=for-the-badge&logo=go)](https://play.golang.org/p/n9MtRW_RIlg) [![MIT Licensed](https://img.shields.io/github/license/simplycodin/bilit?style=for-the-badge)](./LICENSE)
[![MIT Licensed][License Badge]](./LICENSE) [![Latest Version][Latest Badge]](https://github.com/simplycodin/bilit/releases/latest)

Bilit (pronounced /ˈbilit/) is a bidirectional template library for Go.
Inspired by Javascript's Template Literals and [Nunjucks](https://mozilla.github.io/nunjucks/templating.html)

Powered by Regular Expressions

## Examples
### Modern API - Basic:
### Modern API - Basic:
[![Open Example Folder][Open Badge]](./examples/modern) [![Try it on Go Playground][Play Badge]][Modern API]
``` go
template := bilit.Template("Hello, I'm {{name}} from ${City}, {{from_state}}")

Expand All @@ -24,9 +25,10 @@ fmt.Println(str, "end")
data := template.Pull(tr)
fmt.Println(data)
// map[City:Dallas from_state:TX name:John]

```

### Function API (Old API) - Basic:
[![Open Example Folder][Open Badge]](./examples/modern) [![Try it on Go Playground][Play Badge]][Function API]
``` go
const template = "Hello, I'm {{name}} from ${City}, {{from_state}}"

Expand All @@ -44,15 +46,10 @@ data := bilit.Pull(template, str)
fmt.Println(data)
// map[City:Dallas from_state:TX name:John]
```
Open [Function API Example](./examples/function)

## TODO
- [ ] Escape RegExp Symbols
- [x] Parenthesis - `()`
- [x] Curly Brackets - `{}`
- [x] Square Brackes - `[]`
- [ ] Period - `.`
- [ ] Plus Sign - `+`
- [ ] Question Mark - `?`
- [ ] Dollar Sign - `$`
- [ ] Caret - `^`

[Play Badge]: https://img.shields.io/static/v1?label=Go%20Playground&message=Try%20It&color=00addc&style=for-the-badge&logo=go
[Modern API]: https://play.golang.org
[Function API]: https://play.golang.org/p/n9MtRW_RIlg
[License Badge]: https://img.shields.io/github/license/simplycodin/bilit?style=for-the-badge
[Latest Badge]: https://img.shields.io/github/v/release/simplycodin/bilit?style=for-the-badge
[Open Badge]: https://img.shields.io/static/v1?label=Open&message=Example%20Folder&color=green&style=for-the-badge
6 changes: 3 additions & 3 deletions examples/function/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func main() {
bilit.Debug = true

const template = "Hello, I'm [{{name}}] from (${City}), {{{from_state}}})"
const template = "Hello, I'm [{{name}}] from (${City}), {{{from_state}}}"

dataSrc := map[string]string{
"name": "John",
Expand All @@ -18,8 +18,8 @@ func main() {
}

str := bilit.Populate(template, dataSrc)
fmt.Println(str)
fmt.Println("[Function API]", str)

data := bilit.Pull(template, str)
fmt.Println(data)
fmt.Println("[Function API]", data)
}
4 changes: 4 additions & 0 deletions examples/modern/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module github.com/SimplyCodin/bilit/examples/modern

go 1.12

require github.com/SimplyCodin/bilit v0.4.1

replace github.com/SimplyCodin/bilit => ../../
Empty file added examples/modern/go.sum
Empty file.
25 changes: 25 additions & 0 deletions examples/modern/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"fmt"

"github.com/SimplyCodin/bilit"
)

func main() {
bilit.Debug = true

template := bilit.Template("Hello, I'm [{{name}}] from (${City}), {{{from_state}}}")

dataSrc := map[string]string{
"name": "John",
"City": "Dallas",
"from_state": "TX",
}

str := template.Populate(dataSrc)
fmt.Println("[Modern API]", str)

data := template.Pull(str)
fmt.Println("[Modern API]", data)
}

0 comments on commit bca2c15

Please sign in to comment.