Skip to content

chore: auto-generated quick fix #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ To use WebUI, ensure you have the following installed:

### Script

If you pass no template the static one will be used by default and if you pass no project name it will default to `web-ui-template`

```sh
curl -fSls https://raw.githubusercontent.com/maclong9/web-ui/refs/heads/main/initialize.sh | sh
curl -fSls https://raw.githubusercontent.com/maclong9/web-ui/refs/heads/main/initialize.sh | sh -s -- --template [static|server] [<project-name>]
```

### Manually
Expand Down
11 changes: 6 additions & 5 deletions Sources/WebUI/Elements/Base/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public enum ListType: String {
///
/// HTML supports various styles for list elements, such as disc, circle, or square.
/// This enum provides a type-safe way to specify which style to use.
public enum StyleType: String {
public enum ListStyle: String {
/// Creates a list with no bullets or numbers.
case none
case none = ""

/// Creates a list with bullets shaped like discs.
case disc
Expand All @@ -29,7 +29,7 @@ public enum StyleType: String {
case circle

/// Creates a list with bullets shaped like squares.
case square
case square = "[square]"
}

/// Generates HTML list elements (`<ul>` or `<ol>`).
Expand All @@ -50,6 +50,7 @@ public enum StyleType: String {
/// ```
public final class List: Element {
let type: ListType
let style: ListStyle

/// Creates a new HTML list element (`<ul>` or `<ol>`).
///
Expand All @@ -72,7 +73,7 @@ public final class List: Element {
/// ```
public init(
type: ListType = .unordered,
style: ListStyle = .disc,
style: ListStyle = .none,
id: String? = nil,
classes: [String]? = nil,
role: AriaRole? = nil,
Expand All @@ -85,7 +86,7 @@ public final class List: Element {
super.init(
tag: type.rawValue,
id: id,
classes: classes ?? [] + style.rawValue,
classes: (classes ?? []) + (style != .none ? ["list-\(style.rawValue)"] : []),
role: role,
label: label,
data: data,
Expand Down
11 changes: 11 additions & 0 deletions Tests/WebUITests/ElementTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ import Testing
#expect(rendered.contains("</ol>"))
}

@Test("List Styles")
func testListStyles() async throws {
let disc = List(style: .disc).render()
let circle = List(style: .circle).render()
let square = List(style: .square).render()

#expect(disc.contains("list-disc"))
#expect(circle.contains("list-circle"))
#expect(square.contains("list-[square]"))
}

// MARK: - Media Tests

@Test("Picture element with multiple sources")
Expand Down
2 changes: 1 addition & 1 deletion Tests/WebUITests/Styles/BaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ import Testing
func testFontWithDecorationAndWrapping() async throws {
let element = Element(tag: "div").font(decoration: .underline, wrapping: .nowrap)
let rendered = element.render()
#expect(rendered.contains("class=\"decoration-underline text-nowrap\""))
#expect(rendered.contains("class=\"underline text-nowrap\""))
}

@Test("Font with family and modifier")
Expand Down
67 changes: 67 additions & 0 deletions examples/static/.github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Build and Deploy Static Site

on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: write

jobs:
build:
runs-on: macos-15
steps:
# Check out the repository code
- uses: actions/checkout@v4

# Set up Swift
- name: Setup Swift
uses: swift-actions/setup-swift@v2

# Cache Swift build artifacts
- name: Cache Swift Build
uses: actions/cache@v4
id: cache-swift-build
with:
path: .build
key: ${{ runner.os }}-swift-build-${{ hashFiles('Package.swift', 'Sources/**') }}
restore-keys: |
${{ runner.os }}-swift-build-

# Build the project
- name: Build
run: swift build -v
if: steps.cache-swift-build.outputs.cache-hit != 'true'

# Cache generated site output
- name: Cache Generated Site
uses: actions/cache@v4
id: cache-site-output
with:
path: .output
key: ${{ runner.os }}-site-output-${{ hashFiles('Sources/**') }}
restore-keys: |
${{ runner.os }}-site-output-

# Run the static site generator
- name: Generate Site
run: swift run Application
if: steps.cache-site-output.outputs.cache-hit != 'true'

# Push to static branch (only on push to main)
- name: Push to static branch
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
git config user.name "GitHub Actions Bot"
git config user.email "actions@github.com"
git checkout -B static
rm -rf ./*
mv .output/* .
rm -rf .output .gitignore .github .build .swift-format
git add .
git commit -m "release: update static site content"
git push origin static --force
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions examples/static/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
.build/
.output/
.swiftpm/
61 changes: 61 additions & 0 deletions examples/static/.swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"indentation" : {
"spaces" : 4
},
"tabWidth" : 4,
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"spacesAroundRangeFormationOperators" : false,
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : true,
"lineLength" : 120,
"maximumBlankLines" : 1,
"respectsExistingLineBreaks" : true,
"prioritizeKeepingFunctionOutputTogether" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : false,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"UseEarlyExits" : false,
"UseExplicitNilCheckInConditions" : false,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : false,
"UseSynthesizedInitializer" : false,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
}
}
42 changes: 42 additions & 0 deletions examples/static/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions examples/static/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// swift-tools-version: 6.1

import PackageDescription

let package = Package(
name: "Portfolio",
platforms: [.macOS(.v15)],
dependencies: [
.package(url: "https://github.com/maclong9/web-ui.git", from: "1.0.0")
],
targets: [
.executableTarget(
name: "Application",
dependencies: [
.product(name: "WebUI", package: "web-ui")
],
path: "Sources",
resources: [.process("Public")]
)
]
)
36 changes: 36 additions & 0 deletions examples/static/Sources/Application.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Foundation
import WebUI

@main
actor Application {
static let metadata = Metadata(
site: "example",
titleSeperator: " | ",
description: "A static website built with Swift and WebUI",
image: "https://placehold.co/600x400/EEE/31343C",
author: "Swift Developer",
keywords: [
"swift", "web development", "static site", "webui",
],
type: .website,
favicons: [
.init("https://fav.farm/🖥", type: "image/svg")
],
)

static let routes = [
Home().document,
About().document,
]

static func main() async {
do {
try Website(
metadata: metadata,
routes: routes,
).build()
} catch {
print("Failed to build application: \(error)")
}
}
}
62 changes: 62 additions & 0 deletions examples/static/Sources/Components/Layout.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import Foundation
import WebUI

struct Layout: HTML {
let children: Children

init(@HTMLBuilder children: @escaping HTMLContentBuilder) {
self.children = Children(content: children)
}

public func render() -> String {
Stack {
Header {
Link(to: "/") { Application.metadata.site! }
.font(size: .xl2)
.font(size: .xl3, on: .md)
.font(decoration: .underline, on: .hover)
Navigation {
for path in Application.routes {
Link(to: "/\(path.path ?? "")") { path.metadata.title ?? "" }
.font(size: .sm)
.font(size: .base, on: .md)
.font(decoration: .underline, on: .hover)
}
}.flex(align: .center).spacing(of: 2, along: .x)
}
.flex(justify: .between, align: .center)
.frame(width: .full, maxWidth: .character(86))
.margins(at: .bottom)
.margins(at: .horizontal, auto: true)
.padding(at: .vertical)

Main {
children.render()
}
.flex(grow: .one)
.font(wrapping: .pretty)
.frame(maxWidth: .character(72))
.margins(at: .horizontal, auto: true)

Footer {
Text {
"© \(Date().formattedYear()) "
Link(to: "/") { Application.metadata.site! }.font(
weight: .normal
)
}.font(size: .sm, color: .neutral(._700, opacity: 0.7))
}
.flex(justify: .center, align: .center)
}
.font(family: "system-ui")
.frame(minHeight: .screen)
.flex(direction: .column)
.padding()
.responsive {
$0.md {
$0.font(size: .lg)
}
}
.render()
}
}
Loading