forked from rentzsch/markdownlive
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW] MarkdownLive: first rough (but working) cut of using discount.
git-svn-id: http://rentzsch.com/svn/trunk/cocoa/MarkdownLive@330 34dae961-d50d-0410-846e-a203d89df655
- Loading branch information
wolf
committed
Sep 26, 2008
1 parent
5100b5c
commit 34197bd
Showing
13 changed files
with
711 additions
and
103 deletions.
There are no files selected for viewing
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,42 @@ | ||
/* | ||
* Copyright (c) 2007-2008 Dave Dribin | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
@interface DDTemporaryDirectory : NSObject | ||
{ | ||
NSString * mFullPath; | ||
} | ||
|
||
|
||
+ (DDTemporaryDirectory *) temporaryDirectory; | ||
|
||
- (id) init; | ||
|
||
- (void) cleanup; | ||
|
||
- (NSString *) fullPath; | ||
|
||
@end |
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,94 @@ | ||
/* | ||
* Copyright (c) 2007-2008 Dave Dribin | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import "DDTemporaryDirectory.h" | ||
#include <unistd.h> | ||
#import "JRLog.h" | ||
|
||
|
||
@implementation DDTemporaryDirectory | ||
|
||
+ (DDTemporaryDirectory *) temporaryDirectory; | ||
{ | ||
return [[[self alloc] init] autorelease]; | ||
} | ||
|
||
- (id) init; | ||
{ | ||
self = [super init]; | ||
if (self == nil) | ||
return nil; | ||
|
||
NSString * tempDir = NSTemporaryDirectory(); | ||
if (tempDir == nil) | ||
tempDir = @"/tmp"; | ||
|
||
NSString * template = [tempDir stringByAppendingPathComponent: @"temp.XXXXXX"]; | ||
JRLogDebug(@"Template: %@", template); | ||
const char * fsTemplate = [template fileSystemRepresentation]; | ||
NSMutableData * bufferData = [NSMutableData dataWithBytes: fsTemplate | ||
length: strlen(fsTemplate)+1]; | ||
char * buffer = [bufferData mutableBytes]; | ||
JRLogDebug(@"FS Template: %s", buffer); | ||
char * result = mkdtemp(buffer); | ||
NSString * temporaryDirectory = [[NSFileManager defaultManager] | ||
stringWithFileSystemRepresentation: buffer | ||
length: strlen(buffer)]; | ||
if (result == NULL) | ||
{ | ||
JRLogWarn(@"Could not create temporary dir: %@, %s", temporaryDirectory, | ||
strerror(errno)); | ||
[self release]; | ||
return nil; | ||
} | ||
|
||
mFullPath = [temporaryDirectory retain]; | ||
|
||
return self; | ||
} | ||
|
||
//=========================================================== | ||
// dealloc | ||
//=========================================================== | ||
- (void) dealloc | ||
{ | ||
[self cleanup]; | ||
[mFullPath release]; | ||
|
||
mFullPath = nil; | ||
[super dealloc]; | ||
} | ||
|
||
- (void) cleanup; | ||
{ | ||
[[NSFileManager defaultManager] removeFileAtPath: mFullPath | ||
handler: nil]; | ||
} | ||
|
||
- (NSString *) fullPath; | ||
{ | ||
return mFullPath; | ||
} | ||
|
||
@end |
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 @@ | ||
/* | ||
* Copyright (c) 2007-2008 Dave Dribin | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class DDTemporaryDirectory; | ||
|
||
@interface DDTemporaryFile : NSObject | ||
{ | ||
DDTemporaryDirectory * mTemporaryDirectory; | ||
NSString * mFullPath; | ||
} | ||
|
||
+ (DDTemporaryFile *) temporaryFileWithName: (NSString *) name; | ||
|
||
- (id) initWithName: (NSString *) name; | ||
|
||
- (void) cleanup; | ||
|
||
- (NSString *) fullPath; | ||
|
||
@end |
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,72 @@ | ||
/* | ||
* Copyright (c) 2007-2008 Dave Dribin | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import "DDTemporaryFile.h" | ||
#import "DDTemporaryDirectory.h" | ||
|
||
@implementation DDTemporaryFile | ||
|
||
+ (DDTemporaryFile *) temporaryFileWithName: (NSString *) name; | ||
{ | ||
return [[[self alloc] initWithName: name] autorelease]; | ||
} | ||
|
||
- (id) initWithName: (NSString *) name; | ||
{ | ||
self = [super init]; | ||
if (self == nil) | ||
return nil; | ||
|
||
mTemporaryDirectory = [[DDTemporaryDirectory alloc] init]; | ||
mFullPath = [[[mTemporaryDirectory fullPath] | ||
stringByAppendingPathComponent: name] retain]; | ||
|
||
return self; | ||
} | ||
|
||
//=========================================================== | ||
// dealloc | ||
//=========================================================== | ||
- (void) dealloc | ||
{ | ||
[self cleanup]; | ||
[mTemporaryDirectory release]; | ||
[mFullPath release]; | ||
|
||
mTemporaryDirectory = nil; | ||
mFullPath = nil; | ||
[super dealloc]; | ||
} | ||
|
||
- (void) cleanup; | ||
{ | ||
[mTemporaryDirectory cleanup]; | ||
} | ||
|
||
- (NSString *) fullPath; | ||
{ | ||
return mFullPath; | ||
} | ||
|
||
@end |
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,99 @@ | ||
/******************************************************************************* | ||
JRLog.h | ||
Copyright (c) 2006-2007 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com> | ||
Some rights reserved: <http://opensource.org/licenses/mit-license.php> | ||
***************************************************************************/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
// What you need to remember: Debug > Info > Warn > Error > Fatal. | ||
|
||
typedef enum { | ||
JRLogLevel_UNSET, | ||
JRLogLevel_Debug, | ||
JRLogLevel_Info, | ||
JRLogLevel_Warn, | ||
JRLogLevel_Error, | ||
JRLogLevel_Fatal, | ||
JRLogLevel_Off, | ||
} JRLogLevel; | ||
|
||
@protocol JRLogLogger | ||
|
||
- (void)logWithLevel:(JRLogLevel)callerLevel_ | ||
instance:(NSString*)instance_ | ||
file:(const char*)file_ | ||
line:(unsigned)line_ | ||
function:(const char*)function_ | ||
message:(NSString*)message_; | ||
|
||
@end | ||
|
||
@interface NSObject (JRLogAdditions) | ||
+ (JRLogLevel)classJRLogLevel; | ||
+ (void)setClassJRLogLevel:(JRLogLevel)level_; | ||
|
||
+ (JRLogLevel)defaultJRLogLevel; | ||
+ (void)setDefaultJRLogLevel:(JRLogLevel)level_; | ||
|
||
+ (void)setJRLogLogger: (id<JRLogLogger>) logger_; | ||
+ (id<JRLogLogger>)JRLogLogger; | ||
+ (id<JRLogLogger>)defaultJRLogLogger; | ||
@end | ||
|
||
BOOL IsJRLogLevelActive(id self_, JRLogLevel level_); | ||
void JRLog(id self_, JRLogLevel level_, unsigned line_, const char *file_, const char *function_, NSString *format_, ...); | ||
|
||
#define JRLOG_CONDITIONALLY(sender,LEVEL,format,...) \ | ||
do{if(IsJRLogLevelActive(sender,LEVEL)){JRLog(sender,LEVEL,__LINE__,__FILE__,__PRETTY_FUNCTION__,(format),##__VA_ARGS__);}}while(0) | ||
|
||
#if JRLogOverrideNSLog | ||
id self; | ||
#define NSLog JRLogInfo | ||
#endif | ||
|
||
// | ||
// Scary macros! | ||
// The 1st #if is a filter, which you can read "IF any of the symbols are defined, THEN don't log for that level, ELSE log for that level." | ||
// | ||
|
||
#if defined(JRLOGLEVEL_OFF) || defined(JRLOGLEVEL_FATAL) || defined(JRLOGLEVEL_ERROR) || defined(JRLOGLEVEL_WARN) || defined(JRLOGLEVEL_INFO) | ||
#define JRLogDebug(format,...) | ||
#define JRCLogDebug(format,...) | ||
#else | ||
#define JRLogDebug(format,...) JRLOG_CONDITIONALLY(self, JRLogLevel_Debug, format, ##__VA_ARGS__) | ||
#define JRCLogDebug(format,...) JRLOG_CONDITIONALLY(nil, JRLogLevel_Debug, format, ##__VA_ARGS__) | ||
#endif | ||
|
||
#if defined(JRLOGLEVEL_OFF) || defined(JRLOGLEVEL_FATAL) || defined(JRLOGLEVEL_ERROR) || defined(JRLOGLEVEL_WARN) | ||
#define JRLogInfo(format,...) | ||
#define JRCLogInfo(format,...) | ||
#else | ||
#define JRLogInfo(format,...) JRLOG_CONDITIONALLY(self, JRLogLevel_Info, format, ##__VA_ARGS__) | ||
#define JRCLogInfo(format,...) JRLOG_CONDITIONALLY(nil, JRLogLevel_Info, format, ##__VA_ARGS__) | ||
#endif | ||
|
||
#if defined(JRLOGLEVEL_OFF) || defined(JRLOGLEVEL_FATAL) || defined(JRLOGLEVEL_ERROR) | ||
#define JRLogWarn(format,...) | ||
#define JRCLogWarn(format,...) | ||
#else | ||
#define JRLogWarn(format,...) JRLOG_CONDITIONALLY(self, JRLogLevel_Warn, format, ##__VA_ARGS__) | ||
#define JRCLogWarn(format,...) JRLOG_CONDITIONALLY(nil, JRLogLevel_Warn, format, ##__VA_ARGS__) | ||
#endif | ||
|
||
#if defined(JRLOGLEVEL_OFF) || defined(JRLOGLEVEL_FATAL) | ||
#define JRLogError(format,...) | ||
#define JRCLogError(format,...) | ||
#else | ||
#define JRLogError(format,...) JRLOG_CONDITIONALLY(self, JRLogLevel_Error, format, ##__VA_ARGS__) | ||
#define JRCLogError(format,...) JRLOG_CONDITIONALLY(nil, JRLogLevel_Error, format, ##__VA_ARGS__) | ||
#endif | ||
|
||
#if defined(JRLOGLEVEL_OFF) | ||
#define JRLogFatal(format,...) | ||
#define JRCLogFatal(format,...) | ||
#else | ||
#define JRLogFatal(format,...) JRLOG_CONDITIONALLY(self, JRLogLevel_Fatal, format, ##__VA_ARGS__) | ||
#define JCRLogFatal(format,...) JRLOG_CONDITIONALLY(nil, JRLogLevel_Fatal, format, ##__VA_ARGS__) | ||
#endif |
Oops, something went wrong.