Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dataich committed Jul 31, 2013
2 parents 34674ad + 3d768bb commit eb56f71
Show file tree
Hide file tree
Showing 24 changed files with 3,708 additions and 1 deletion.
405 changes: 405 additions & 0 deletions LiveDiag.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions LiveDiag.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added LiveDiag/Icon.icns
Binary file not shown.
16 changes: 16 additions & 0 deletions LiveDiag/LDDocument.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// LDDocument.h
// LiveDiag
//
// Created by Taichiro Yoshida on 2013/07/29.
// Copyright (c) 2013 dataich.com. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>

@interface LDDocument : NSDocument <NSTextViewDelegate>
@property (unsafe_unretained) IBOutlet NSTextView *textView;
@property (weak) IBOutlet WebView *webView;

@end
136 changes: 136 additions & 0 deletions LiveDiag/LDDocument.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//
// LDDocument.m
// LiveDiag
//
// Created by Taichiro Yoshida on 2013/07/29.
// Copyright (c) 2013 dataich.com. All rights reserved.
//

#import "LDDocument.h"
#import "NSString+Count.h"
#import <GHMarkdownParser/GHMarkdownParser.h>

@implementation LDDocument

- (id)init
{
self = [super init];
if (self) {
}
return self;
}

- (NSString *)windowNibName
{
return @"LDDocument";
}

- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
self.textView.font = [NSFont userFixedPitchFontOfSize:12];

NSURL *fileURL = [self fileURL];
if (!fileURL) {
return;
}

NSString *markdown = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:fileURL] encoding:NSUTF8StringEncoding];
if (!markdown) {
return;
}

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

+ (BOOL)autosavesInPlace
{
return YES;
}

- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
NSString *markdown = [self.textView string];
NSData *data = [markdown dataUsingEncoding:NSUTF8StringEncoding];
return data;
}

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
if (outError != NULL ) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
}
return TRUE;
}

- (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)printSettings error:(NSError *__autoreleasing *)outError
{
NSView *view = [[[self.webView mainFrame] frameView] documentView];
NSPrintOperation *operation = [NSPrintOperation printOperationWithView:view printInfo:[self printInfo]];
return operation;
}

-(void)textDidChange:(NSNotification *)notification
{
[self textViewContentToWebView];
}

-(void)textViewContentToWebView
{
NSString *markDown = [self.textView.textStorage string];

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

NSString *diag = [markDown substringWithRange:match.range];
diag = [diag stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]; //convert " to ' for parse diag

// task to execute blockdiag
NSTask *echo = [[NSTask alloc] init];
[echo setLaunchPath:@"/bin/bash"];

NSString *command = [markDown substringWithRange:[match rangeAtIndex:1]];
NSLog(@"%@", command);
if(!command || [command isEqualToString:@""]) {
command = @"blockdiag";
}

//don't want to use image cache, so create filename by arc4random
NSString *outPath = [NSString stringWithFormat:@"%@%u.png", NSTemporaryDirectory(), arc4random()];

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

[echo launch];

int pid = echo.processIdentifier;

// temporarily, convert diag part to <img id='{process identifier}' prepareSrc='{file path}'>
NSString *imgTag = [NSString stringWithFormat:@"<img id='%d' prepareSrc='%@'>", pid, outPath];
markDown = [markDown stringByReplacingCharactersInRange:match.range withString:imgTag];

__block __weak LDDocument *weakSelf = self;
// after task terminated, add 'src' attribute to <img> from 'prapareSrc' attribute using jQuery
// to pinpoint a <img>, use process identifier
echo.terminationHandler = ^(NSTask *task) {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *script = [NSString stringWithFormat:@"$('#%d').attr('src', $('#%d').attr('prepareSrc'));", pid, pid];
[weakSelf.webView stringByEvaluatingJavaScriptFromString:script];
});
};
};
}

NSString *html = markDown.flavoredHTMLStringFromMarkdown;
html = [NSString stringWithFormat:NSLocalizedString(@"%@%@base.html", nil), html];

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

@end
15 changes: 15 additions & 0 deletions LiveDiag/Library/NSString+Count.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// NSString+Count.h
// LiveDiag
//
// Created by Taichiro Yoshida on 2013/07/30.
// Copyright (c) 2013年 dataich.com. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSString (Count)

- (NSUInteger)countOfString:(NSString *)search;

