Kitura

APIDoc Build Status - Master macOS Linux Apache 2 Slack Status

Kitura-Markdown

一个使用 Markdown 模板的 Kitura 模板引擎。

Kitura-Markdown 使得 Kitura 服务器能够提供由 Markdown 模板 (.md 文件) 生成的 HTML 内容。

Markdown 文件

Markdown 是一种轻量级的标记语言,使用纯文本格式语法。 掌握 Markdown 提供了关于如何编写 Markdown 文件的文档和示例。 默认情况下,Kitura 路由器将在 Views 文件夹中查找扩展名为 .md 的 Markdown 文件。

用法

添加依赖

Kitura-Markdown 包添加到应用程序的 Package.swift 文件中的依赖项中。 将 "x.x.x" 替换为最新的 Kitura-Markdown 版本

.package(url: "https://github.com/Kitura/Kitura-Markdown.git", from: "x.x.x")

KituraMarkdown 添加到您的目标的依赖项中

.target(name: "example", dependencies: ["KituraMarkdown"]),

导入包

import KituraMarkdown

示例

以下示例使用 kitura init 生成的服务器,并对其进行修改以提供来自 .md 文件的 Markdown 格式文本。

在此示例中将要编辑的文件如下

<ServerRepositoryName>
├── Package.swift
├── Sources
│    └── Application
│         └── Application.swift
└── Views
     └── Example.md

Views 文件夹和 Example.md 文件将在稍后创建,因为它们没有被 kitura init 初始化。

依赖项

将依赖项添加到您的 Package.swift 文件(如上文添加依赖中所定义)。

Application.swift

Application.swift 文件中,添加以下代码以在 "/docs" 路由上渲染 Example.md 模板文件。

import KituraMarkdown

postInit() 函数中添加以下代码

router.add(templateEngine: KituraMarkdown())
router.get("/docs") { _, response, next in
    try response.render("Example.md", context: [String:Any]())
    response.status(.OK)
    next()
}

Example.md

创建 Views 文件夹,并将以下 Markdown 模板代码放入名为 Example.md 的文件中

It's very easy to make some words **bold** and other words *italic* with Markdown. You can even [link to Kitura](https://github.com/Kitura/Kitura) and write code examples:
`print("Hello world!")`

当服务器运行时,访问 https://:8080/docs 以查看渲染的 Markdown 模板。

API 文档

有关更多信息,请访问我们的 API 参考

社区

我们喜欢讨论服务器端的 Swift 和 Kitura。 加入我们的 Slack 来认识团队!

许可

此库在 Apache 2.0 许可下发布。 完整的许可文本可在 LICENSE 中找到。