Skip to content

Commit

Permalink
Change crossorigin to take a bool argument
Browse files Browse the repository at this point in the history
As per review comments on #87
  • Loading branch information
davidrothera committed Apr 3, 2023
1 parent bb1b9bf commit 64d234a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Sources/Plot/API/HTMLAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public extension Attribute where Context == HTML.LinkContext {
}

/// Assign a `crossorigin` attribute to the link.
static func crossorigin() -> Attribute {
Attribute(name: "crossorigin", value: nil, ignoreIfValueIsEmpty: false)
static func crossorigin(_ crossOrigin: Bool) -> Attribute {
crossOrigin ? Attribute(name: "crossorigin", value: nil, ignoreIfValueIsEmpty: false) : .empty
}
}

Expand Down
16 changes: 14 additions & 2 deletions Tests/PlotTests/HTMLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,30 @@ final class HTMLTests: XCTestCase {
""")
}

func testCrossoriginLink() {
func testCrossoriginLinkEnabled() {
let html = HTML(.head(.link(
.rel(.preconnect),
.href("https://foo.com"),
.crossorigin()
.crossorigin(true)
)))

assertEqualHTMLContent(html, """
<head><link rel="preconnect" href="https://foo.com" crossorigin/></head>
""")
}

func testCrossoriginLinkDisabled() {
let html = HTML(.head(.link(
.rel(.preconnect),
.href("https://foo.com"),
.crossorigin(false)
)))

assertEqualHTMLContent(html, """
<head><link rel="preconnect" href="https://foo.com"/></head>
""")
}

func testManifestLink() {
let html = HTML(.head(.link(
.rel(.manifest),
Expand Down

0 comments on commit 64d234a

Please sign in to comment.