Support publishing posts

Adds a menu option and publishes whatever is in the editor, using the
`writeas` command-line client.
This commit is contained in:
Matt Baer 2017-07-29 13:33:05 -04:00
parent 71a7fa47eb
commit 378d335549
5 changed files with 30 additions and 0 deletions

View File

@ -7,6 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
C98EE9AC1F29532F002F646E /* writeas in Resources */ = {isa = PBXBuildFile; fileRef = C98EE9AB1F29532F002F646E /* writeas */; };
C99B910D1C33841E00A91990 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99B910C1C33841E00A91990 /* AppDelegate.swift */; }; C99B910D1C33841E00A91990 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99B910C1C33841E00A91990 /* AppDelegate.swift */; };
C99B910F1C33841E00A91990 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99B910E1C33841E00A91990 /* ViewController.swift */; }; C99B910F1C33841E00A91990 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99B910E1C33841E00A91990 /* ViewController.swift */; };
C99B91111C33841F00A91990 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C99B91101C33841F00A91990 /* Assets.xcassets */; }; C99B91111C33841F00A91990 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C99B91101C33841F00A91990 /* Assets.xcassets */; };
@ -14,6 +15,7 @@
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
C98EE9AB1F29532F002F646E /* writeas */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = writeas; sourceTree = "<group>"; };
C99B91091C33841E00A91990 /* Write.as.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Write.as.app; sourceTree = BUILT_PRODUCTS_DIR; }; C99B91091C33841E00A91990 /* Write.as.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Write.as.app; sourceTree = BUILT_PRODUCTS_DIR; };
C99B910C1C33841E00A91990 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; C99B910C1C33841E00A91990 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C99B910E1C33841E00A91990 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; }; C99B910E1C33841E00A91990 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
@ -52,6 +54,7 @@
C99B910B1C33841E00A91990 /* writeas */ = { C99B910B1C33841E00A91990 /* writeas */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C98EE9AB1F29532F002F646E /* writeas */,
C99B910C1C33841E00A91990 /* AppDelegate.swift */, C99B910C1C33841E00A91990 /* AppDelegate.swift */,
C99B910E1C33841E00A91990 /* ViewController.swift */, C99B910E1C33841E00A91990 /* ViewController.swift */,
C99B91101C33841F00A91990 /* Assets.xcassets */, C99B91101C33841F00A91990 /* Assets.xcassets */,
@ -122,6 +125,7 @@
isa = PBXResourcesBuildPhase; isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
C98EE9AC1F29532F002F646E /* writeas in Resources */,
C99B91111C33841F00A91990 /* Assets.xcassets in Resources */, C99B91111C33841F00A91990 /* Assets.xcassets in Resources */,
C99B91141C33841F00A91990 /* Main.storyboard in Resources */, C99B91141C33841F00A91990 /* Main.storyboard in Resources */,
); );

View File

@ -42,5 +42,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@IBAction func saveDocument(_ sender: AnyObject) { @IBAction func saveDocument(_ sender: AnyObject) {
vc?.saveDocument() vc?.saveDocument()
} }
@IBAction func publishDoc(_ sender: Any) {
vc?.publish()
}
} }

View File

@ -65,6 +65,15 @@
<action selector="saveDocument:" target="Voe-Tx-rLC" id="6F3-Jk-bXC"/> <action selector="saveDocument:" target="Voe-Tx-rLC" id="6F3-Jk-bXC"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem isSeparatorItem="YES" id="aJh-i4-bef"/>
<menuItem title="Publish" id="Vdf-ed-k4A">
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
<connections>
<action selector="publishDoc:" target="Voe-Tx-rLC" id="krY-d8-wc3"/>
</connections>
</menuItem>
</items> </items>
</menu> </menu>
</menuItem> </menuItem>

View File

@ -87,6 +87,19 @@ class ViewController: NSViewController, NSTextViewDelegate {
} }
} }
func publish() {
saveDocument()
let task = Process()
task.launchPath = Bundle.main.executablePath! + "/../../Resources/writeas"
let pipe = Pipe()
task.standardInput = pipe
task.launch()
let fh: FileHandle = pipe.fileHandleForWriting
fh.write(writerText.textStorage!.string.data(using: .utf8)!)
fh.closeFile()
}
func toggle(isNight: Bool) { func toggle(isNight: Bool) {
let darkBG = NSColor(red:0.13, green:0.13, blue:0.13, alpha:1.0) let darkBG = NSColor(red:0.13, green:0.13, blue:0.13, alpha:1.0)
if isNight { if isNight {

BIN
writeas/writeas Executable file

Binary file not shown.