Bootstrap 🍃

Swift Version Vapor Version Circle CI codebeat badge codecov Readme Score GitHub license

此软件包将 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

添加 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
    }
}

支持的标签

Alert

#bs:alert() { alert text }

Badge

#bs:badge(type?, classExtras?, attributes?) { badge text }

Button

#bs:button(type?, classExtras?, attributes?) { btn text }

Button Group

#bs:buttonGroup(isVertical, classExtras?, Aria?) { }
#bs:buttonGroup(false, "btn-group-sm") {
    #bs:button() { First Option }
    #bs:button("danger") { Second Option}
    #bs:button() { Third Option}
}

Button Toolbar

#bs:buttonToolbar(classExtras?, Aria?) { }
#bs:buttonToolbar() {
    #bs:button() { First Option }
    #bs:button("danger") { Second Option}
    #bs:button() { Third Option}
}

Input

#bs:input(type?, classExtras?, attributes?)

Breadcrumb

#bs:breadcrumb(classExtras?, attributes?) {
  #bs:breadcrumbItem(classExtras?, attributes?) { <a href="/"> Home </a> }
  #bs:breadcrumbItem(classExtras?, attributes?) { Profile }
}

Textarea

#bs:textArea(classExtras?, attributes?, value?)

Card

#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 许可 开源的软件