From 5845fef3814f99bb2c9d5f585c754ed3a01b8cb6 Mon Sep 17 00:00:00 2001 From: Evert van Brussel Date: Mon, 31 Oct 2016 12:55:29 +0100 Subject: [PATCH] cleanup (#7) - `attributes` is no longer an optional dictionary, now it's guaranteed since it was initialized empty - cleaned up code around rendering `children` thank you @Evertt --- Sources/Hypertext.swift | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Sources/Hypertext.swift b/Sources/Hypertext.swift index ddadf06..f9839d3 100644 --- a/Sources/Hypertext.swift +++ b/Sources/Hypertext.swift @@ -52,7 +52,7 @@ open class tag: Renderable { public var name: String? = nil public var isSelfClosing: Bool = false public var children: Renderable? = nil - public var attributes: [String: String]? = [:] + public var attributes: [String: String] = [:] public init(setChildren: (() -> Renderable?)) { self.children = setChildren() @@ -80,7 +80,7 @@ open class tag: Renderable { if isSelfClosing { return "<\(name)\(renderAttributes())/>" } else { - return "<\(name)\(renderAttributes())>\(children != nil ? children!.render() : "")" + return "<\(name)\(renderAttributes())>\(children?.render() ?? "")" } } @@ -101,10 +101,6 @@ open class tag: Renderable { } private func renderAttributes() -> String { - guard let attributes = attributes else { - return "" - } - return attributes.keys.reduce("") { renderedSoFar, attributeKey in return "\(renderedSoFar) \(attributeKey)=\"\(attributes[attributeKey]!)\"" }