Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.

Commit

Permalink
cleanup (#7)
Browse files Browse the repository at this point in the history
- `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
  • Loading branch information
Evertt authored and sahandnayebaziz committed Oct 31, 2016
1 parent 820c332 commit 5845fef
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Sources/Hypertext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -80,7 +80,7 @@ open class tag: Renderable {
if isSelfClosing {
return "<\(name)\(renderAttributes())/>"
} else {
return "<\(name)\(renderAttributes())>\(children != nil ? children!.render() : "")</\(name)>"
return "<\(name)\(renderAttributes())>\(children?.render() ?? "")</\(name)>"
}
}

Expand All @@ -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]!)\""
}
Expand Down

0 comments on commit 5845fef

Please sign in to comment.