forked from lukakerr/Pine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to create custom preview plugins
- See Docs/Wiki/Plugins.md for more details - Also created a new preference tab for the preview
- Loading branch information
Showing
14 changed files
with
201 additions
and
24 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Plugins | ||
|
||
Creating a preview plugin is easy. Follow the steps below to get started: | ||
|
||
1. Open the Pine preferences window and select the 'Preview' tab | ||
2. Click 'Reveal Plugins' | ||
|
||
At this point a directory named `Plugins` will appear. This is where all the active plugins are stored. | ||
|
||
Plugins are written in JavaScript and loaded directly into the preview window. | ||
This means you can do almost an manipulation you want to the elements displayed in the preview. | ||
|
||
### An Example | ||
|
||
Lets write a quick plugin to make all header elements appear green in color. | ||
|
||
1. Create a file named `headers.js` and save it in the `Plugins` directory mentioned above | ||
|
||
2. Inside this file, copy and paste the following JavaScript: | ||
|
||
```javascript | ||
var headers = document.querySelectorAll("h1, h2, h3, h4, h5, h6"); | ||
|
||
for (var i = 0; i < headers.length; i++) { | ||
headers[i].style.color = "green"; | ||
} | ||
``` | ||
|
||
What this does it find every `<h..>` element and set its color to green. | ||
|
||
3. Close and re-open Pine, and type `# A Green Heading!` into the editor, you'll now notice | ||
the heading is shown as green in the preview. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "mac", | ||
"filename" : "Preview.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"filename" : "[email protected]", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// SupportDirectory.swift | ||
// Pine | ||
// | ||
// Created by Luka Kerr on 24/3/19. | ||
// Copyright © 2019 Luka Kerr. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum SupportDirectory: String { | ||
case plugins = "Plugins" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// PreviewStackView.swift | ||
// Pine | ||
// | ||
// Created by Luka Kerr on 24/3/19. | ||
// Copyright © 2019 Luka Kerr. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
|
||
class PreviewStackView: NSStackView, PreferenceStackView { | ||
|
||
private func getPluginsArea() -> NSStackView { | ||
let view = PreferencesStackView(name: "Plugins:") | ||
|
||
let revealPluginsButton = PreferencesRoundedButton() | ||
revealPluginsButton.title = "Reveal Plugins" | ||
revealPluginsButton.target = self | ||
revealPluginsButton.action = #selector(revealPlugins) | ||
|
||
view.addPreferences([ | ||
revealPluginsButton | ||
]) | ||
|
||
return view | ||
} | ||
|
||
public func getViews() -> [NSView] { | ||
return [ | ||
getPluginsArea() | ||
] | ||
} | ||
|
||
// MARK: - Plugins preference actions | ||
|
||
@objc func revealPlugins(_ sender: NSButton) { | ||
if let folder = Utils.getApplicationSupportDirectory(for: .plugins) { | ||
NSWorkspace.shared.activateFileViewerSelecting([folder]) | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters