Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM authored Jul 16, 2024
1 parent e742d65 commit 8c79311
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@
A utility for creating case-by-case code for your Swift enums using the Mustache templating engine.
`EnumeratorMacro` uses [swift-mustache](https://github.com/hummingbird-project/swift-mustache)'s flavor.

This macro will parse your enum code, and pass different info of your enum to the mustache template renderer.
This way you can access the enum's info such as each case-name or case-parameters in the template, and create code based on that.
The macro will parse your enum code, and pass different info of your enum to the mustache template renderer.
Then you can access each case-name, case-parameters etc.. in the template, and create code based on that.

This can automate and simplify creation of code that has a repeated pattern, for enums.

## How Does Mustache Templating Work?

It's rather simple.
* Inject variables using the `{{variableName}}` syntax.
* Loop though arrays using the `{{#array}} {{/array}}` syntax.
* Apply if conditions using the `{{#boolean}} {{/boolean}}` syntax.
* Apply inverted if conditions using the `{{^boolean}} {{/boolean}}` syntax.
* Apply transformations using the "function call" syntax: `snakedCased(variable)`.
* Available transformations are mentioned below.
* See [the reference](https://mustache.github.io/mustache.5.html) and the [swift-mustache docs](https://docs.hummingbird.codes/2.0/documentation/mustache) for more info.

## Examples

### Derive Case Names
Expand Down Expand Up @@ -252,13 +263,6 @@ enum TestEnum {
}
```

## How Does Mustache Templating Work?

It's rather simple.
* Inject variables using the `{{variableName}}` syntax.
* Loop though arrays using the `{{#array}} {{/array}}` syntax.
* Apply transformations using the "function call" syntax: `snakedCased(variable)`.

## Available Context Values

Here's a sample context object:
Expand Down

0 comments on commit 8c79311

Please sign in to comment.