Skip to content

Commit 75fe573

Browse files
committed
Merge branch 'release/1.2.0'
2 parents 7d61c53 + 7a4bd7a commit 75fe573

File tree

8 files changed

+592
-938
lines changed

8 files changed

+592
-938
lines changed

LiveDiag.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
0AEF9BD917A743B600A2A3B1 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0AEF9BD617A743B600A2A3B1 /* Localizable.strings */; };
2424
0AEF9BDA17A743CB00A2A3B1 /* jquery-2.0.3.min.js in Resources */ = {isa = PBXBuildFile; fileRef = 0AEF9BD517A743B600A2A3B1 /* jquery-2.0.3.min.js */; };
2525
0AEF9BE017A751D000A2A3B1 /* application.css in Resources */ = {isa = PBXBuildFile; fileRef = 0AEF9BDF17A751D000A2A3B1 /* application.css */; };
26-
0AEF9BE217A7551000A2A3B1 /* bootstrap.min.css in Resources */ = {isa = PBXBuildFile; fileRef = 0AEF9BE117A7551000A2A3B1 /* bootstrap.min.css */; };
2726
5D8B1745E30A47E6AFF0BD21 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 48907CBA55644CEDBE5D9732 /* libPods.a */; };
2827
/* End PBXBuildFile section */
2928

@@ -55,7 +54,6 @@
5554
0AEF9BD517A743B600A2A3B1 /* jquery-2.0.3.min.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = "jquery-2.0.3.min.js"; sourceTree = "<group>"; };
5655
0AEF9BD617A743B600A2A3B1 /* Localizable.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
5756
0AEF9BDF17A751D000A2A3B1 /* application.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = application.css; sourceTree = "<group>"; };
58-
0AEF9BE117A7551000A2A3B1 /* bootstrap.min.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = bootstrap.min.css; sourceTree = "<group>"; };
5957
48907CBA55644CEDBE5D9732 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
6058
D27F5829857243A4A4840F75 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; };
6159
/* End PBXFileReference section */
@@ -139,7 +137,6 @@
139137
0A11A98917A6B50800E94748 /* LiveDiag-Prefix.pch */,
140138
0A11A98A17A6B50800E94748 /* Credits.rtf */,
141139
0AEF9BD517A743B600A2A3B1 /* jquery-2.0.3.min.js */,
142-
0AEF9BE117A7551000A2A3B1 /* bootstrap.min.css */,
143140
0AEF9BDF17A751D000A2A3B1 /* application.css */,
144141
0AEF9BD617A743B600A2A3B1 /* Localizable.strings */,
145142
0A675C5517A88BBC00EDEB47 /* Icon.icns */,
@@ -219,7 +216,6 @@
219216
0A11A99517A6B50800E94748 /* MainMenu.xib in Resources */,
220217
0AEF9BD917A743B600A2A3B1 /* Localizable.strings in Resources */,
221218
0AEF9BE017A751D000A2A3B1 /* application.css in Resources */,
222-
0AEF9BE217A7551000A2A3B1 /* bootstrap.min.css in Resources */,
223219
0A675C5617A88BBC00EDEB47 /* Icon.icns in Resources */,
224220
);
225221
runOnlyForDeploymentPostprocessing = 0;

LiveDiag/LDDocument.m

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ - (void)windowControllerDidLoadNib:(NSWindowController *)aController
4242
return;
4343
}
4444

45-
[self.textView setString:markdown];
45+
[self.textView setString:[self imagesToDiagramBlocks:markdown]];
4646
[self textViewContentToWebView];
4747
}
4848

@@ -51,9 +51,60 @@ + (BOOL)autosavesInPlace
5151
return YES;
5252
}
5353

