Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit 26ef245

Browse files
author
Brandon Walkin
committed
Origami 2.2
1 parent 6566c55 commit 26ef245

File tree

137 files changed

+12608
-46
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+12608
-46
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2016-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*
8+
*/
9+
10+
#import <SkankySDK/SkankySDK.h>
11+
12+
@interface DHAppleScriptPatch : QCPatch
13+
{
14+
QCStringPort *inputScript;
15+
QCBooleanPort *inputUpdateSignal;
16+
QCVirtualPort *outputResult;
17+
}
18+
19+
@end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2016-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*
8+
*/
9+
10+
#import "DHAppleScriptPatch.h"
11+
#import "NSAppleScript+FBAdditions.h"
12+
13+
@implementation DHAppleScriptPatch
14+
15+
- (id)initWithIdentifier:(id)identifier {
16+
if (self = [super initWithIdentifier:identifier]) {
17+
18+
}
19+
20+
return self;
21+
}
22+
23+
+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)identifier {
24+
return kQCPatchExecutionModeProvider;
25+
}
26+
27+
+ (BOOL)allowsSubpatchesWithIdentifier:(id)identifier {
28+
return NO;
29+
}
30+
31+
+ (QCPatchTimeMode)timeModeWithIdentifier:(id)identifier {
32+
return kQCPatchTimeModeNone;
33+
}
34+
35+
- (BOOL)execute:(QCOpenGLContext *)context time:(double)time arguments:(NSDictionary *)arguments {
36+
if (!(inputScript.wasUpdated || inputUpdateSignal.wasUpdated)) {
37+
return YES;
38+
}
39+
40+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
41+
NSString *error = nil;
42+
id result = [NSAppleScript runScript:inputScript.stringValue error:&error];
43+
44+
if ([result isKindOfClass:[NSArray class]]) {
45+
result = [[QCStructure alloc] initWithArray:result];
46+
} else if ([result isKindOfClass:[NSDictionary class]]) {
47+
result = [[QCStructure alloc] initWithDictionary:result];
48+
}
49+
50+
outputResult.rawValue = (error) ? error : result;
51+
});
52+
53+
return YES;
54+
}
55+
56+
@end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>nodeAttributes</key>
6+
<dict>
7+
<key>category</key>
8+
<string>Origami</string>
9+
<key>categories</key>
10+
<array>
11+
<string>Origami</string>
12+
</array>
13+
<key>description</key>
14+
<string>Executes an AppleScript.
15+
16+
17+
Origami
18+
http://origami.facebook.com/
19+
20+
Use of this patch is subject to the license found at http://origami.facebook.com/license/
21+
22+
Copyright: (c) 2016, Facebook, Inc. All rights reserved.
23+
24+
Created by: Drew Hamlin</string>
25+
<key>name</key>
26+
<string>AppleScript</string>
27+
</dict>
28+
<key>inputAttributes</key>
29+
<dict>
30+
<key>inputScript</key>
31+
<dict>
32+
<key>description</key>
33+
<string></string>
34+
<key>name</key>
35+
<string>Location</string>
36+
</dict>
37+
<key>inputUpdateSignal</key>
38+
<dict>
39+
<key>description</key>
40+
<string></string>
41+
<key>name</key>
42+
<string>Update Signal</string>
43+
</dict>
44+
</dict>
45+
<key>outputAttributes</key>
46+
<dict>
47+
<key>outputResult</key>
48+
<dict>
49+
<key>description</key>
50+
<string></string>
51+
<key>name</key>
52+
<string>Result</string>
53+
</dict>
54+
</dict>
55+
</dict>
56+
</plist>

