Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyRose2798 committed Mar 19, 2024
0 parents commit 35b7344
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: test

on:
push:
branches:
- master
- main
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: "26.0.2"
gleam-version: "1.0.0"
rebar3-version: "3"
# elixir-version: "1.15.4"
- run: gleam deps download
- run: gleam test
- run: gleam format --check src test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.beam
*.ez
/build
erl_crash.dump
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# sprinkle

[![Package Version](https://img.shields.io/hexpm/v/sprinkle)](https://hex.pm/packages/sprinkle)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/sprinkle/)

```sh
gleam add sprinkle
```
```gleam
import sprinkle.{format}
pub fn main() {
let output = format("My name is {name} and I like to do {activity}!", [
#("name", "Lily"),
#("activity", "programming")
])
}
```

Further documentation can be found at <https://hexdocs.pm/sprinkle>.

## Development

```sh
gleam run # Run the project
gleam test # Run the tests
gleam shell # Run an Erlang shell
```
12 changes: 12 additions & 0 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name = "sprinkle"
version = "1.0.0"

description = "A simple to use string formatting library"
licences = ["AGPL-3.0-only"]
repository = { type = "github", user = "LilyRose2798", repo = "sprinkle" }

[dependencies]
gleam_stdlib = "~> 0.34 or ~> 1.0"

[dev-dependencies]
gleeunit = "~> 1.0"
11 changes: 11 additions & 0 deletions manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was generated by Gleam
# You typically do not need to edit this file

packages = [
{ name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
]

[requirements]
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
gleeunit = { version = "~> 1.0" }
8 changes: 8 additions & 0 deletions src/sprinkle.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import gleam/string
import gleam/list

pub fn format(format_string: String, data: List(#(String, String))) -> String {
list.fold(data, format_string, fn(acc, cur) {
string.replace(acc, each: "{" <> cur.0 <> "}", with: cur.1)
})
}
25 changes: 25 additions & 0 deletions test/sprinkle_test.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import gleeunit
import gleeunit/should
import sprinkle.{format}

pub fn main() {
gleeunit.main()
}

pub fn format_single_test() {
format("My name is {name}!", [#("name", "Lily")])
|> should.equal("My name is Lily!")
}

pub fn format_mutiple_test() {
format("My name is {name} and I like to do {activity}!", [
#("name", "Lily"),
#("activity", "programming"),
])
|> should.equal("My name is Lily and I like to do programming!")
}

pub fn format_repeated_test() {
format("My name is {name}! Yep, it's definitely {name}.", [#("name", "Lily")])
|> should.equal("My name is Lily! Yep, it's definitely Lily.")
}

0 comments on commit 35b7344

Please sign in to comment.