If you set YES to the question of whether to use Leaf when creating a new project in Vapor, `index.leaf``` will be automatically generated in Resources/Views. This
.leaf``` extension is not syntax highlighted automatically in Xcode. (If you select Editor-> Syntax Coloring-> HTML, it will be applied temporarily, but if you close Xcode, it will return to the original, so you have to set it every time.) This is a hassle, so configure.swift should be able to read ``
.html``` as follows.
Add import Leaf Kit and app.leaf.Change sources with sources
#### **`configure.swift`**
```swift
import Leaf
import LeafKit
import Vapor
// configures your application
public func configure(_ app: Application) throws {
// uncomment to serve files from /Public folder
// app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
app.views.use(.leaf)
app.leaf.sources = .singleSource(NIOLeafFiles(fileio: app.fileio,
limits: .default,
sandboxDirectory: app.directory.viewsDirectory,
viewDirectory: app.directory.viewsDirectory,
defaultExtension: "html"))
// register routes
try routes(app)
}
index.from leaf to index.Change to html and change Syntax Coloring to HTML
![スクリーンショット 2020-12-21 11.46.35.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/16624/3b0b3e20-ee28-8089-f1b1-b5a44ee51e46.png)
Now, even if you close and restart Xcode, Syntax Coloring will still be applied.
Recommended Posts