此软件包将 Bootstrap 元素封装为方便易用的 Leaf-Tags。
将 Bootstrap
添加到包依赖项中 (在您的 Package.swift
文件中)
dependencies: [
...,
.package(url: "https://github.com/nodes-vapor/bootstrap.git", from: "4.0.0")
]
以及添加到您的目标 (例如 “App”)
targets: [
...
.target(
name: "App",
dependencies: [... "Bootstrap" ...]
),
...
]
首先在您的 configure.swift
文件中导入 Bootstrap 和 Leaf
import Bootstrap
import Leaf
为了渲染 Bootstrap 元素,您需要添加 Bootstrap Leaf 标签
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
services.register { _ -> LeafTagConfig in
var tags = LeafTagConfig.default()
tags.useBootstrapLeafTags()
return tags
}
}
#bs:alert() { alert text }
#bs:badge(type?, classExtras?, attributes?) { badge text }
#bs:button(type?, classExtras?, attributes?) { btn text }
#bs:buttonGroup(isVertical, classExtras?, Aria?) { }
#bs:buttonGroup(false, "btn-group-sm") {
#bs:button() { First Option }
#bs:button("danger") { Second Option}
#bs:button() { Third Option}
}
#bs:buttonToolbar(classExtras?, Aria?) { }
#bs:buttonToolbar() {
#bs:button() { First Option }
#bs:button("danger") { Second Option}
#bs:button() { Third Option}
}
#bs:input(type?, classExtras?, attributes?)
#bs:breadcrumb(classExtras?, attributes?) {
#bs:breadcrumbItem(classExtras?, attributes?) { <a href="/"> Home </a> }
#bs:breadcrumbItem(classExtras?, attributes?) { Profile }
}
#bs:textArea(classExtras?, attributes?, value?)
#bs:card(title?, classExtras?, attributes?) { <card body> }
或
#bs:card:outer(title?, classExtras?, attributes?) {
#bs:card:header(classExtras?, attributes?) { <card header, if more than a simple string should be rendered> }
#bs:card:body(classExtras?, attributes?) { <card contents> }
#bs:card:footer(classExtras?, attributes?) { <card footer> }
}
此软件包由 Vapor 团队在 Nodes 开发和维护。
此软件包是根据 MIT 许可 开源的软件