From 4a3cc18dc3bf9a7cefa0533f52ed22c7106cb068 Mon Sep 17 00:00:00 2001 From: fumoboy007 Date: Sat, 20 Apr 2019 21:28:45 -0700 Subject: [PATCH] Use `XMLNode.Options.nodePrettyPrint` in `generate_appcast` instead of trying to add whitespace manually --- generate_appcast/FeedXML.swift | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/generate_appcast/FeedXML.swift b/generate_appcast/FeedXML.swift index 1691509c..0dc3073b 100644 --- a/generate_appcast/FeedXML.swift +++ b/generate_appcast/FeedXML.swift @@ -23,7 +23,6 @@ func findOrCreateElement(name: String, parent: XMLElement) -> XMLElement { return element; } let element = XMLElement(name: name); - linebreak(parent); parent.addChild(element); return element; } @@ -32,10 +31,6 @@ func text(_ text: String) -> XMLNode { return XMLNode.text(withStringValue: text) as! XMLNode } -func linebreak(_ element: XMLElement) { - element.addChild(text("\n")); -} - func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { let appBaseName = updates[0].appPath.deletingPathExtension().lastPathComponent; @@ -70,9 +65,7 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { channel = channelNodes[0] as! XMLElement; } else { channel = XMLElement(name: "channel"); - linebreak(channel); channel.addChild(XMLElement.element(withName: "title", stringValue: appBaseName) as! XMLElement); - linebreak(root); root.addChild(channel); } @@ -90,18 +83,15 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { if createNewItem { item = XMLElement.element(withName: "item") as! XMLElement; - linebreak(channel); channel.addChild(item); } else { item = existingItems[0] as! XMLElement; } if nil == findElement(name: "title", parent: item) { - linebreak(item); item.addChild(XMLElement.element(withName: "title", stringValue: update.shortVersion) as! XMLElement); } if nil == findElement(name: "pubDate", parent: item) { - linebreak(item); item.addChild(XMLElement.element(withName: "pubDate", stringValue: update.pubDate) as! XMLElement); } @@ -115,7 +105,6 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { var minVer = findElement(name: SUAppcastElementMinimumSystemVersion, parent: item); if nil == minVer { minVer = XMLElement.element(withName: SUAppcastElementMinimumSystemVersion, uri: sparkleNS) as? XMLElement; - linebreak(item); item.addChild(minVer!); } minVer?.setChildren([text(update.minimumSystemVersion)]); @@ -123,17 +112,15 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { let relElement = findElement(name: SUAppcastElementReleaseNotesLink, parent: item); if let url = update.releaseNotesURL { if nil == relElement { - linebreak(item); item.addChild(XMLElement.element(withName: SUAppcastElementReleaseNotesLink, stringValue: url.absoluteString) as! XMLElement); } } else if let childIndex = relElement?.index { item.removeChild(at: childIndex); } - + var enclosure = findElement(name: "enclosure", parent: item); if nil == enclosure { enclosure = XMLElement.element(withName: "enclosure") as? XMLElement; - linebreak(item); item.addChild(enclosure!); } @@ -159,7 +146,6 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { var deltas = findElement(name: SUAppcastElementDeltas, parent: item); if nil == deltas { deltas = XMLElement.element(withName: SUAppcastElementDeltas, uri: sparkleNS) as? XMLElement; - linebreak(item); item.addChild(deltas!); } else { deltas!.setChildren([]); @@ -179,17 +165,12 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { if let sig = delta.dsaSignature { attributes.append(XMLNode.attribute(withName: SUAppcastAttributeDSASignature, uri: sparkleNS, stringValue: sig) as! XMLNode); } - linebreak(deltas!); deltas!.addChild(XMLNode.element(withName: "enclosure", children: nil, attributes: attributes) as! XMLElement); } } - if createNewItem { - linebreak(item); - linebreak(channel); - } } - let options = XMLNode.Options.nodeCompactEmptyElement; + let options: XMLNode.Options = [.nodeCompactEmptyElement, .nodePrettyPrint]; let docData = doc.xmlData(options:options); let _ = try XMLDocument(data: docData, options:XMLNode.Options()); // Verify that it was generated correctly, which does not always happen! try docData.write(to: appcastDestPath);