54+
- (NSString *)imagesToDiagramBlocks:(NSString *)text
55+
{
56+
NSMutableString *markdown = [NSMutableString stringWithString:text];
57+
58+
NSRegularExpression *re;
59+
NSError *error;
60+
NSString *template;
61+
62+
//comment in diagram block
63+
re = [NSRegularExpression regularExpressionWithPattern:@"^<!--\n((blockdiag|seqdiag|actdiag|nwdiag|rackdiag|)(\\s|)\\{.*?^\\})\n-->" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionAnchorsMatchLines error:&error];
64+
template = @"$1";
65+
[re replaceMatchesInString:markdown options:0 range:NSMakeRange(0, markdown.length) withTemplate:template];
66+
67+
re = [NSRegularExpression regularExpressionWithPattern:@"\n^!\\[image]\\(diagrams.*?$" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionAnchorsMatchLines error:&error];
68+
template = @"";
69+
[re replaceMatchesInString:markdown options:0 range:NSMakeRange(0, markdown.length) withTemplate:template];
70+
71+
return (NSString *)markdown;
72+
}
73+
74+
- (NSString *)diagramBlocksToImages:(NSString *)text
75+
{
76+
NSMutableString *markdown = [NSMutableString stringWithString:text];
77+
78+
//comment out diagram block and add image syntax
79+
NSError *error;
80+
NSRegularExpression *re;
81+
NSString *template;
82+
re = [NSRegularExpression regularExpressionWithPattern:@"^(blockdiag|seqdiag|actdiag|nwdiag|rackdiag|)(\\s|)\\{.*?^\\}" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionAnchorsMatchLines error:&error];
83+
template = @"<!--\n$0\n-->\n![image](diagrams/0000.svg)";
84+
[re replaceMatchesInString:markdown options:0 range:NSMakeRange(0, markdown.length) withTemplate:template];
85+
86+
87+
//replace diagram filename number
88+
re = [NSRegularExpression regularExpressionWithPattern:@"diagrams\\/(0000).svg" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionAnchorsMatchLines error:&error];
89+
NSArray *matches;
90+
int count = 0;
91+
while([matches = [re matchesInString:markdown options:0 range:NSMakeRange(0, markdown.length)] count] > 0) {
92+
NSTextCheckingResult *match = matches[0];
93+
94+
count = count + 1;
95+
template = [NSString stringWithFormat:@"%04d", count];
96+
97+
[markdown replaceCharactersInRange:[match rangeAtIndex:1] withString:template];
98+
NSLog(@"%@", markdown);
99+
}
100+
101+
return (NSString *)markdown;
102+
}
103+
54104
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
55105
{
56-
NSString *markdown = [self.textView string];
106+
NSString *markdown = [self diagramBlocksToImages:[self.textView string]];
107+
57108
NSData *data = [markdown dataUsingEncoding:NSUTF8StringEncoding];
58109
return data;
59110
}
@@ -81,13 +132,22 @@ -(void)textDidChange:(NSNotification *)notification
81132
-(void)textViewContentToWebView
82133
{
83134
NSString *markDown = [self.textView.textStorage string];
135+
NSURL *currentDirectory;
136+
if(self.fileURL ) {
137+
currentDirectory = [self.fileURL URLByDeletingLastPathComponent];
138+
} else {
139+
currentDirectory = [NSURL URLWithString:NSTemporaryDirectory()];
140+
}
84141

85142
if([markDown countOfString:@"{"] == [markDown countOfString:@"}"]) {
86143
//loop for parts of diag
87144
NSError *error;
88145
NSRegularExpression *re = [NSRegularExpression regularExpressionWithPattern:@"^(blockdiag|seqdiag|actdiag|nwdiag|rackdiag|)(\\s|)\\{.*?^\\}" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionAnchorsMatchLines error:&error];
89146
NSArray *matches;
90-
while ([matches = [re matchesInString:markDown options:0 range:NSMakeRange(0, markDown.length)] count] > 0) {
147+
int count = 0;
148+
while ([matches = [re matchesInString:markDown options:0 range:NSMakeRange(0, markDown.length)]
149+
count] > 0) {
150+
91151
NSTextCheckingResult *match = matches[0];
92152

93153
NSString *diag = [markDown substringWithRange:match.range];
@@ -104,10 +164,17 @@ -(void)textViewContentToWebView
104164
}
105165
command = [LDUtils pathTo:command];
106166

167+
NSString *directory = [NSString stringWithFormat:@"%@/diagrams", currentDirectory.path];
168+
169+
NSFileManager *fileManager = [NSFileManager defaultManager];
170+
if(![fileManager fileExistsAtPath:directory]) {
171+
[fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:NULL];
172+
}
107173
//don't want to use image cache, so create filename by arc4random
108-
NSString *outPath = [NSString stringWithFormat:@"%@%u.png", NSTemporaryDirectory(), arc4random()];
174+
count = count + 1;
175+
NSString *outPath = [NSString stringWithFormat:@"%@/%04d.svg", directory, count];
109176

110-
[echo setArguments:@[@"-c", [NSString stringWithFormat:@"echo \"%@\" | %@ --size=2048x2048 -o %@ /dev/stdin", diag, command, outPath]]];
177+
[echo setArguments:@[@"-c", [NSString stringWithFormat:@"echo \"%@\" | %@ -Tsvg -o %@ /dev/stdin", diag, command, outPath]]];
111178

112179
[echo launch];
113180

@@ -128,12 +195,16 @@ -(void)textViewContentToWebView
128195
};
129196
};
130197
}
131-
198+
199+
NSString *externalFilePath = [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]];
132200
NSString *html = markDown.flavoredHTMLStringFromMarkdown;
133-
html = [NSString stringWithFormat:NSLocalizedString(@"%@%@base.html", nil), html];
201+
html = [NSString stringWithFormat:NSLocalizedString(@"%@%@%@base.html", nil),
202+
externalFilePath,
203+
externalFilePath,
204+
html];
134205

135206
// at this time, <img> has no 'src' attribute
136-
[[self.webView mainFrame] loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];
207+
[[self.webView mainFrame] loadHTMLString:html baseURL:currentDirectory];
137208
}
138209

139210
@end

LiveDiag/LiveDiag-Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<key>CFBundlePackageType</key>
3939
<string>APPL</string>
4040
<key>CFBundleShortVersionString</key>
41-
<string>1.1.1</string>
41+
<string>1.2.0</string>
4242
<key>CFBundleSignature</key>
4343
<string>????</string>
4444
<key>CFBundleVersion</key>

LiveDiag/Localizable.strings

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
Copyright (c) 2013年 Taichiro Yoshida. All rights reserved.
77
*/
88

9-
"%@%@base.html" = "
9+
"%@%@%@base.html" = "
1010
<!DOCTYPE html>
1111
<html>
1212
<head>
1313
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
14-
<link rel='stylesheet' href='bootstrap.min.css' type='text/css' />
15-
<link rel='stylesheet' href='application.css' type='text/css' />
16-
<script src='jquery-2.0.3.min.js'></script>
14+
<link rel='stylesheet' href='%@application.css' type='text/css' />
15+
<script src='%@jquery-2.0.3.min.js'></script>
1716
</head>
1817
<body>
1918
%@

0 commit comments

Comments
 (0)