Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vapor-community/mustache-provider
Render Mustache templates in Vapor
https://github.com/vapor-community/mustache-provider
Last synced: about 2 months ago
JSON representation
Render Mustache templates in Vapor
- Host: GitHub
- URL: https://github.com/vapor-community/mustache-provider
- Owner: vapor-community
- License: mit
- Created: 2016-03-29T03:01:39.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-24T06:23:02.000Z (almost 8 years ago)
- Last Synced: 2024-05-18T22:52:49.339Z (8 months ago)
- Language: Swift
- Homepage:
- Size: 24.4 KB
- Stars: 16
- Watchers: 12
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- TheList - Vapor Mustache
README
# Vapor Mustache
Vapor `RenderDriver` implementation for [Mustache](https://github.com/Zewo/Mustache).
## Installation
### Package
To add `VaporMustache`, add the following package to your `Package.swift`.
`Package.swift`
```swift
.Package(url: "https://github.com/qutheory/vapor-mustache.git", majorVersion: 0, minor: 8)
```### Provider
This package includes a Vapor Provider which makes it easy to add as a dependency.
```swift
import Vapor
import VaporMustachelet app = Application()
//routes, etc
app.providers.append(VaporMustache.Provider())
app.start()
```### Manual
If you don't want to use the Provider, set the `MustacheRenderer()` on your `View.renderers` for whatever file extensions you would like to be rendered as `Mustache` templates.
`main.swift`
```swift
import VaporMustache//set the mustache renderer
//for all .mustache files
View.renderers[".mustache"] = VaporZewoMustache.MustacheRenderer()
```## Includes
Includes let you load other mustache templates into your template with a syntax like `{{> header}}`.
To use includes, you must specify them ahead of time to the `MustacheRenderer`.
### Provider
Simply add them as the Provider's `includeFiles`.
```swift
let mustache = VaporMustache.Provider(withIncludes: [
"header": "Includes/header.mustache",
"footer": "Includes/footer.mustache"
])let app = Application(providers: [mustache])
```The path will be appended to `Resources/Views/...` by default.
### Manual
The `MustacheRenderer` accepts a dictionary of files where the key is the include name and the value is the file path relative to the working directory.
```swift
public init(files: [String: String])
```