Skip to content

Commit

Permalink
Merge pull request #4 from micheltlutz/feature/Title
Browse files Browse the repository at this point in the history
New tag Title and new init for meta
  • Loading branch information
micheltlutz authored Aug 13, 2024
2 parents ee6f7b9 + 7f7645b commit e13f96c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/WingedSwift/HTML/Commons/Meta.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ public class Meta: HTMLTag {
allAttributes.append(Attribute(key: "content", value: content))
super.init("meta", attributes: allAttributes)
}

/// Initializes a new <meta> tag.
///
/// - Parameters:
/// - attributes: Additional attributes of the <meta> tag.
public init(attributes: [Attribute] = []) {
let allAttributes = attributes
super.init("meta", attributes: allAttributes)
}
}
12 changes: 12 additions & 0 deletions Sources/WingedSwift/HTML/Commons/Title.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

/// Represents a <title> HTML tag.
public class Title: HTMLTag {
/// Initializes a new title tag.
///
/// - Parameters:
/// - content: The content of the <title> tag.
public init(content: String) {
super.init("title", attributes: [], children: [], content: content)
}
}
25 changes: 25 additions & 0 deletions Tests/WingedSwiftTests/HTMLTagTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,29 @@ final class HTMLTagTests: XCTestCase {
"""
XCTAssertEqual(document.render(), expected)
}

func testMetaWithName() {
let document = html {
Meta(name: "description", content: "A description of the page")
Meta(attributes: [Attribute(key: "charset", value: "utf-8")])
}

let expected = """
<html><meta name="description" content="A description of the page" /><meta charset="utf-8" /></html>
"""
XCTAssertEqual(document.render(), expected)
}

func testHTMLTitle() {
let document = html {
Title(
content: "Title my site"
)
}

let expected = """
<html><title>Title my site</title></html>
"""
XCTAssertEqual(document.render(), expected)
}
}

0 comments on commit e13f96c

Please # to comment.