refactor: Introducing Environments

This commit is contained in:
Kyle Fuller
2016-12-01 00:17:04 +00:00
parent 2be672c6a5
commit 9e2a061795
27 changed files with 289 additions and 91 deletions

View File

@@ -19,25 +19,24 @@ There are {{ articles.count }} articles.
```
```swift
import Stencil
struct Article {
let title: String
let author: String
}
let context = Context(dictionary: [
let context = [
"articles": [
Article(title: "Migrating from OCUnit to XCTest", author: "Kyle Fuller"),
Article(title: "Memory Management with ARC", author: "Kyle Fuller"),
]
])
]
do {
let template = try Template(named: "template.html")
let rendered = try template.render(context)
print(rendered)
} catch {
print("Failed to render template \(error)")
}
let environment = Environment(loader: FileSystemLoader(paths: ["templates/"])
let rendered = try environment.renderTemplate(name: context)
print(rendered)
```
## Installation