【问题标题】:How to read html files on Vapor with Leaf when not using the tau version?不使用 tau 版本时,如何使用 Leaf 读取 Vapor 上的 html 文件?
【发布时间】:2021-12-14 17:42:45
【问题描述】:

我使用了一个版本的 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 框架成功地使此代码像以前一样工作?

【问题讨论】:

    标签: swift vapor leaf


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-22
      • 2019-01-18
      • 2017-12-23
      • 2011-11-27
      • 1970-01-01
      相关资源
      最近更新 更多