简体   繁体   中英

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

There was a version of Leaf that I was using to load .html files instead of .leaf ones from my Vapor project, which would make syntax coloring for those same files done automatically.

The version of Leaf was 4.0.0-tau.1 and the one for LeafKit was 1.0.0-tau.1.1

When using this particular version, I could setup leaf in the configure.swift file this way:

/// 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)
}

In this code, the LeafRenderer.Option.caching = .bypass and the code used with LeafEngine do not work anymore since having updated Leaf to 4.1.3 and LeafKit to 1.3.1 .

How can I successfully make this code work as before with the updated Leaf and LeafKit frameworks?

You can use this Xcode plugin: https://github.com/OmranK/VaporLeafPlugIn

It adds Vapor Leaf language support to Xcode IDE. Provides syntax highlighting for Leaf tags as well as HTML tags with auto-indentation all together.

At the moment the plugin supports Xcode up to 13.2 beta. Future Xcode versions will require small update (add new DVTPlugInCompatibilityUUID) but it can be easily handled even on already installed plugin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM