Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dataich committed Apr 11, 2014
2 parents 7d61c53 + 7a4bd7a commit 75fe573
Show file tree
Hide file tree
Showing 8 changed files with 592 additions and 938 deletions.
4 changes: 0 additions & 4 deletions LiveDiag.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
0AEF9BD917A743B600A2A3B1 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0AEF9BD617A743B600A2A3B1 /* Localizable.strings */; };
0AEF9BDA17A743CB00A2A3B1 /* jquery-2.0.3.min.js in Resources */ = {isa = PBXBuildFile; fileRef = 0AEF9BD517A743B600A2A3B1 /* jquery-2.0.3.min.js */; };
0AEF9BE017A751D000A2A3B1 /* application.css in Resources */ = {isa = PBXBuildFile; fileRef = 0AEF9BDF17A751D000A2A3B1 /* application.css */; };
0AEF9BE217A7551000A2A3B1 /* bootstrap.min.css in Resources */ = {isa = PBXBuildFile; fileRef = 0AEF9BE117A7551000A2A3B1 /* bootstrap.min.css */; };
5D8B1745E30A47E6AFF0BD21 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 48907CBA55644CEDBE5D9732 /* libPods.a */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -55,7 +54,6 @@
0AEF9BD517A743B600A2A3B1 /* jquery-2.0.3.min.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = "jquery-2.0.3.min.js"; sourceTree = "<group>"; };
0AEF9BD617A743B600A2A3B1 /* Localizable.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = "<group>"; };
0AEF9BDF17A751D000A2A3B1 /* application.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = application.css; sourceTree = "<group>"; };
0AEF9BE117A7551000A2A3B1 /* bootstrap.min.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = bootstrap.min.css; sourceTree = "<group>"; };
48907CBA55644CEDBE5D9732 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
D27F5829857243A4A4840F75 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -139,7 +137,6 @@
0A11A98917A6B50800E94748 /* LiveDiag-Prefix.pch */,
0A11A98A17A6B50800E94748 /* Credits.rtf */,
0AEF9BD517A743B600A2A3B1 /* jquery-2.0.3.min.js */,
0AEF9BE117A7551000A2A3B1 /* bootstrap.min.css */,
0AEF9BDF17A751D000A2A3B1 /* application.css */,
0AEF9BD617A743B600A2A3B1 /* Localizable.strings */,
0A675C5517A88BBC00EDEB47 /* Icon.icns */,
Expand Down Expand Up @@ -219,7 +216,6 @@
0A11A99517A6B50800E94748 /* MainMenu.xib in Resources */,
0AEF9BD917A743B600A2A3B1 /* Localizable.strings in Resources */,
0AEF9BE017A751D000A2A3B1 /* application.css in Resources */,
0AEF9BE217A7551000A2A3B1 /* bootstrap.min.css in Resources */,
0A675C5617A88BBC00EDEB47 /* Icon.icns in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
87 changes: 79 additions & 8 deletions LiveDiag/LDDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ - (void)windowControllerDidLoadNib:(NSWindowController *)aController
return;
}

[self.textView setString:markdown];
[self.textView setString:[self imagesToDiagramBlocks:markdown]];
[self textViewContentToWebView];
}

Expand All @@ -51,9 +51,60 @@ + (BOOL)autosavesInPlace
return YES;
}

- (NSString *)imagesToDiagramBlocks:(NSString *)text
{
NSMutableString *markdown = [NSMutableString stringWithString:text];

NSRegularExpression *re;
NSError *error;
NSString *template;

//comment in diagram block
re = [NSRegularExpression regularExpressionWithPattern:@"^<!--\n((blockdiag|seqdiag|actdiag|nwdiag|rackdiag|)(\\s|)\\{.*?^\\})\n-->" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionAnchorsMatchLines error:&error];
template = @"$1";
[re replaceMatchesInString:markdown options:0 range:NSMakeRange(0, markdown.length) withTemplate:template];

re = [NSRegularExpression regularExpressionWithPattern:@"\n^!\\[image]\\(diagrams.*?$" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionAnchorsMatchLines error:&error];
template = @"";
[re replaceMatchesInString:markdown options:0 range:NSMakeRange(0, markdown.length) withTemplate:template];

return (NSString *)markdown;
}

- (NSString *)diagramBlocksToImages:(NSString *)text
{
NSMutableString *markdown = [NSMutableString stringWithString:text];

//comment out diagram block and add image syntax
NSError *error;
NSRegularExpression *re;
NSString *template;
re = [NSRegularExpression regularExpressionWithPattern:@"^(blockdiag|seqdiag|actdiag|nwdiag|rackdiag|)(\\s|)\\{.*?^\\}" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionAnchorsMatchLines error:&error];
template = @"<!--\n$0\n-->\n![image](diagrams/0000.svg)";
[re replaceMatchesInString:markdown options:0 range:NSMakeRange(0, markdown.length) withTemplate:template];


//replace diagram filename number
re = [NSRegularExpression regularExpressionWithPattern:@"diagrams\\/(0000).svg" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionAnchorsMatchLines error:&error];
NSArray *matches;
int count = 0;
while([matches = [re matchesInString:markdown options:0 range:NSMakeRange(0, markdown.length)] count] > 0) {
NSTextCheckingResult *match = matches[0];

count = count + 1;
template = [NSString stringWithFormat:@"%04d", count];

[markdown replaceCharactersInRange:[match rangeAtIndex:1] withString:template];
NSLog(@"%@", markdown);
}

return (NSString *)markdown;
}

- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
NSString *markdown = [self.textView string];
NSString *markdown = [self diagramBlocksToImages:[self.textView string]];

NSData *data = [markdown dataUsingEncoding:NSUTF8StringEncoding];
return data;
}
Expand Down Expand Up @@ -81,13 +132,22 @@ -(void)textDidChange:(NSNotification *)notification
-(void)textViewContentToWebView
{
NSString *markDown = [self.textView.textStorage string];
NSURL *currentDirectory;
if(self.fileURL ) {
currentDirectory = [self.fileURL URLByDeletingLastPathComponent];
} else {
currentDirectory = [NSURL URLWithString:NSTemporaryDirectory()];
}

if([markDown countOfString:@"{"] == [markDown countOfString:@"}"]) {
//loop for parts of diag
NSError *error;
NSRegularExpression *re = [NSRegularExpression regularExpressionWithPattern:@"^(blockdiag|seqdiag|actdiag|nwdiag|rackdiag|)(\\s|)\\{.*?^\\}" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionAnchorsMatchLines error:&error];
NSArray *matches;
while ([matches = [re matchesInString:markDown options:0 range:NSMakeRange(0, markDown.length)] count] > 0) {
int count = 0;
while ([matches = [re matchesInString:markDown options:0 range:NSMakeRange(0, markDown.length)]
count] > 0) {

NSTextCheckingResult *match = matches[0];

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

NSString *directory = [NSString stringWithFormat:@"%@/diagrams", currentDirectory.path];

NSFileManager *fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:directory]) {
[fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:NULL];
}
//don't want to use image cache, so create filename by arc4random
NSString *outPath = [NSString stringWithFormat:@"%@%u.png", NSTemporaryDirectory(), arc4random()];
count = count + 1;
NSString *outPath = [NSString stringWithFormat:@"%@/%04d.svg", directory, count];

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

[echo launch];

Expand All @@ -128,12 +195,16 @@ -(void)textViewContentToWebView
};
};
}


NSString *externalFilePath = [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]];
NSString *html = markDown.flavoredHTMLStringFromMarkdown;
html = [NSString stringWithFormat:NSLocalizedString(@"%@%@base.html", nil), html];
html = [NSString stringWithFormat:NSLocalizedString(@"%@%@%@base.html", nil),
externalFilePath,
externalFilePath,
html];

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

@end
2 changes: 1 addition & 1 deletion LiveDiag/LiveDiag-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1.1</string>
<string>1.2.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
7 changes: 3 additions & 4 deletions LiveDiag/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
Copyright (c) 2013年 Taichiro Yoshida. All rights reserved.
*/

"%@%@base.html" = "
"%@%@%@base.html" = "
<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<link rel='stylesheet' href='bootstrap.min.css' type='text/css' />
<link rel='stylesheet' href='application.css' type='text/css' />
<script src='jquery-2.0.3.min.js'></script>
<link rel='stylesheet' href='%@application.css' type='text/css' />
<script src='%@jquery-2.0.3.min.js'></script>
</head>
<body>
%@
Expand Down
Loading

0 comments on commit 75fe573

Please sign in to comment.