Add OPMLExporter. Fix an invalid OPML bug.

This commit is contained in:
Brent Simmons 2017-12-22 10:28:26 -08:00
parent 8d749caf7a
commit d5a43ecaaf
3 changed files with 55 additions and 1 deletions

View File

@ -18,6 +18,7 @@
842E45E51ED8C6B7000A8B52 /* MainWindowSplitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842E45E41ED8C6B7000A8B52 /* MainWindowSplitView.swift */; }; 842E45E51ED8C6B7000A8B52 /* MainWindowSplitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842E45E41ED8C6B7000A8B52 /* MainWindowSplitView.swift */; };
842E45E71ED8C747000A8B52 /* DB5.plist in Resources */ = {isa = PBXBuildFile; fileRef = 842E45E61ED8C747000A8B52 /* DB5.plist */; }; 842E45E71ED8C747000A8B52 /* DB5.plist in Resources */ = {isa = PBXBuildFile; fileRef = 842E45E61ED8C747000A8B52 /* DB5.plist */; };
84411E711FE5FBFA004B527F /* SmallIconProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84411E701FE5FBFA004B527F /* SmallIconProvider.swift */; }; 84411E711FE5FBFA004B527F /* SmallIconProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84411E701FE5FBFA004B527F /* SmallIconProvider.swift */; };
8444C8F21FED81840051386C /* OPMLExporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8444C8F11FED81840051386C /* OPMLExporter.swift */; };
844B5B591FE9FE4F00C7C76A /* SidebarKeyboardDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844B5B581FE9FE4F00C7C76A /* SidebarKeyboardDelegate.swift */; }; 844B5B591FE9FE4F00C7C76A /* SidebarKeyboardDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844B5B581FE9FE4F00C7C76A /* SidebarKeyboardDelegate.swift */; };
844B5B5B1FEA00FB00C7C76A /* TimelineKeyboardDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844B5B5A1FEA00FB00C7C76A /* TimelineKeyboardDelegate.swift */; }; 844B5B5B1FEA00FB00C7C76A /* TimelineKeyboardDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844B5B5A1FEA00FB00C7C76A /* TimelineKeyboardDelegate.swift */; };
844B5B651FEA11F200C7C76A /* GlobalKeyboardShortcuts.plist in Resources */ = {isa = PBXBuildFile; fileRef = 844B5B641FEA11F200C7C76A /* GlobalKeyboardShortcuts.plist */; }; 844B5B651FEA11F200C7C76A /* GlobalKeyboardShortcuts.plist in Resources */ = {isa = PBXBuildFile; fileRef = 844B5B641FEA11F200C7C76A /* GlobalKeyboardShortcuts.plist */; };
@ -425,6 +426,7 @@
842E45E41ED8C6B7000A8B52 /* MainWindowSplitView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainWindowSplitView.swift; sourceTree = "<group>"; }; 842E45E41ED8C6B7000A8B52 /* MainWindowSplitView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainWindowSplitView.swift; sourceTree = "<group>"; };
842E45E61ED8C747000A8B52 /* DB5.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = DB5.plist; path = Evergreen/Resources/DB5.plist; sourceTree = "<group>"; }; 842E45E61ED8C747000A8B52 /* DB5.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = DB5.plist; path = Evergreen/Resources/DB5.plist; sourceTree = "<group>"; };
84411E701FE5FBFA004B527F /* SmallIconProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmallIconProvider.swift; sourceTree = "<group>"; }; 84411E701FE5FBFA004B527F /* SmallIconProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmallIconProvider.swift; sourceTree = "<group>"; };
8444C8F11FED81840051386C /* OPMLExporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OPMLExporter.swift; sourceTree = "<group>"; };
844B5B581FE9FE4F00C7C76A /* SidebarKeyboardDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarKeyboardDelegate.swift; sourceTree = "<group>"; }; 844B5B581FE9FE4F00C7C76A /* SidebarKeyboardDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarKeyboardDelegate.swift; sourceTree = "<group>"; };
844B5B5A1FEA00FB00C7C76A /* TimelineKeyboardDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineKeyboardDelegate.swift; sourceTree = "<group>"; }; 844B5B5A1FEA00FB00C7C76A /* TimelineKeyboardDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineKeyboardDelegate.swift; sourceTree = "<group>"; };
844B5B641FEA11F200C7C76A /* GlobalKeyboardShortcuts.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = GlobalKeyboardShortcuts.plist; sourceTree = "<group>"; }; 844B5B641FEA11F200C7C76A /* GlobalKeyboardShortcuts.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = GlobalKeyboardShortcuts.plist; sourceTree = "<group>"; };
@ -596,6 +598,14 @@
path = Evergreen/MainWindow; path = Evergreen/MainWindow;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
8444C9011FED81880051386C /* Exporters */ = {
isa = PBXGroup;
children = (
8444C8F11FED81840051386C /* OPMLExporter.swift */,
);
path = Exporters;
sourceTree = "<group>";
};
844B5B6A1FEA224000C7C76A /* Keyboard */ = { 844B5B6A1FEA224000C7C76A /* Keyboard */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -857,6 +867,7 @@
849A978B1ED9EE4D007D329B /* Feed List */, 849A978B1ED9EE4D007D329B /* Feed List */,
849A97901ED9EF65007D329B /* Progress Window */, 849A97901ED9EF65007D329B /* Progress Window */,
84DAEE201F86CAE00058304B /* Importers */, 84DAEE201F86CAE00058304B /* Importers */,
8444C9011FED81880051386C /* Exporters */,
84F2D5341FC22FCB00998D64 /* SmartFeeds */, 84F2D5341FC22FCB00998D64 /* SmartFeeds */,
849A97561ED9EB0D007D329B /* Data */, 849A97561ED9EB0D007D329B /* Data */,
8426119C1FCB6ED40086A189 /* HTMLMetadata */, 8426119C1FCB6ED40086A189 /* HTMLMetadata */,
@ -1401,6 +1412,7 @@
842E45DD1ED8C54B000A8B52 /* Browser.swift in Sources */, 842E45DD1ED8C54B000A8B52 /* Browser.swift in Sources */,
842E45E31ED8C681000A8B52 /* KeyboardDelegateProtocol.swift in Sources */, 842E45E31ED8C681000A8B52 /* KeyboardDelegateProtocol.swift in Sources */,
845F52ED1FB2B9FC00C10BF0 /* FeedPasteboardWriter.swift in Sources */, 845F52ED1FB2B9FC00C10BF0 /* FeedPasteboardWriter.swift in Sources */,
8444C8F21FED81840051386C /* OPMLExporter.swift in Sources */,
849A975E1ED9EB72007D329B /* MainWindowController.swift in Sources */, 849A975E1ED9EB72007D329B /* MainWindowController.swift in Sources */,
842E45E51ED8C6B7000A8B52 /* MainWindowSplitView.swift in Sources */, 842E45E51ED8C6B7000A8B52 /* MainWindowSplitView.swift in Sources */,
84F2D53A1FC2308B00998D64 /* UnreadFeed.swift in Sources */, 84F2D53A1FC2308B00998D64 /* UnreadFeed.swift in Sources */,

View File

@ -388,7 +388,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
let result = panel.runModal() let result = panel.runModal()
if result == NSApplication.ModalResponse.OK, let url = panel.url { if result == NSApplication.ModalResponse.OK, let url = panel.url {
DispatchQueue.main.async { DispatchQueue.main.async {
let opmlString = AccountManager.shared.localAccount.OPMLString(indentLevel: 0) let filename = url.lastPathComponent
let opmlString = OPMLExporter.OPMLString(with: AccountManager.shared.localAccount, title: filename)
do { do {
try opmlString.write(to: url, atomically: true, encoding: String.Encoding.utf8) try opmlString.write(to: url, atomically: true, encoding: String.Encoding.utf8)
} }

View File

@ -0,0 +1,41 @@
//
// OPMLExporter.swift
// Evergreen
//
// Created by Brent Simmons on 12/22/17.
// Copyright © 2017 Ranchero Software. All rights reserved.
//
import Foundation
import Account
import RSCore
struct OPMLExporter {
static func OPMLString(with account: Account, title: String) -> String {
let escapedTitle = title.rs_stringByEscapingSpecialXMLCharacters()
let openingText =
"""
<?xml version="1.0" encoding="UTF-8"?>
<!-- OPML generated by Evergreen -->
<opml version="1.1">
<head>
<title>\(escapedTitle)</title>
</head>
<body>
"""
let middleText = account.OPMLString(indentLevel: 0)
let closingText =
"""
</body>
</opml>
"""
let opml = openingText + middleText + closingText
return opml
}
}