@end
18 changes: 18 additions & 0 deletions LiveDiag/Library/NSString+Count.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// NSString+Count.m
// LiveDiag
//
// Created by Taichiro Yoshida on 2013/07/30.
// Copyright (c) 2013年 dataich.com. All rights reserved.
//

#import "NSString+Count.h"

@implementation NSString (Count)

- (NSUInteger)countOfString:(NSString *)search {
NSUInteger count = [self length] - [[self stringByReplacingOccurrencesOfString:search withString:@""] length];
return count / [search length];
}

@end
57 changes: 57 additions & 0 deletions LiveDiag/LiveDiag-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>md</string>
</array>
<key>CFBundleTypeIconFile</key>
<string></string>
<key>CFBundleTypeName</key>
<string>DocumentType</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>????</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>NSDocumentClass</key>
<string>LDDocument</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>Icon.icns</string>
<key>CFBundleIdentifier</key>
<string>com.dataich.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © dataich.com. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
18 changes: 18 additions & 0 deletions LiveDiag/LiveDiag-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Prefix header for all source files of the 'LiveDiag' target in the 'LiveDiag' project
//

#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif

//When DEBUG=1 NSLog should be enabled
#ifdef DEBUG
#ifndef NSLog
#define NSLog( m, args... ) NSLog( m, ##args )
#endif
#else
#ifndef NSLog
#define NSLog( m, args... )
#endif
#endif
27 changes: 27 additions & 0 deletions LiveDiag/Localizable.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Localizable.strings
LiveBlockdiag

Created by Taichiro Yoshida on 2013/07/25.
Copyright (c) 2013年 Taichiro Yoshida. All rights reserved.
*/

"%@%@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>
</head>
<body>
%@
<script>
$(document).ready(function() {
$('table').addClass('table table-striped table-bordered');
});
</script>
</body>
</html>
";
7 changes: 7 additions & 0 deletions LiveDiag/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
body {
margin: 10px;
}

img {
width: 100%;
}
9 changes: 9 additions & 0 deletions LiveDiag/bootstrap.min.css

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions LiveDiag/en.lproj/Credits.rtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{\rtf1\ansi\ansicpg932\cocoartf1187\cocoasubrtf390
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{\*\listtable{\list\listtemplateid1\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{hyphen\}}{\leveltext\leveltemplateid1\'01\uc0\u8259 ;}{\levelnumbers;}\fi-360\li720\lin720 }{\listname ;}\listid1}}
{\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}}
\paperw11900\paperh16840\vieww9600\viewh8400\viewkind0
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural

\f0\b\fs24 \cf0 Developer:
\b0 \
\
Taichiro Yoshida\
@dataich\
\

\b Licenses:
\b0 \
\

\b blockdiag
\b0 \
\pard\tx220\tx720\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\li720\fi-720\pardirnatural
\ls1\ilvl0\cf0 Copyright 2011 Takeshi KOMIYA\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural
\cf0 \
Licensed under the Apache License, Version 2.0 (the "License");\
you may not use this file except in compliance with the License.\
You may obtain a copy of the License at\
\
http://www.apache.org/licenses/LICENSE-2.0\
\
Unless required by applicable law or agreed to in writing, software\
distributed under the License is distributed on an "AS IS" BASIS,\
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\
See the License for the specific language governing permissions and\
limitations under the License.\
\

\b GHMarkdownParser
\b0 \
Copyright (c) 2011 Oliver Letterer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\
\

\b jQuery
\b0 \
Copyright 2013 jQuery Foundation and other contributors\
http://jquery.com/\
\
Permission is hereby granted, free of charge, to any person obtaining\
a copy of this software and associated documentation files (the\
"Software"), to deal in the Software without restriction, including\
without limitation the rights to use, copy, modify, merge, publish,\
distribute, sublicense, and/or sell copies of the Software, and to\
permit persons to whom the Software is furnished to do so, subject to\
the following conditions:\
\
The above copyright notice and this permission notice shall be\
included in all copies or substantial portions of the Software.\
\
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\
\

\b Bootstrap v3.0.0
\b0 \
Copyright 2013 Twitter, Inc\
Licensed under the Apache License v2.0\
http://www.apache.org/licenses/LICENSE-2.0}
2 changes: 2 additions & 0 deletions LiveDiag/en.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Localized versions of Info.plist keys */

Loading

0 comments on commit eb56f71

Please sign in to comment.