Skip to content

Commit

Permalink
[HTMLDocument] Conformed Document to AttributeNode
Browse files Browse the repository at this point in the history
  • Loading branch information
MatsMoll committed Sep 22, 2020
1 parent c4b9749 commit 1a5d872
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Sources/HTMLKit/HTMLDocument.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

public struct Document: HTMLPage {
public struct Document: HTMLPage, AttributeNode {

public enum Types: String {
case html5 = "html"
Expand Down Expand Up @@ -29,15 +29,28 @@ public struct Document: HTMLPage {
let type: Types
let content: HTML

public var attributes: [HTMLAttribute]

public init(type: Types, @HTMLBuilder content: () -> HTML) {
self.type = type
self.content = content()
self.attributes = []
}

init(type: Types, content: HTML, attributes: [HTMLAttribute]) {
self.type = type
self.content = content
self.attributes = attributes
}

public var body: HTML {
[
"<!DOCTYPE \(type.rawValue)>",
HTMLNode { content }
HTMLNode { content }.add(attributes: attributes)
]
}

public func copy(with attributes: [HTMLAttribute]) -> Document {
Document(type: type, content: content, attributes: attributes)
}
}

0 comments on commit 1a5d872

Please sign in to comment.