Permalink
Browse files

Added Commit model and parser

  • Loading branch information...
1 parent 9e5484e commit 92e377ca3ceb7c712df9c161d98b3a2271be7c2c @dbloete dbloete committed Apr 20, 2009
@@ -27,7 +27,7 @@ - (void)viewDidLoad {
NSString *stylePath = [[NSBundle mainBundle] pathForResource:@"styles" ofType:@"html"];
NSString *style = [NSString stringWithContentsOfFile:stylePath encoding:NSUTF8StringEncoding error:nil];
NSString *html = [NSString stringWithFormat:@"%@%@", style, entry.content];
- [contentView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://github.com/"]];
+ [contentView loadHTMLString:html baseURL:nil];
// Date
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterFullStyle];
@@ -95,7 +95,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:object change:change
#pragma mark UIWebView delegation methods
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
- return YES;
+ return [[[request URL] absoluteString] isEqualToString:@"about:blank"];
}
#pragma mark -
View
@@ -0,0 +1,30 @@
+#import <Foundation/Foundation.h>
+
+
+@interface GHCommit : NSObject {
+ NSString *commitID;
+ NSString *tree;
+ NSString *message;
+ NSURL *commitURL;
+ NSString *authorName;
+ NSString *authorEmail;
+ NSString *committerName;
+ NSString *committerEmail;
+ NSDate *committedDate;
+ NSDate *authoredDate;
+}
+
+@property (nonatomic, retain) NSString *commitID;
+@property (nonatomic, retain) NSString *tree;
+@property (nonatomic, retain) NSString *message;
+@property (nonatomic, retain) NSURL *commitURL;
+@property (nonatomic, retain) NSString *authorName;
+@property (nonatomic, retain) NSString *authorEmail;
+@property (nonatomic, retain) NSString *committerName;
+@property (nonatomic, retain) NSString *committerEmail;
+@property (nonatomic, retain) NSDate *committedDate;
+@property (nonatomic, retain) NSDate *authoredDate;
+
+- (id)initWithCommitID:(NSString *)theCommitID;
+
+@end
View
@@ -0,0 +1,32 @@
+#import "GHCommit.h"
+
+
+@implementation GHCommit
+
+@synthesize commitID, tree, message, commitURL, authorName, authorEmail, committerName, committerEmail, committedDate, authoredDate;
+
+- (id)initWithCommitID:(NSString *)theCommitID {
+ if (self = [super init]) {
+ self.commitID = theCommitID;
+ }
+ return self;
+}
+
+#pragma mark -
+#pragma mark Cleanup
+
+- (void)dealloc {
+ [commitID release];
+ [tree release];
+ [message release];
+ [commitURL release];
+ [authorName release];
+ [authorEmail release];
+ [committerName release];
+ [committerEmail release];
+ [committedDate release];
+ [authoredDate release];
+ [super dealloc];
+}
+
+@end
@@ -0,0 +1,17 @@
+#import <Foundation/Foundation.h>
+
+
+@class GHCommit;
+
+@interface GHCommitsParserDelegate : NSObject {
+ @private
+ id target;
+ SEL selector;
+ NSMutableArray *commits;
+ NSMutableString *currentElementValue;
+ GHCommit *currentCommit;
+}
+
+- (id)initWithTarget:(id)theTarget andSelector:(SEL)theSelector;
+
+@end
@@ -0,0 +1,64 @@
+#import "GHCommitsParserDelegate.h"
+#import "GHCommit.h"
+
+
+@implementation GHCommitsParserDelegate
+
+- (id)initWithTarget:(id)theTarget andSelector:(SEL)theSelector {
+ if (self = [super init]) {
+ commits = [[NSMutableArray alloc] init];
+ target = theTarget;
+ selector = theSelector;
+ }
+ return self;
+}
+
+#pragma mark -
+#pragma mark NSXMLParser delegation methods
+
+- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
+ if ([elementName isEqualToString:@"commit"]) {
+ currentCommit = [[GHCommit alloc] init];
+ }
+}
+
+- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
+ string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ if (!currentElementValue) {
+ currentElementValue = [[NSMutableString alloc] initWithString:string];
+ } else {
+ [currentElementValue appendString:string];
+ }
+}
+
+- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
+ if ([elementName isEqualToString:@"commit"]) {
+ [commits addObject:currentCommit];
+ [currentCommit release];
+ currentCommit = nil;
+ } else if ([elementName isEqualToString:@"message"] || [elementName isEqualToString:@"tree"]) {
+ [currentCommit setValue:currentElementValue forKey:elementName];
+ } else if ([elementName isEqualToString:@"id"]) {
+ currentCommit.commitID = currentElementValue;
+ } else if ([elementName isEqualToString:@"url"]) {
+ currentCommit.commitURL = ([currentElementValue isEqualToString:@""]) ? nil : [NSURL URLWithString:currentElementValue];
+ }
+ [currentElementValue release];
+ currentElementValue = nil;
+}
+
+- (void)parserDidEndDocument:(NSXMLParser *)parser {
+ [target performSelectorOnMainThread:selector withObject:commits waitUntilDone:YES];
+}
+
+#pragma mark -
+#pragma mark Cleanup
+
+- (void)dealloc {
+ [commits release];
+ [currentElementValue release];
+ [currentCommit release];
+ [super dealloc];
+}
+
+@end
@@ -56,6 +56,8 @@
6FB7FEAB0F7E2C8700E8D702 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6FB7FEA90F7E2C8700E8D702 /* MainWindow.xib */; };
6FB7FEEC0F7E31AC00E8D702 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 6FB7FEEA0F7E31AC00E8D702 /* Default.png */; };
6FB7FEED0F7E31AC00E8D702 /* NoConnection.png in Resources */ = {isa = PBXBuildFile; fileRef = 6FB7FEEB0F7E31AC00E8D702 /* NoConnection.png */; };
+ 6FC465120F9D141D003A8E7B /* GHCommitsParserDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FC465110F9D141D003A8E7B /* GHCommitsParserDelegate.m */; };
+ 6FC465170F9D1445003A8E7B /* GHCommit.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FC465160F9D1445003A8E7B /* GHCommit.m */; };
6FC647290F9B165E00FE39F6 /* GHReposParserDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FC647280F9B165E00FE39F6 /* GHReposParserDelegate.m */; };
6FC95F1F0F8905F500FC0968 /* UserViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FC95F1E0F8905F500FC0968 /* UserViewController.m */; };
6FC95F280F8908ED00FC0968 /* UserTableHeadBackground.png in Resources */ = {isa = PBXBuildFile; fileRef = 6FC95F270F8908ED00FC0968 /* UserTableHeadBackground.png */; };
@@ -135,6 +137,10 @@
6FB7FEA90F7E2C8700E8D702 /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = MainWindow.xib; path = IBFiles/MainWindow.xib; sourceTree = "<group>"; };
6FB7FEEA0F7E31AC00E8D702 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Default.png; path = Images/Default.png; sourceTree = "<group>"; };
6FB7FEEB0F7E31AC00E8D702 /* NoConnection.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = NoConnection.png; path = Images/NoConnection.png; sourceTree = "<group>"; };
+ 6FC465100F9D141D003A8E7B /* GHCommitsParserDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHCommitsParserDelegate.h; sourceTree = "<group>"; };
+ 6FC465110F9D141D003A8E7B /* GHCommitsParserDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHCommitsParserDelegate.m; sourceTree = "<group>"; };
+ 6FC465150F9D1445003A8E7B /* GHCommit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHCommit.h; sourceTree = "<group>"; };
+ 6FC465160F9D1445003A8E7B /* GHCommit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHCommit.m; sourceTree = "<group>"; };
6FC647270F9B165E00FE39F6 /* GHReposParserDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHReposParserDelegate.h; sourceTree = "<group>"; };
6FC647280F9B165E00FE39F6 /* GHReposParserDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHReposParserDelegate.m; sourceTree = "<group>"; };
6FC95F1D0F8905F500FC0968 /* UserViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserViewController.h; sourceTree = "<group>"; };
@@ -248,8 +254,12 @@
6F35BD380F88B01900E978CD /* GHUser.m */,
6F35BD520F88B06200E978CD /* GHRepository.h */,
6F35BD530F88B06200E978CD /* GHRepository.m */,
+ 6FC465150F9D1445003A8E7B /* GHCommit.h */,
+ 6FC465160F9D1445003A8E7B /* GHCommit.m */,
6FC647270F9B165E00FE39F6 /* GHReposParserDelegate.h */,
6FC647280F9B165E00FE39F6 /* GHReposParserDelegate.m */,
+ 6FC465100F9D141D003A8E7B /* GHCommitsParserDelegate.h */,
+ 6FC465110F9D141D003A8E7B /* GHCommitsParserDelegate.m */,
6FCAF1640F895756005E1173 /* GravatarLoader.h */,
6FCAF1650F895756005E1173 /* GravatarLoader.m */,
);
@@ -464,6 +474,8 @@
6F72FA880F9B3D750069F092 /* DebugLog.m in Sources */,
6F72FAE80F9B47730069F092 /* FeedEntryDetailsController.m in Sources */,
6F72FB2F0F9B53810069F092 /* GHFeedEntryCell.m in Sources */,
+ 6FC465120F9D141D003A8E7B /* GHCommitsParserDelegate.m in Sources */,
+ 6FC465170F9D1445003A8E7B /* GHCommit.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

0 comments on commit 92e377c

Please sign in to comment.