Origami Plugin/DHImageAtURLPatch.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2016-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*
8+
*/
9+
10+
#import <Foundation/Foundation.h>
11+
#import <SkankySDK/SkankySDK.h>
12+
13+
@interface DHImageAtURLPatch : QCPatch
14+
{
15+
QCVirtualPort *inputURLOrURLs;
16+
QCBooleanPort *inputUseCache;
17+
QCVirtualPort *outputImageOrStructure;
18+
QCBooleanPort *outputDone;
19+
20+
NSDictionary *_URLs;
21+
NSMutableSet *_stillDownloading;
22+
}
23+
24+
@end

Origami Plugin/DHImageAtURLPatch.m

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Copyright (c) 2016-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*
8+
*/
9+
10+
#import "DHImageAtURLPatch.h"
11+
#import "NSArray+FBAdditions.h"
12+
#import "NSURL+FBAdditions.h"
13+
#import "QCPatch+FBAdditions.h"
14+
#import "NSDocument+FBAdditions.h"
15+
16+
@interface DHImageAtURLPatch (Private)
17+
- (void)_downloadImageAtURL:(NSString *)URL;
18+
- (void)_updateOutputPorts;
19+
@end
20+
21+
@implementation DHImageAtURLPatch
22+
23+
static NSMutableDictionary *_downloadedImages;
24+
25+
- (id)initWithIdentifier:(id)identifier {
26+
if (self = [super initWithIdentifier:identifier]) {
27+
inputUseCache.booleanValue = YES;
28+
_stillDownloading = [[NSMutableSet alloc] init];
29+
if (!_downloadedImages) {
30+
_downloadedImages = [[NSMutableDictionary alloc] init];
31+
}
32+
}
33+
34+
return self;
35+
}
36+
37+
+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)identifier {
38+
return kQCPatchExecutionModeProcessor;
39+
}
40+
41+
+ (BOOL)allowsSubpatchesWithIdentifier:(id)identifier {
42+
return NO;
43+
}
44+
45+
+ (QCPatchTimeMode)timeModeWithIdentifier:(id)identifier {
46+
return kQCPatchTimeModeNone;
47+
}
48+
49+
- (BOOL)execute:(QCOpenGLContext *)context time:(double)time arguments:(NSDictionary *)arguments {
50+
if (!(inputURLOrURLs.wasUpdated || inputUseCache.wasUpdated)) {
51+
return YES;
52+
}
53+
54+
id inputValue = inputURLOrURLs.rawValue;
55+
if ([inputValue isKindOfClass:[NSString class]]) {
56+
_URLs = @{@(0): inputValue};
57+
} else if ([inputValue isKindOfClass:[QCStructure class]]) {
58+
_URLs = [inputValue dictionaryRepresentation];
59+
} else {
60+
_URLs = @{};
61+
}
62+
63+
[_stillDownloading removeAllObjects];
64+
[self _updateOutputPorts];
65+
66+
for (id key in _URLs) {
67+
NSString *URL = _URLs[key];
68+
if (URL && (inputUseCache.booleanValue == NO || _downloadedImages[URL] == nil)) {
69+
[_stillDownloading addObject:URL];
70+
[NSThread detachNewThreadSelector:@selector(_downloadImageAtURL:) toTarget:self withObject:URL];
71+
}
72+
}
73+
74+
return YES;
75+
}
76+
77+
@end
78+
79+
@implementation DHImageAtURLPatch (Private)
80+
81+
- (void)_downloadImageAtURL:(NSString *)URL {
82+
if (!(URL && [URL isKindOfClass:[NSString class]])) {
83+
return;
84+
}
85+
86+
NSImage *image = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithQuartzComposerLocation:URL relativeToDocument:self.fb_document]];
87+
_downloadedImages[URL] = image ? image : [NSNull null];
88+
[_stillDownloading removeObject:URL];
89+
90+
[self performSelectorOnMainThread:@selector(_updateOutputPorts) withObject:nil waitUntilDone:NO];
91+
}
92+
93+
- (void)_updateOutputPorts {
94+
if (_URLs.count == 1) {
95+
id result = _downloadedImages[[_URLs allValues][0]];
96+
outputImageOrStructure.rawValue = (result && result != [NSNull null]) ? result : nil;
97+
outputDone.booleanValue = YES;
98+
return;
99+
}
100+
101+
NSMutableDictionary *images = [[NSMutableDictionary alloc] initWithCapacity:_URLs.count];
102+
if (_downloadedImages.count) {
103+
for (id key in _URLs) {
104+
NSString *URL = _URLs[key];
105+
if (![_stillDownloading containsObject:URL]) {
106+
NSImage *image = _downloadedImages[URL];
107+
if (image) {
108+
images[key] = image;
109+
}
110+
}
111+
}
112+
}
113+
114+
BOOL allKeysAreNumbers = YES;
115+
for (id key in images) {
116+
allKeysAreNumbers &= [key isKindOfClass:[NSNumber class]];
117+
}
118+
119+
QCStructure *outputStructure = nil;
120+
if (images.count) {
121+
if (!allKeysAreNumbers) {
122+
outputStructure = [[QCStructure alloc] initWithDictionary:images];
123+
} else {
124+
NSMutableArray *sortedImages = [[NSMutableArray alloc] initWithCapacity:images.count];
125+
id keysArray = [[images allKeys] sortedArrayUsingAlphabeticalSort];
126+
for (NSNumber *key in keysArray) {
127+
[sortedImages addObject:images[key]];
128+
}
129+
outputStructure = [[QCStructure alloc] initWithArray:sortedImages];
130+
}
131+
}
132+
133+
outputImageOrStructure.rawValue = outputStructure;
134+
outputDone.booleanValue = images.count ? (images.count == _URLs.count) : NO;
135+
}
136+
137+
@end
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>nodeAttributes</key>
6+
<dict>
7+
<key>category</key>
8+
<string>Origami</string>
9+
<key>categories</key>
10+
<array>
11+
<string>Origami</string>
12+
</array>
13+
<key>description</key>
14+
<string>Asynchronously downloads and caches requested images.
15+
16+
If you specify a single URL (a string), the image at that URL will be returned. If you specify multiple URLs (a structure of strings), a structure of images will be returned.
17+
18+
19+
Origami
20+
http://origami.facebook.com/
21+
22+
Use of this patch is subject to the license found at http://origami.facebook.com/license/
23+
24+
Copyright: (c) 2016, Facebook, Inc. All rights reserved.
25+
26+
Created by: Drew Hamlin</string>
27+
<key>name</key>
28+
<string>Image at URL</string>
29+
</dict>
30+
<key>inputAttributes</key>
31+
<dict>
32+
<key>inputURLOrURLs</key>
33+
<dict>
34+
<key>description</key>
35+
<string></string>
36+
<key>name</key>
37+
<string>URL(s)</string>
38+
</dict>
39+
<key>inputUseCache</key>
40+
<dict>
41+
<key>description</key>
42+
<string></string>
43+
<key>name</key>
44+
<string>Use Cache</string>
45+
</dict>
46+
</dict>
47+
<key>outputAttributes</key>
48+
<dict>
49+
<key>outputImageOrStructure</key>
50+
<dict>
51+
<key>description</key>
52+
<string></string>
53+
<key>name</key>
54+
<string>Image(s)</string>
55+
</dict>
56+
<key>outputDone</key>
57+
<dict>
58+
<key>description</key>
59+
<string></string>
60+
<key>name</key>
61+
<string>Done</string>
62+
</dict>
63+
</dict>
64+
</dict>
65+
</plist>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2016-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*
8+
*/
9+
10+
#import <Foundation/Foundation.h>
11+
#import <SkankySDK/SkankySDK.h>
12+
13+
@interface DHImageWithFormattedStrings : QCPatch
14+
{
15+
QCStringPort *inputString;
16+
QCImagePort *outputImage;
17+
QCStringPort *outputUnformattedString;
18+
}
19+
20+
@end

0 commit comments

Comments
 (0)