vapor / template-kit

📄 Easy-to-use foundation for building powerful templating languages in Swift.
MIT License
46 stars 17 forks source link

Error When Passing Inline Array Or Dict To Tag #27

Closed mikebronner closed 6 years ago

mikebronner commented 6 years ago

Steps to reproduce:

  1. Create a new vapor project: vapor new test-inline-array cd test-inline-array vapor xcode -y
  2. Add Leaf to Package.swift:

    // swift-tools-version:4.1
    import PackageDescription
    
    let package = Package(
      name: "test",
      dependencies: [
          .package(url: "https://github.com/vapor/vapor.git", from: "3.0.4"),
          .package(url: "https://github.com/vapor/leaf.git", from: "3.0.0-rc.2"),
      ],
      targets: [
          .target(name: "App", dependencies: ["Leaf", "Vapor"]),
          .target(name: "Run", dependencies: ["App"]),
          .testTarget(name: "AppTests", dependencies: ["App"])
      ]
    )
  3. Register Leaf in configure.swift (and import Leaf at the top of the file):
    try services.register(LeafProvider())
    config.prefer(LeafRenderer.self, for: ViewRenderer.self)
  4. Register the test route in routes.swift:
    router.get("test", use: TestController().index)
  5. Create the controller in /Sources/App/Controllers/TestController.swift:

    import Vapor
    
    final class TestController {
      func index(_ request: Request) throws -> Future<View> {
          return try request.view().render("test.leaf")
      }
    }
  6. Create a new view file: /Resources/Views/test.leaf
  7. Paste the following content:
    Hello!
    #count(["class", "test"])
  8. Build and run the test app, open browser to: http://localhost:8080/test.
  9. The following error is displayed:
    {"error":true,"reason":"Expected ')' got '[' (\/Users\/mike\/Developer\/test\/Resources\/Views\/test.leaf line: 1 column: 31 range: 40..<40)"}

Updated leaf page to not include ConvertToTemplateData class, I was just testing possible solutions.

tanner0101 commented 6 years ago

Moving this to: https://github.com/vapor/leaf/issues/121. TemplateKit only handles serialization. Leaf is responsible for parsing the files.

mikebronner commented 6 years ago

Thanks ... wasn't sure.

tanner0101 commented 6 years ago

No worries. Thanks for reporting! :)