Skip to content

Commit

Permalink
variadic media query functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tib committed Jan 24, 2022
1 parent 9e0c094 commit 9de5853
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Sources/SwiftHtml/Tags/A.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public extension A {
attribute("media", value)
}

func media(_ queries: MediaQuery...) -> Self {
return media(queries)
}

func media(_ queries: [MediaQuery]) -> Self {
return media(queries.map(\.value).joined(separator: " and "))
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftHtml/Tags/Area.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public extension Area {
attribute("media", value)
}

func media(_ queries: MediaQuery...) -> Self {
return media(queries)
}

func media(_ queries: [MediaQuery]) -> Self {
return media(queries.map(\.value).joined(separator: " and "))
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftHtml/Tags/Link.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public extension Link {
attribute("media", value)
}

func media(_ queries: MediaQuery...) -> Self {
return media(queries)
}

func media(_ queries: [MediaQuery]) -> Self {
return media(queries.map(\.value).joined(separator: " and "))
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftHtml/Tags/Meta.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public extension Meta {
func media(_ value: String) -> Self {
attribute("media", value)
}

func media(_ queries: MediaQuery...) -> Self {
return media(queries)
}

func media(_ queries: [MediaQuery]) -> Self {
return media(queries.map(\.value).joined(separator: " and "))
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftHtml/Tags/Source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public extension Source {
attribute("media", value)
}

func media(_ queries: MediaQuery...) -> Self {
return media(queries)
}

func media(_ queries: [MediaQuery]) -> Self {
return media(queries.map(\.value).joined(separator: " and "))
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftHtml/Tags/Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public extension Style {
attribute("media", value)
}

func media(_ queries: MediaQuery...) -> Self {
return media(queries)
}

func media(_ queries: [MediaQuery]) -> Self {
return media(queries.map(\.value).joined(separator: " and "))
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftHtmlTests/Tags/MetaTagTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class MetaTagTests: XCTestCase {
Meta()
.name(.themeColor)
.content("#fff")
.media([.prefersColorScheme(.light)])
.media(.prefersColorScheme(.light))
}
let html = DocumentRenderer(minify: true).render(doc)
XCTAssertEqual(##"<meta name="theme-color" content="#fff" media="(prefers-color-scheme: light)">"##, html)
Expand Down

0 comments on commit 9de5853

Please sign in to comment.