Remove HB prefix, make Parser private (#26)

This commit is contained in:
Adam Fowler
2024-03-11 22:07:05 +00:00
committed by GitHub
parent f029081b61
commit bdfa05391a
25 changed files with 300 additions and 262 deletions

View File

@@ -8,7 +8,7 @@ While Hummingbird Mustache has been designed to be used with the Hummingbird ser
Load your templates from the filesystem
```swift
let library = HBMustacheLibrary("folder/my/templates/are/in")
let library = MustacheLibrary("folder/my/templates/are/in")
```
This will look for all the files with the extension ".mustache" in the specified folder and subfolders and attempt to load them. Each file is registed with the name of the file (with subfolder, if inside a subfolder) minus the "mustache" extension.
@@ -20,23 +20,23 @@ let output = library.render(object, withTemplate: "myTemplate")
### Using with Hummingbird
HummingbirdMustache doesn't have any integration with Hummingbird as I wanted to keep the library dependency free. But if you are going to use the library with Hummingbird it is recommended you extend `HBApplication` to store an instance of your library.
HummingbirdMustache doesn't have any integration with Hummingbird as I wanted to keep the library dependency free. But if you are going to use the library with Hummingbird it is recommended you extend `Application` to store an instance of your library.
```swift
extension HBApplication {
var mustache: HBMustacheLibrary {
extension Application {
var mustache: MustacheLibrary {
get { self.extensions.get(\.mustache) }
set { self.extensions.set(\.mustache, value: newValue) }
}
}
extension HBRequest {
var mustache: HBMustacheLibrary { self.application.mustache }
extension Request {
var mustache: MustacheLibrary { self.application.mustache }
}
// load mustache templates from templates folder
application.mustache = try .init(directory: "templates")
```
You can now access your mustache templates via `HBRequest` eg `HBRequest.mustache.render(obj, withTemplate: "myTemplate")`
You can now access your mustache templates via `Request` eg `Request.mustache.render(obj, withTemplate: "myTemplate")`
## Support