不使用 tau 版本时如何使用 Leaf 读取 Vapor 上的 html 文件?

How to read html files on Vapor with Leaf when not using the tau version?

我使用 Leaf 的一个版本来加载 .html 文件,而不是我的 Vapor 项目中的 .leaf 文件,这会自动完成这些相同文件的语法着色。

Leaf 的版本是 4.0.0-tau.1,LeafKit 的版本是 1.0.0-tau.1.1

使用这个特定版本时,我可以这样在 configure.swift 文件中设置叶子:

/// Change the classic .leaf extension to .html for the syntax
/// coloring option of Xcode to work each time the app is being load up.
fileprivate func leaf(_ app: Application) {
  if !app.environment.isRelease {
    LeafRenderer.Option.caching = .bypass  // Another issue from the update
  }
  let detected = LeafEngine.rootDirectory ?? app.directory.viewsDirectory
  LeafEngine.rootDirectory = detected
  LeafEngine.sources = .singleSource(
    NIOLeafFiles(fileio: app.fileio,
                 limits: .default,
                 sandboxDirectory: detected,
                 viewDirectory: detected,
                 defaultExtension: "html"))
  app.views.use(.leaf)
}

在此代码中,LeafRenderer.Option.caching = .bypass 和与 LeafEngine 一起使用的代码不再工作,因为将 Leaf 更新为 4.1.3 并将 LeafKit 更新为 1.3.1

如何使用更新后的 Leaf 和 LeafKit 框架成功地使此代码像以前一样工作?

您可以使用这个 Xcode 插件: https://github.com/OmranK/VaporLeafPlugIn

它为 Xcode IDE 添加了 Vapor Leaf 语言支持。为 Leaf 标签和 HTML 标签提供语法高亮和自动缩进。

目前插件支持 Xcode 最高 13.2 beta。未来 Xcode 版本将需要小更新(添加新的 DVTPlugInCompatibilityUUID),但即使在已安装的插件上也可以轻松处理。