Original webview for ios redesigned. New icons.

This commit is contained in:
Samuel Clay 2013-03-04 15:09:09 -08:00
parent 59332ce127
commit 9dbc5154a5
37 changed files with 3246 additions and 349 deletions

View file

@ -4248,7 +4248,7 @@ form.opml_import_form input {
margin: 11px 0 0 4px;
width: 16px;
height: 16px;
background: transparent url('/media/embed/icons/circular/g_icn_folder.png') no-repeat 0 0;
background: transparent url('/media/embed/icons/circular/g_icn_folder_add.png') no-repeat 0 0;
background-size: 16px;
cursor: pointer;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

View file

@ -47,6 +47,7 @@
- (IBAction)checkSiteAddress;
- (void)reloadSearchResults;
- (IBAction)toggleAddFolder:(id)sender;
- (NSArray *)folders;
@property (nonatomic) IBOutlet NewsBlurAppDelegate *appDelegate;
@property (nonatomic) IBOutlet UITextField *inFolderInput;

View file

@ -354,13 +354,21 @@
#pragma mark -
#pragma mark Folder Picker
- (NSArray *)folders {
return _.without([appDelegate dictFoldersArray],
@[@"saved_stories",
@"river_blurblogs",
@"river_global",
@"everything"]);
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component {
return [[appDelegate dictFoldersArray] count] - 2;
return [[self folders] count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView
@ -369,7 +377,7 @@ numberOfRowsInComponent:(NSInteger)component {
if (row == 0) {
return @"— Top Level —";
} else {
return [[appDelegate dictFoldersArray] objectAtIndex:row + 2];
return [[self folders] objectAtIndex:row];
}
}
@ -380,7 +388,7 @@ numberOfRowsInComponent:(NSInteger)component {
if (row == 0) {
folder_title = @"— Top Level —";
} else {
folder_title = [[appDelegate dictFoldersArray] objectAtIndex:row + 2];
folder_title = [[self folders] objectAtIndex:row];
}
[inFolderInput setText:folder_title];
}

View file

@ -241,6 +241,7 @@
if ([folder isEqualToString:@"everything"]) continue;
if ([folder isEqualToString:@"river_blurblogs"]) continue;
if ([folder isEqualToString:@"river_global"]) continue;
if ([folder isEqualToString:@"saved_stories"]) continue;
if ([[folder trim] isEqualToString:@""]) continue;
if (appDelegate.isRiverView) {
if (![folder containsString:appDelegate.activeFolder]) {

View file

@ -463,7 +463,7 @@
self.storyPageControl.nextPage.webView.hidden = YES;
self.storyPageControl.bottomPlaceholderToolbar.hidden = NO;
self.storyPageControl.progressViewContainer.hidden = YES;
self.storyPageControl.navigationItem.rightBarButtonItems = nil;
// self.storyPageControl.navigationItem.rightBarButtonItems = nil;
[self.storyPageControl resetPages];
int unreadCount = appDelegate.unreadCount;
if (unreadCount == 0) {

View file

@ -761,10 +761,8 @@
[feedDetailViewController.navigationItem setBackBarButtonItem: newBackButton];
UINavigationController *navController = self.navigationController;
[navController pushViewController:storyPageControl animated:YES];
//self.storyDetailViewController.navigationItem.titleView = nil;
[navController.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:feedTitle style:UIBarButtonItemStyleBordered target:nil action:nil]];
navController.navigationItem.hidesBackButton = YES;
// navController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.9];
}
}

View file

@ -159,6 +159,8 @@ static const CGFloat kFolderTitleHeight = 28;
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:i1
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTintColor:UIColorFromRGB(0x404040)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:i2
forState:UIControlStateNormal
@ -194,21 +196,28 @@ static const CGFloat kFolderTitleHeight = 28;
forState:UIControlStateHighlighted
barMetrics:UIBarMetricsLandscapePhone];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
[[UIBarButtonItem appearance]
setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
UIColorFromRGB(0x404040), UITextAttributeTextColor,
UIColorFromRGB(0xFAFAFA), UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
nil]
forState:UIControlStateNormal];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
[[UIBarButtonItem appearance]
setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
UIColorFromRGB(0xF0F0F0), UITextAttributeTextColor,
UIColorFromRGB(0x202020), UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
nil]
forState:UIControlStateHighlighted|UIControlStateSelected];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
forState:UIControlStateSelected];
[[UIBarButtonItem appearance]
setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
UIColorFromRGB(0xF0F0F0), UITextAttributeTextColor,
UIColorFromRGB(0x202020), UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
nil]
forState:UIControlStateHighlighted];
[[UIBarButtonItem appearance]
setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
UIColorFromRGB(0xB0B0B0), UITextAttributeTextColor,
UIColorFromRGB(0xFAFAFA), UITextAttributeTextShadowColor,

View file

@ -47,9 +47,13 @@ static const CGFloat kButtonWidth = 48.0f;
@property (nonatomic) IBOutlet UITextField *pageUrl;
@property (nonatomic) IBOutlet UIToolbar *toolbar;
- (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
- (IBAction) doCloseOriginalStoryViewController;
- (IBAction) doOpenActionSheet;
- (IBAction)loadAddress:(id)sender;
- (IBAction)webViewGoBack:(id)sender;
- (IBAction)webViewGoForward:(id)sender;
- (IBAction)webViewRefresh:(id)sender;
- (void)updateTitle:(UIWebView*)aWebView;
- (void)updateAddress:(NSURLRequest*)request;
- (void)updateButtons;

View file

@ -12,6 +12,7 @@
#import "TransparentToolbar.h"
#import "SHK.h"
#import "MBProgressHUD.h"
#import "UIBarButtonItem+Image.h"
@implementation OriginalStoryViewController
@ -36,7 +37,6 @@
- (void)viewWillAppear:(BOOL)animated {
// NSLog(@"Original Story View: %@", [appDelegate activeOriginalStoryURL]);
toolbar.tintColor = UIColorFromRGB(0x183353);
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:appDelegate.activeOriginalStoryURL] ;
[self updateAddress:request];
[self.pageTitle setText:[[appDelegate activeStory] objectForKey:@"story_title"]];
@ -57,11 +57,19 @@
return YES;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self layoutForInterfaceOrientation:toInterfaceOrientation];
}
- (void)viewDidLoad {
CGRect navBarFrame = self.view.bounds;
navBarFrame.size.height = kNavBarHeight;
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:navBarFrame];
navBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
toolbar.autoresizingMask = toolbar.autoresizingMask | UIViewAutoresizingFlexibleHeight | UIViewContentModeBottom;
[navBar
setBackgroundImage:[UIImage imageNamed:@"toolbar_tall_background.png"]
forBarMetrics:UIBarMetricsDefault];
CGRect labelFrame = CGRectMake(kMargin, kSpacer,
navBar.bounds.size.width - 2*kMargin,
@ -70,9 +78,9 @@
label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:12];
label.textColor = [UIColor colorWithRed:0.97f green:0.98f blue:0.99 alpha:0.95];
label.shadowColor = [UIColor colorWithRed:0.06f green:0.12f blue:0.16f alpha:0.4f];
label.shadowOffset = CGSizeMake(0.0f, 1.0f);
label.textColor = UIColorFromRGB(0x404040);
label.shadowColor = UIColorFromRGB(0xFAFAFA);
label.shadowOffset = CGSizeMake(0.0f, -1.0f);
label.textAlignment = UITextAlignmentCenter;
label.text = [[appDelegate activeStory] objectForKey:@"story_title"];
[navBar addSubview:label];
@ -119,18 +127,66 @@
[self.view addSubview:navBar];
CGRect webViewFrame = CGRectMake(0,
UIImage *backImage = [UIImage imageNamed:@"barbutton_back.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.bounds = CGRectMake(0, 0, 44, 44);
[backButton setImage:backImage forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(webViewGoBack:) forControlEvents:UIControlEventTouchUpInside];
[back setCustomView:backButton];
UIImage *forwardImage = [UIImage imageNamed:@"barbutton_forward.png"];
UIButton *forwardButton = [UIButton buttonWithType:UIButtonTypeCustom];
forwardButton.bounds = CGRectMake(0, 0, 44, 44);
[forwardButton setImage:forwardImage forState:UIControlStateNormal];
[forwardButton addTarget:self action:@selector(webViewGoForward:) forControlEvents:UIControlEventTouchUpInside];
[forward setCustomView:forwardButton];
UIImage *refreshImage = [UIImage imageNamed:@"barbutton_refresh.png"];
UIButton *refreshButton = [UIButton buttonWithType:UIButtonTypeCustom];
refreshButton.bounds = CGRectMake(0, 0, 44, 44);
[refreshButton setImage:refreshImage forState:UIControlStateNormal];
[refreshButton addTarget:self action:@selector(webViewRefresh:) forControlEvents:UIControlEventTouchUpInside];
[refresh setCustomView:refreshButton];
UIImage *sendtoImage = [UIImage imageNamed:@"barbutton_sendto.png"];
UIButton *sendtoButton = [UIButton buttonWithType:UIButtonTypeCustom];
sendtoButton.bounds = CGRectMake(0, 0, 44, 44);
[sendtoButton setImage:sendtoImage forState:UIControlStateNormal];
[sendtoButton addTarget:self action:@selector(doOpenActionSheet) forControlEvents:UIControlEventTouchUpInside];
[pageAction setCustomView:sendtoButton];
CGRect webViewFrame = CGRectMake(0,
navBarFrame.origin.y +
navBarFrame.size.height,
self.view.frame.size.width,
self.view.frame.size.height - kNavBarHeight - 44);
self.webView.frame = webViewFrame;
navBar.tintColor = UIColorFromRGB(0x183353);
}
- (IBAction)webViewGoBack:(id)sender {
[webView goBack];
}
- (IBAction)webViewGoForward:(id)sender {
[webView goForward];
}
- (IBAction)webViewRefresh:(id)sender {
[webView reload];
}
- (void) layoutForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
CGSize toolbarSize = [self.toolbar sizeThatFits:self.view.bounds.size];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.toolbar.frame = CGRectMake(-10.0f,
CGRectGetHeight(self.view.bounds) - toolbarSize.height,
toolbarSize.width + 20, toolbarSize.height);
} else {
self.toolbar.frame = (CGRect){CGPointMake(0.f, CGRectGetHeight(self.view.bounds) -
toolbarSize.height), toolbarSize};
self.webView.frame = (CGRect){CGPointMake(0, kNavBarHeight), CGSizeMake(CGRectGetWidth(self.view.bounds), CGRectGetMinY(self.toolbar.frame) - kNavBarHeight)};
}
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {

View file

@ -851,7 +851,7 @@
- (IBAction)toggleFontSize:(id)sender {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[appDelegate.masterContainerViewController showFontSettingsPopover:sender];
[appDelegate.masterContainerViewController showFontSettingsPopover:self.fontSettingsButton];
} else {
if (self.popoverController == nil) {
self.popoverController = [[WEPopoverController alloc]

View file

@ -205,6 +205,21 @@
FF22FE4E16E41EB40046165A /* disclosure_down.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE4C16E41EB40046165A /* disclosure_down.png */; };
FF22FE4F16E41EB40046165A /* disclosure_down@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE4D16E41EB40046165A /* disclosure_down@2x.png */; };
FF22FE5116E42C600046165A /* world@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE5016E42C600046165A /* world@2x.png */; };
FF22FE5E16E53ADC0046165A /* Underscore+Functional.m in Sources */ = {isa = PBXBuildFile; fileRef = FF22FE5516E53ADC0046165A /* Underscore+Functional.m */; };
FF22FE5F16E53ADC0046165A /* Underscore.m in Sources */ = {isa = PBXBuildFile; fileRef = FF22FE5816E53ADC0046165A /* Underscore.m */; };
FF22FE6016E53ADC0046165A /* USArrayWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = FF22FE5A16E53ADC0046165A /* USArrayWrapper.m */; };
FF22FE6116E53ADC0046165A /* USDictionaryWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = FF22FE5D16E53ADC0046165A /* USDictionaryWrapper.m */; };
FF22FE6316E54B350046165A /* g_icn_folder_add.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE6216E54B350046165A /* g_icn_folder_add.png */; };
FF22FE6616E54E590046165A /* barbutton_back.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE6416E54E590046165A /* barbutton_back.png */; };
FF22FE6716E54E590046165A /* barbutton_back@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE6516E54E590046165A /* barbutton_back@2x.png */; };
FF22FE6A16E54F590046165A /* barbutton_forward.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE6816E54F590046165A /* barbutton_forward.png */; };
FF22FE6B16E54F590046165A /* barbutton_forward@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE6916E54F590046165A /* barbutton_forward@2x.png */; };
FF22FE6E16E554540046165A /* barbutton_refresh.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE6C16E554540046165A /* barbutton_refresh.png */; };
FF22FE6F16E554540046165A /* barbutton_refresh@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE6D16E554540046165A /* barbutton_refresh@2x.png */; };
FF22FE7216E554FD0046165A /* barbutton_sendto.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE7016E554FD0046165A /* barbutton_sendto.png */; };
FF22FE7316E554FD0046165A /* barbutton_sendto@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE7116E554FD0046165A /* barbutton_sendto@2x.png */; };
FF22FE7616E557D80046165A /* toolbar_tall_background.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE7416E557D80046165A /* toolbar_tall_background.png */; };
FF22FE7716E557D80046165A /* toolbar_tall_background@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FF22FE7516E557D80046165A /* toolbar_tall_background@2x.png */; };
FF29708B16DD7AA400E92F85 /* segment_active.png in Resources */ = {isa = PBXBuildFile; fileRef = FF29708916DD7AA400E92F85 /* segment_active.png */; };
FF29708C16DD7AA400E92F85 /* segment_inactive.png in Resources */ = {isa = PBXBuildFile; fileRef = FF29708A16DD7AA400E92F85 /* segment_inactive.png */; };
FF29708E16DD7C8A00E92F85 /* segment_left_selected.png in Resources */ = {isa = PBXBuildFile; fileRef = FF29708D16DD7C8A00E92F85 /* segment_left_selected.png */; };
@ -650,6 +665,27 @@
FF22FE4C16E41EB40046165A /* disclosure_down.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = disclosure_down.png; sourceTree = "<group>"; };
FF22FE4D16E41EB40046165A /* disclosure_down@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "disclosure_down@2x.png"; sourceTree = "<group>"; };
FF22FE5016E42C600046165A /* world@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "world@2x.png"; sourceTree = "<group>"; };
FF22FE5416E53ADC0046165A /* Underscore+Functional.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Underscore+Functional.h"; sourceTree = "<group>"; };
FF22FE5516E53ADC0046165A /* Underscore+Functional.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Underscore+Functional.m"; sourceTree = "<group>"; };
FF22FE5616E53ADC0046165A /* Underscore-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Underscore-Prefix.pch"; sourceTree = "<group>"; };
FF22FE5716E53ADC0046165A /* Underscore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Underscore.h; sourceTree = "<group>"; };
FF22FE5816E53ADC0046165A /* Underscore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Underscore.m; sourceTree = "<group>"; };
FF22FE5916E53ADC0046165A /* USArrayWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = USArrayWrapper.h; sourceTree = "<group>"; };
FF22FE5A16E53ADC0046165A /* USArrayWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = USArrayWrapper.m; sourceTree = "<group>"; };
FF22FE5B16E53ADC0046165A /* USConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = USConstants.h; sourceTree = "<group>"; };
FF22FE5C16E53ADC0046165A /* USDictionaryWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = USDictionaryWrapper.h; sourceTree = "<group>"; };
FF22FE5D16E53ADC0046165A /* USDictionaryWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = USDictionaryWrapper.m; sourceTree = "<group>"; };
FF22FE6216E54B350046165A /* g_icn_folder_add.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = g_icn_folder_add.png; sourceTree = "<group>"; };
FF22FE6416E54E590046165A /* barbutton_back.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = barbutton_back.png; sourceTree = "<group>"; };
FF22FE6516E54E590046165A /* barbutton_back@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "barbutton_back@2x.png"; sourceTree = "<group>"; };
FF22FE6816E54F590046165A /* barbutton_forward.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = barbutton_forward.png; sourceTree = "<group>"; };
FF22FE6916E54F590046165A /* barbutton_forward@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "barbutton_forward@2x.png"; sourceTree = "<group>"; };
FF22FE6C16E554540046165A /* barbutton_refresh.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = barbutton_refresh.png; sourceTree = "<group>"; };
FF22FE6D16E554540046165A /* barbutton_refresh@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "barbutton_refresh@2x.png"; sourceTree = "<group>"; };
FF22FE7016E554FD0046165A /* barbutton_sendto.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = barbutton_sendto.png; sourceTree = "<group>"; };
FF22FE7116E554FD0046165A /* barbutton_sendto@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "barbutton_sendto@2x.png"; sourceTree = "<group>"; };
FF22FE7416E557D80046165A /* toolbar_tall_background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = toolbar_tall_background.png; sourceTree = "<group>"; };
FF22FE7516E557D80046165A /* toolbar_tall_background@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "toolbar_tall_background@2x.png"; sourceTree = "<group>"; };
FF29708916DD7AA400E92F85 /* segment_active.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = segment_active.png; sourceTree = "<group>"; };
FF29708A16DD7AA400E92F85 /* segment_inactive.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = segment_inactive.png; sourceTree = "<group>"; };
FF29708D16DD7C8A00E92F85 /* segment_left_selected.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = segment_left_selected.png; sourceTree = "<group>"; };
@ -960,6 +996,7 @@
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
FF22FE5316E53ADC0046165A /* Underscore */,
43A4BABE15C8663600F3B8D4 /* Popover */,
43A3912E15B73A7B0074B212 /* AFNetworking */,
43F6A7A215B0E1A40092EE91 /* NSAttributedString+Attributes.h */,
@ -1142,6 +1179,17 @@
431B857615A132B600DCE497 /* Images */ = {
isa = PBXGroup;
children = (
FF22FE7416E557D80046165A /* toolbar_tall_background.png */,
FF22FE7516E557D80046165A /* toolbar_tall_background@2x.png */,
FF22FE7016E554FD0046165A /* barbutton_sendto.png */,
FF22FE7116E554FD0046165A /* barbutton_sendto@2x.png */,
FF22FE6C16E554540046165A /* barbutton_refresh.png */,
FF22FE6D16E554540046165A /* barbutton_refresh@2x.png */,
FF22FE6816E54F590046165A /* barbutton_forward.png */,
FF22FE6916E54F590046165A /* barbutton_forward@2x.png */,
FF22FE6416E54E590046165A /* barbutton_back.png */,
FF22FE6516E54E590046165A /* barbutton_back@2x.png */,
FF22FE6216E54B350046165A /* g_icn_folder_add.png */,
FF22FE5016E42C600046165A /* world@2x.png */,
FF22FE4416E410A60046165A /* folder_collapse.png */,
FF22FE4516E410A60046165A /* folder_expand.png */,
@ -1512,6 +1560,23 @@
name = Foundation;
sourceTree = "<group>";
};
FF22FE5316E53ADC0046165A /* Underscore */ = {
isa = PBXGroup;
children = (
FF22FE5416E53ADC0046165A /* Underscore+Functional.h */,
FF22FE5516E53ADC0046165A /* Underscore+Functional.m */,
FF22FE5616E53ADC0046165A /* Underscore-Prefix.pch */,
FF22FE5716E53ADC0046165A /* Underscore.h */,
FF22FE5816E53ADC0046165A /* Underscore.m */,
FF22FE5916E53ADC0046165A /* USArrayWrapper.h */,
FF22FE5A16E53ADC0046165A /* USArrayWrapper.m */,
FF22FE5B16E53ADC0046165A /* USConstants.h */,
FF22FE5C16E53ADC0046165A /* USDictionaryWrapper.h */,
FF22FE5D16E53ADC0046165A /* USDictionaryWrapper.m */,
);
path = Underscore;
sourceTree = "<group>";
};
FF29708816DD7AA400E92F85 /* segmented */ = {
isa = PBXGroup;
children = (
@ -2134,6 +2199,17 @@
FF22FE4E16E41EB40046165A /* disclosure_down.png in Resources */,
FF22FE4F16E41EB40046165A /* disclosure_down@2x.png in Resources */,
FF22FE5116E42C600046165A /* world@2x.png in Resources */,
FF22FE6316E54B350046165A /* g_icn_folder_add.png in Resources */,
FF22FE6616E54E590046165A /* barbutton_back.png in Resources */,
FF22FE6716E54E590046165A /* barbutton_back@2x.png in Resources */,
FF22FE6A16E54F590046165A /* barbutton_forward.png in Resources */,
FF22FE6B16E54F590046165A /* barbutton_forward@2x.png in Resources */,
FF22FE6E16E554540046165A /* barbutton_refresh.png in Resources */,
FF22FE6F16E554540046165A /* barbutton_refresh@2x.png in Resources */,
FF22FE7216E554FD0046165A /* barbutton_sendto.png in Resources */,
FF22FE7316E554FD0046165A /* barbutton_sendto@2x.png in Resources */,
FF22FE7616E557D80046165A /* toolbar_tall_background.png in Resources */,
FF22FE7716E557D80046165A /* toolbar_tall_background@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -2287,6 +2363,10 @@
FF67D3B2168924C40057A7DA /* TrainerViewController.m in Sources */,
FF1660CD16D6FD8A00AF8541 /* SmallInteractionCell.m in Sources */,
FF4151C016DED9660013E84B /* UIBarButtonItem+Image.m in Sources */,
FF22FE5E16E53ADC0046165A /* Underscore+Functional.m in Sources */,
FF22FE5F16E53ADC0046165A /* Underscore.m in Sources */,
FF22FE6016E53ADC0046165A /* USArrayWrapper.m in Sources */,
FF22FE6116E53ADC0046165A /* USDictionaryWrapper.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -1,6 +1,9 @@
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "Underscore.h"
#define _ Underscore
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
@ -10,8 +13,8 @@
// #define BACKGROUND_REFRESH_SECONDS -5
#define BACKGROUND_REFRESH_SECONDS -10*60
#define NEWSBLUR_URL [NSString stringWithFormat:@"nb.local.com"]
// #define NEWSBLUR_URL [NSString stringWithFormat:@"www.newsblur.com"]
// #define NEWSBLUR_URL [NSString stringWithFormat:@"nb.local.com"]
#define NEWSBLUR_URL [NSString stringWithFormat:@"www.newsblur.com"]
#define NEWSBLUR_LINK_COLOR 0x405BA8
#define NEWSBLUR_HIGHLIGHT_COLOR 0xd2e6fd

View file

@ -324,7 +324,6 @@ permittedArrowDirections:(UIPopoverArrowDirection)permittedArrowDirections
theArrowRect.origin.y = CGRectGetMinY(theBgRect) - upArrowImage.size.height + properties.topBgMargin;
}
}
bgFrame = CGRectOffset(theBgRect, theOffset.x, theOffset.y);
CGFloat minMargin = MIN(minMarginLeft, minMarginRight);
minMargin = MIN(minMargin, minMarginTop);

View file

@ -62,7 +62,7 @@
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<string key="IBUIText">Adding...</string>
<object class="NSColor" key="IBUITextColor" id="434289576">
<object class="NSColor" key="IBUITextColor" id="253759158">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MC4zMzMzMzMzMzMzAA</bytes>
</object>
@ -171,6 +171,7 @@
<string key="NSFrame">{{0, 500}, {320, 216}}</string>
<reference key="NSSuperview" ref="973185930"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:624</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIShowsSelectionIndicator">YES</bool>
@ -181,7 +182,7 @@
<string key="NSFrame">{{20, 96}, {250, 31}}</string>
<reference key="NSSuperview" ref="973185930"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="438310581"/>
<reference key="NSNextKeyView" ref="75500952"/>
<string key="NSReuseIdentifierKey">_NS:294</string>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
@ -193,19 +194,19 @@
<string key="IBUIText"/>
<int key="IBUIBorderStyle">3</int>
<string key="IBUIPlaceholder">Choose a folder</string>
<reference key="IBUITextColor" ref="434289576"/>
<reference key="IBUITextColor" ref="253759158"/>
<bool key="IBUIAdjustsFontSizeToFit">YES</bool>
<float key="IBUIMinimumFontSize">17</float>
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIFontDescription" key="IBUIFontDescription" id="217792136">
<object class="IBUIFontDescription" key="IBUIFontDescription" id="43069502">
<string key="name">Helvetica-Bold</string>
<string key="family">Helvetica</string>
<int key="traits">2</int>
<double key="pointSize">12</double>
</object>
<object class="NSFont" key="IBUIFont" id="608208801">
<object class="NSFont" key="IBUIFont" id="10285439">
<string key="NSName">Helvetica-Bold</string>
<double key="NSSize">12</double>
<int key="NSfFlags">16</int>
@ -226,7 +227,7 @@
<string key="IBUIText"/>
<int key="IBUIBorderStyle">3</int>
<string key="IBUIPlaceholder">Search by site title or address...</string>
<reference key="IBUITextColor" ref="434289576"/>
<reference key="IBUITextColor" ref="253759158"/>
<bool key="IBUIAdjustsFontSizeToFit">YES</bool>
<float key="IBUIMinimumFontSize">18</float>
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
@ -265,7 +266,7 @@
<string key="IBUIText"/>
<int key="IBUIBorderStyle">3</int>
<string key="IBUIPlaceholder">New folder title</string>
<reference key="IBUITextColor" ref="434289576"/>
<reference key="IBUITextColor" ref="253759158"/>
<bool key="IBUIAdjustsFontSizeToFit">YES</bool>
<float key="IBUIMinimumFontSize">18</float>
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
@ -277,8 +278,8 @@
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<int key="IBUIClearButtonMode">1</int>
<reference key="IBUIFontDescription" ref="217792136"/>
<reference key="IBUIFont" ref="608208801"/>
<reference key="IBUIFontDescription" ref="43069502"/>
<reference key="IBUIFont" ref="10285439"/>
</object>
<object class="IBUIActivityIndicatorView" id="450177912">
<reference key="NSNextResponder" ref="973185930"/>
@ -340,10 +341,10 @@
<bool key="IBUIMultipleTouchEnabled">YES</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIButton" id="438310581">
<object class="IBUIButton" id="75500952">
<reference key="NSNextResponder" ref="973185930"/>
<int key="NSvFlags">289</int>
<string key="NSFrame">{{272, 100}, {28, 24}}</string>
<string key="NSFrame">{{270, 96}, {50, 32}}</string>
<reference key="NSSuperview" ref="973185930"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="39450128"/>
@ -353,10 +354,10 @@
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<double key="IBUIImageEdgeInsets.top">4</double>
<double key="IBUIImageEdgeInsets.bottom">4</double>
<double key="IBUIImageEdgeInsets.left">6</double>
<double key="IBUIImageEdgeInsets.right">6</double>
<double key="IBUIImageEdgeInsets.top">8</double>
<double key="IBUIImageEdgeInsets.bottom">8</double>
<double key="IBUIImageEdgeInsets.left">8</double>
<double key="IBUIImageEdgeInsets.right">26</double>
<string key="IBUINormalTitle">Button</string>
<reference key="IBUIHighlightedTitleColor" ref="346851231"/>
<object class="NSColor" key="IBUINormalTitleColor">
@ -369,7 +370,7 @@
</object>
<object class="NSCustomResource" key="IBUINormalImage">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">g_icn_folder_rss.png</string>
<string key="NSResourceName">g_icn_folder_add.png</string>
</object>
<object class="IBUIFontDescription" key="IBUIFontDescription">
<int key="type">2</int>
@ -514,7 +515,7 @@
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">addFolderButton</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="438310581"/>
<reference key="destination" ref="75500952"/>
</object>
<int key="connectionID">69</int>
</object>
@ -619,7 +620,7 @@
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">toggleAddFolder:</string>
<reference key="source" ref="438310581"/>
<reference key="source" ref="75500952"/>
<reference key="destination" ref="372490531"/>
<int key="IBEventType">7</int>
</object>
@ -663,7 +664,7 @@
<reference ref="622270256"/>
<reference ref="845365385"/>
<reference ref="919711053"/>
<reference ref="438310581"/>
<reference ref="75500952"/>
</object>
<reference key="parent" ref="0"/>
</object>
@ -752,7 +753,7 @@
</object>
<object class="IBObjectRecord">
<int key="objectID">67</int>
<reference key="object" ref="438310581"/>
<reference key="object" ref="75500952"/>
<reference key="parent" ref="973185930"/>
</object>
</object>
@ -840,12 +841,10 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addFolder</string>
<string>addSite</string>
<string>checkSiteAddress</string>
<string>doAddButton</string>
<string>doCancelButton</string>
<string>selectAddTypeSignup</string>
<string>toggleAddFolder:</string>
</object>
<object class="NSArray" key="dict.values">
@ -855,28 +854,20 @@
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addFolder</string>
<string>addSite</string>
<string>checkSiteAddress</string>
<string>doAddButton</string>
<string>doCancelButton</string>
<string>selectAddTypeSignup</string>
<string>toggleAddFolder:</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBActionInfo">
<string key="name">addFolder</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">addSite</string>
<string key="candidateClassName">id</string>
@ -893,10 +884,6 @@
<string key="name">doCancelButton</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">selectAddTypeSignup</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">toggleAddFolder:</string>
<string key="candidateClassName">id</string>
@ -911,7 +898,6 @@
<string>addButton</string>
<string>addFolderButton</string>
<string>addFolderInput</string>
<string>addTypeControl</string>
<string>addingLabel</string>
<string>appDelegate</string>
<string>cancelButton</string>
@ -930,7 +916,6 @@
<string>UIBarButtonItem</string>
<string>UIButton</string>
<string>UITextField</string>
<string>UISegmentedControl</string>
<string>UILabel</string>
<string>NewsBlurAppDelegate</string>
<string>UIBarButtonItem</string>
@ -952,7 +937,6 @@
<string>addButton</string>
<string>addFolderButton</string>
<string>addFolderInput</string>
<string>addTypeControl</string>
<string>addingLabel</string>
<string>appDelegate</string>
<string>cancelButton</string>
@ -983,10 +967,6 @@
<string key="name">addFolderInput</string>
<string key="candidateClassName">UITextField</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">addTypeControl</string>
<string key="candidateClassName">UISegmentedControl</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">addingLabel</string>
<string key="candidateClassName">UILabel</string>
@ -3373,7 +3353,7 @@
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<object class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">
<string key="NS.key.0">g_icn_folder_rss.png</string>
<string key="NS.key.0">g_icn_folder_add.png</string>
<string key="NS.object.0">{32, 32}</string>
</object>
<string key="IBCocoaTouchPluginVersion">2083</string>

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 519 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 876 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 848 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -0,0 +1,72 @@
//
// USArrayWrapper.h
// Underscore
//
// Created by Robert Böhnke on 5/13/12.
// Copyright (C) 2012 Robert Böhnke
//
// 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>
#import "USConstants.h"
@interface USArrayWrapper : NSObject
+ (USArrayWrapper *)wrap:(NSArray *)array;
- (id)init __attribute__((deprecated("You should Underscore.array() instead")));
@property (readonly) NSArray *unwrap;
@property (readonly) id first;
@property (readonly) id last;
@property (readonly) USArrayWrapper *(^head)(NSUInteger n);
@property (readonly) USArrayWrapper *(^tail)(NSUInteger n);
@property (readonly) NSUInteger (^indexOf)(id obj);
@property (readonly) USArrayWrapper *flatten;
@property (readonly) USArrayWrapper *(^without)(NSArray *values);
@property (readonly) USArrayWrapper *shuffle;
@property (readonly) id (^reduce)(id memo, UnderscoreReduceBlock block);
@property (readonly) id (^reduceRight)(id memo, UnderscoreReduceBlock block);
@property (readonly) USArrayWrapper *(^each)(UnderscoreArrayIteratorBlock block);
@property (readonly) USArrayWrapper *(^map)(UnderscoreArrayMapBlock block);
@property (readonly) USArrayWrapper *(^pluck)(NSString *keyPath);
@property (readonly) USArrayWrapper *uniq;
@property (readonly) id (^find)(UnderscoreTestBlock block);
@property (readonly) USArrayWrapper *(^filter)(UnderscoreTestBlock block);
@property (readonly) USArrayWrapper *(^reject)(UnderscoreTestBlock block);
@property (readonly) BOOL (^all)(UnderscoreTestBlock block);
@property (readonly) BOOL (^any)(UnderscoreTestBlock block);
@property (readonly) USArrayWrapper *(^sort)(UnderscoreSortBlock block);
@end

View file

@ -0,0 +1,305 @@
//
// USArrayWrapper.m
// Underscore
//
// Created by Robert Böhnke on 5/13/12.
// Copyright (C) 2012 Robert Böhnke
//
// 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 "Underscore.h"
#import "USArrayWrapper.h"
@interface USArrayWrapper ()
- initWithArray:(NSArray *)array;
@property (readwrite, retain) NSArray *array;
@end
@implementation USArrayWrapper
#pragma mark Class methods
+ (USArrayWrapper *)wrap:(NSArray *)array
{
return [[USArrayWrapper alloc] initWithArray:[array copy]];
}
#pragma mark Lifecycle
- (id)init
{
return [super init];
}
- (id)initWithArray:(NSArray *)array
{
if (self = [super init]) {
self.array = array;
}
return self;
}
@synthesize array = _array;
- (NSArray *)unwrap
{
return [self.array copy];
}
#pragma mark Underscore methods
- (id)first
{
return self.array.count ? [self.array objectAtIndex:0] : nil;
}
- (id)last
{
return self.array.lastObject;
}
- (USArrayWrapper *(^)(NSUInteger))head
{
return ^USArrayWrapper *(NSUInteger count) {
NSRange range = NSMakeRange(0, MIN(self.array.count, count));
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range];
NSArray *result = [self.array objectsAtIndexes:indexSet];
return [[USArrayWrapper alloc] initWithArray:result];
};
}
- (USArrayWrapper *(^)(NSUInteger))tail
{
return ^USArrayWrapper *(NSUInteger count) {
NSRange range;
if (count > self.array.count) {
range = NSMakeRange(0, self.array.count);
} else {
range = NSMakeRange(self.array.count - count, count);
}
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range];
NSArray *result = [self.array objectsAtIndexes:indexSet];
return [[USArrayWrapper alloc] initWithArray:result];
};
}
- (NSUInteger (^)(id))indexOf
{
return ^NSUInteger (id obj) {
return [self.array indexOfObject:obj];
};
}
- (USArrayWrapper *)flatten
{
__weak NSArray *array = self.array;
__block NSArray *(^flatten)(NSArray *) = ^NSArray *(NSArray *input) {
NSMutableArray *result = [NSMutableArray array];
for (id obj in input) {
if ([obj isKindOfClass:[NSArray class]]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
[result addObjectsFromArray:flatten(obj)];
#pragma clang diagnostic pop
} else {
[result addObject:obj];
}
}
// If the outmost call terminates, nil the reference to flatten to break
// the retain cycle
if (input == array) {
flatten = nil;
}
return result;
};
return [USArrayWrapper wrap:flatten(self.array)];
}
- (USArrayWrapper *(^)(NSArray *))without
{
return ^USArrayWrapper *(NSArray *value) {
return self.reject(^(id obj){
return [value containsObject:obj];
});
};
}
- (USArrayWrapper *)shuffle
{
NSMutableArray *result = [self.array mutableCopy];
for (NSInteger i = result.count - 1; i > 0; i--) {
[result exchangeObjectAtIndex:arc4random() % (i + 1)
withObjectAtIndex:i];
}
return [[USArrayWrapper alloc] initWithArray:result];
}
- (id (^)(id, UnderscoreReduceBlock))reduce
{
return ^USArrayWrapper *(id memo, UnderscoreReduceBlock function) {
for (id obj in self.array) {
memo = function(memo, obj);
}
return memo;
};
}
- (id (^)(id, UnderscoreReduceBlock))reduceRight
{
return ^USArrayWrapper *(id memo, UnderscoreReduceBlock function) {
for (id obj in self.array.reverseObjectEnumerator) {
memo = function(memo, obj);
}
return memo;
};
}
- (USArrayWrapper *(^)(UnderscoreArrayIteratorBlock))each
{
return ^USArrayWrapper *(UnderscoreArrayIteratorBlock block) {
for (id obj in self.array) {
block(obj);
}
return self;
};
}
- (USArrayWrapper *(^)(UnderscoreArrayMapBlock))map
{
return ^USArrayWrapper *(UnderscoreArrayMapBlock block) {
NSMutableArray *result = [NSMutableArray arrayWithCapacity:self.array.count];
for (id obj in self.array) {
id mapped = block(obj);
if (mapped) {
[result addObject:mapped];
}
}
return [[USArrayWrapper alloc] initWithArray:result];
};
}
- (USArrayWrapper *(^)(NSString *))pluck
{
return ^USArrayWrapper *(NSString *keyPath) {
return self.map(^id (id obj) {
return [obj valueForKeyPath:keyPath];
});
};
}
- (USArrayWrapper *)uniq
{
NSSet* uniqSet = [NSSet setWithArray:self.array];
NSArray* result = [uniqSet allObjects];
return [[USArrayWrapper alloc] initWithArray:result];
}
- (id (^)(UnderscoreTestBlock))find
{
return ^id (UnderscoreTestBlock test) {
for (id obj in self.array) {
if (test(obj)) {
return obj;
}
}
return nil;
};
}
- (USArrayWrapper *(^)(UnderscoreTestBlock))filter
{
return ^USArrayWrapper *(UnderscoreTestBlock test) {
return self.map(^id (id obj) {
return test(obj) ? obj : nil;
});
};
}
- (USArrayWrapper *(^)(UnderscoreTestBlock))reject
{
return ^USArrayWrapper *(UnderscoreTestBlock test) {
return self.filter(Underscore.negate(test));
};
}
- (BOOL (^)(UnderscoreTestBlock))all
{
return ^BOOL (UnderscoreTestBlock test) {
if (self.array.count == 0) {
return NO;
}
BOOL result = YES;
for (id obj in self.array) {
if (!test(obj)) {
return NO;
}
}
return result;
};
}
- (BOOL (^)(UnderscoreTestBlock))any
{
return ^BOOL (UnderscoreTestBlock test) {
BOOL result = NO;
for (id obj in self.array) {
if (test(obj)) {
return YES;
}
}
return result;
};
}
- (USArrayWrapper *(^)(UnderscoreSortBlock))sort
{
return ^USArrayWrapper *(UnderscoreSortBlock block) {
NSArray *result = [self.array sortedArrayUsingComparator:block];
return [[USArrayWrapper alloc] initWithArray:result];
};
}
@end

View file

@ -0,0 +1,38 @@
//
// USConstants.h
// Underscore
//
// Created by Robert Böhnke on 5/14/12.
// Copyright (C) 2012 Robert Böhnke
//
// 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>
typedef BOOL (^UnderscoreTestBlock)(id obj);
typedef id (^UnderscoreReduceBlock)(id memo, id obj);
typedef void (^UnderscoreArrayIteratorBlock)(id obj);
typedef id (^UnderscoreArrayMapBlock)(id obj);
typedef void (^UnderscoreDictionaryIteratorBlock)(id key, id obj);
typedef id (^UnderscoreDictionaryMapBlock)(id key, id obj);
typedef NSComparisonResult (^UnderscoreSortBlock)(id a, id b);

View file

@ -0,0 +1,57 @@
//
// USDictionaryWrapper.h
// Underscore
//
// Created by Robert Böhnke on 5/14/12.
// Copyright (C) 2012 Robert Böhnke
//
// 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>
#import "USArrayWrapper.h"
#import "USConstants.h"
@interface USDictionaryWrapper : NSObject
+ (USDictionaryWrapper *)wrap:(NSDictionary *)dictionary;
- (NSDictionary *)unwrap;
- (id)init __attribute__((deprecated("You should Underscore.dict() instead")));
@property (readonly) USArrayWrapper *keys;
@property (readonly) USArrayWrapper *values;
@property (readonly) USDictionaryWrapper *(^each)(UnderscoreDictionaryIteratorBlock block);
@property (readonly) USDictionaryWrapper *(^map)(UnderscoreDictionaryMapBlock block);
@property (readonly) USDictionaryWrapper *(^pick)(NSArray *keys);
@property (readonly) USDictionaryWrapper *(^extend)(NSDictionary *source);
@property (readonly) USDictionaryWrapper *(^defaults)(NSDictionary *defaults);
@property (readonly) USDictionaryWrapper *(^filterKeys)(UnderscoreTestBlock block);
@property (readonly) USDictionaryWrapper *(^filterValues)(UnderscoreTestBlock block);
@property (readonly) USDictionaryWrapper *(^rejectKeys)(UnderscoreTestBlock block);
@property (readonly) USDictionaryWrapper *(^rejectValues)(UnderscoreTestBlock block);
@end

View file

@ -0,0 +1,188 @@
//
// USDictionaryWrapper.m
// Underscore
//
// Created by Robert Böhnke on 5/14/12.
// Copyright (C) 2012 Robert Böhnke
//
// 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 "Underscore.h"
#import "USDictionaryWrapper.h"
@interface USDictionaryWrapper ()
- initWithDictionary:(NSDictionary *)dictionary;
@property (readwrite, retain) NSDictionary *dictionary;
@end
@implementation USDictionaryWrapper
#pragma mark Class methods
+ (USDictionaryWrapper *)wrap:(NSDictionary *)dictionary
{
return [[USDictionaryWrapper alloc] initWithDictionary:[dictionary copy]];
}
#pragma mark Lifecycle
- (id)init
{
return [super init];
}
- (id)initWithDictionary:(NSDictionary *)dictionary
{
if (self = [super init]) {
self.dictionary = dictionary;
}
return self;
}
@synthesize dictionary = _dictionary;
- (NSDictionary *)unwrap
{
return [self.dictionary copy];
}
#pragma mark Underscore methods
- (USArrayWrapper *)keys
{
return [USArrayWrapper wrap:self.dictionary.allKeys];
}
- (USArrayWrapper *)values
{
return [USArrayWrapper wrap:self.dictionary.allValues];
}
- (USDictionaryWrapper *(^)(UnderscoreDictionaryIteratorBlock))each
{
return ^USDictionaryWrapper *(UnderscoreDictionaryIteratorBlock block) {
[self.dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
block(key, obj);
}];
return self;
};
}
- (USDictionaryWrapper *(^)(UnderscoreDictionaryMapBlock))map
{
return ^USDictionaryWrapper *(UnderscoreDictionaryMapBlock block) {
NSMutableDictionary *result = [NSMutableDictionary dictionary];
[self.dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
id mapped = block(key, obj);
if (mapped) {
[result setObject:mapped
forKey:key];
}
}];
return [[USDictionaryWrapper alloc] initWithDictionary:result];
};
}
- (USDictionaryWrapper *(^)(NSArray *))pick
{
return ^USDictionaryWrapper *(NSArray *keys) {
__block NSMutableDictionary *result = [NSMutableDictionary dictionaryWithCapacity:keys.count];
[self.dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
if ([keys containsObject:key]) {
[result setObject:obj
forKey:key];
}
}];
return [[USDictionaryWrapper alloc] initWithDictionary:result];
};
}
- (USDictionaryWrapper *(^)(NSDictionary *))extend
{
return ^USDictionaryWrapper *(NSDictionary *source) {
__block NSMutableDictionary *result = [self.dictionary mutableCopy];
[source enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[result setObject:obj
forKey:key];
}];
return [[USDictionaryWrapper alloc] initWithDictionary:result];
};
}
- (USDictionaryWrapper *(^)(NSDictionary *))defaults
{
return ^USDictionaryWrapper *(NSDictionary *source) {
__block NSMutableDictionary *result = [self.dictionary mutableCopy];
[source enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
if (![result valueForKey:key]) {
[result setObject:obj
forKey:key];
}
}];
return [[USDictionaryWrapper alloc] initWithDictionary:result];
};
}
- (USDictionaryWrapper *(^)(UnderscoreTestBlock))filterKeys
{
return ^USDictionaryWrapper *(UnderscoreTestBlock test) {
return self.map(^id (id key, id obj) {
return test(key) ? obj : nil;
});
};
}
- (USDictionaryWrapper *(^)(UnderscoreTestBlock))filterValues
{
return ^USDictionaryWrapper *(UnderscoreTestBlock test) {
return self.map(^id (id key, id obj) {
return test(obj) ? obj : nil;
});
};
}
- (USDictionaryWrapper *(^)(UnderscoreTestBlock))rejectKeys
{
return ^USDictionaryWrapper *(UnderscoreTestBlock test) {
return self.filterKeys(Underscore.negate(test));
};
}
- (USDictionaryWrapper *(^)(UnderscoreTestBlock))rejectValues
{
return ^USDictionaryWrapper *(UnderscoreTestBlock test) {
return self.filterValues(Underscore.negate(test));
};
}
@end

View file

@ -0,0 +1,89 @@
//
// Underscore+Functional.h
// Underscore
//
// Created by Robert Böhnke on 7/15/12.
// Copyright (c) 2012 Robert Böhnke. All rights reserved.
//
// 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 "Underscore.h"
@interface Underscore (FunctionalStyle)
#pragma mark NSArray functional style methods
+ (USArrayWrapper *(^)(NSArray *))array;
+ (id (^)(NSArray *))first;
+ (id (^)(NSArray *))last;
+ (NSArray *(^)(NSArray *array, NSUInteger n))head;
+ (NSArray *(^)(NSArray *array, NSUInteger n))tail;
+ (NSUInteger (^)(NSArray *array, id obj))indexOf;
+ (NSArray *(^)(NSArray *array))flatten;
+ (NSArray *(^)(NSArray *array, NSArray *values))without;
+ (NSArray *(^)(NSArray *array))shuffle;
+ (id (^)(NSArray *array, id memo, UnderscoreReduceBlock block))reduce;
+ (id (^)(NSArray *array, id memo, UnderscoreReduceBlock block))reduceRight;
+ (void (^)(NSArray *array, UnderscoreArrayIteratorBlock block))arrayEach;
+ (NSArray *(^)(NSArray *array, UnderscoreArrayMapBlock block))arrayMap;
+ (NSArray *(^)(NSArray *array, NSString *keyPath))pluck;
+ (NSArray *(^)(NSArray *array))uniq;
+ (id (^)(NSArray *array, UnderscoreTestBlock block))find;
+ (NSArray *(^)(NSArray *array, UnderscoreTestBlock block))filter;
+ (NSArray *(^)(NSArray *array, UnderscoreTestBlock block))reject;
+ (BOOL (^)(NSArray *array, UnderscoreTestBlock block))all;
+ (BOOL (^)(NSArray *array, UnderscoreTestBlock block))any;
+ (NSArray *(^)(NSArray *array, UnderscoreSortBlock block))sort;
#pragma mark NSDictionary style methods
+ (USDictionaryWrapper *(^)(NSDictionary *dictionary))dict;
+ (NSArray *(^)(NSDictionary *dictionary))keys;
+ (NSArray *(^)(NSDictionary *dictionary))values;
+ (void (^)(NSDictionary *dictionary, UnderscoreDictionaryIteratorBlock block))dictEach;
+ (NSDictionary *(^)(NSDictionary *dictionary, UnderscoreDictionaryMapBlock block))dictMap;
+ (NSDictionary *(^)(NSDictionary *dictionary, NSArray *keys))pick;
+ (NSDictionary *(^)(NSDictionary *dictionary, NSDictionary *source))extend;
+ (NSDictionary *(^)(NSDictionary *dictionary, NSDictionary *defaults))defaults;
+ (NSDictionary *(^)(NSDictionary *dictionary, UnderscoreTestBlock block))filterKeys;
+ (NSDictionary *(^)(NSDictionary *dictionary, UnderscoreTestBlock block))filterValues;
+ (NSDictionary *(^)(NSDictionary *dictionary, UnderscoreTestBlock block))rejectKeys;
+ (NSDictionary *(^)(NSDictionary *dictionary, UnderscoreTestBlock block))rejectValues;
@end

View file

@ -0,0 +1,261 @@
//
// Underscore+Functional.m
// Underscore
//
// Created by Robert Böhnke on 7/15/12.
// Copyright (c) 2012 Robert Böhnke. All rights reserved.
//
// 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 "Underscore+Functional.h"
@implementation Underscore (Functional)
#pragma mark NSArray shortcuts
+ (USArrayWrapper *(^)(NSArray *))array
{
return ^(NSArray *array) {
return [USArrayWrapper wrap:array];
};
}
+ (id (^)(NSArray *))first
{
return ^(NSArray *array) {
return Underscore.array(array).first;
};
}
+ (id (^)(NSArray *))last
{
return ^(NSArray *array) {
return Underscore.array(array).last;
};
}
+ (NSArray *(^)(NSArray *, NSUInteger))head
{
return ^(NSArray *array, NSUInteger n) {
return Underscore.array(array).head(n).unwrap;
};
}
+ (NSArray *(^)(NSArray *, NSUInteger))tail
{
return ^(NSArray *array, NSUInteger n) {
return Underscore.array(array).tail(n).unwrap;
};
}
+ (NSUInteger (^)(NSArray *, id))indexOf
{
return ^(NSArray *array, id obj) {
return Underscore.array(array).indexOf(obj);
};
}
+ (NSArray *(^)(NSArray *))flatten
{
return ^(NSArray *array) {
return Underscore.array(array).flatten.unwrap;
};
}
+ (NSArray *(^)(NSArray *))uniq
{
return ^(NSArray *array) {
return Underscore.array(array).uniq.unwrap;
};
}
+ (NSArray *(^)(NSArray *, NSArray *))without
{
return ^(NSArray *array, NSArray *values) {
return Underscore.array(array).without(values).unwrap;
};
}
+ (NSArray *(^)(NSArray *))shuffle
{
return ^(NSArray *array) {
return Underscore.array(array).shuffle.unwrap;
};
}
+(id (^)(NSArray *, id, UnderscoreReduceBlock))reduce
{
return ^(NSArray *array, id memo, UnderscoreReduceBlock block) {
return Underscore.array(array).reduce(memo, block);
};
}
+ (id (^)(NSArray *, id, UnderscoreReduceBlock))reduceRight
{
return ^(NSArray *array, id memo, UnderscoreReduceBlock block) {
return Underscore.array(array).reduceRight(memo, block);
};
}
+ (void (^)(NSArray *, UnderscoreArrayIteratorBlock))arrayEach
{
return ^(NSArray *array, UnderscoreArrayIteratorBlock block) {
Underscore.array(array).each(block);
};
}
+ (NSArray *(^)(NSArray *array, UnderscoreArrayMapBlock block))arrayMap
{
return ^(NSArray *array, UnderscoreArrayMapBlock block) {
return Underscore.array(array).map(block).unwrap;
};
}
+ (NSArray *(^)(NSArray *, NSString *))pluck
{
return ^(NSArray *array, NSString *keyPath) {
return Underscore.array(array).pluck(keyPath).unwrap;
};
}
+ (id (^)(NSArray *, UnderscoreTestBlock))find
{
return ^(NSArray *array, UnderscoreTestBlock block) {
return Underscore.array(array).find(block);
};
}
+ (NSArray *(^)(NSArray *, UnderscoreTestBlock))filter
{
return ^(NSArray *array, UnderscoreTestBlock block) {
return Underscore.array(array).filter(block).unwrap;
};
}
+ (NSArray *(^)(NSArray *, UnderscoreTestBlock))reject
{
return ^(NSArray *array, UnderscoreTestBlock block) {
return Underscore.array(array).reject(block).unwrap;
};
}
+ (BOOL (^)(NSArray *, UnderscoreTestBlock))all
{
return ^(NSArray *array, UnderscoreTestBlock block) {
return Underscore.array(array).all(block);
};
}
+ (BOOL (^)(NSArray *, UnderscoreTestBlock))any
{
return ^(NSArray *array, UnderscoreTestBlock block) {
return Underscore.array(array).any(block);
};
}
+ (NSArray *(^)(NSArray *, UnderscoreSortBlock))sort
{
return ^(NSArray *array, UnderscoreSortBlock block) {
return Underscore.array(array).sort(block).unwrap;
};
}
#pragma mark NSDictionary shortcuts
+ (USDictionaryWrapper *(^)(NSDictionary *))dict
{
return ^(NSDictionary *dictionary) {
return [USDictionaryWrapper wrap:dictionary];
};
}
+ (NSArray *(^)(NSDictionary *))keys
{
return ^(NSDictionary *dictionary) {
return [USDictionaryWrapper wrap:dictionary].keys.unwrap;
};
}
+ (NSArray *(^)(NSDictionary *))values
{
return ^(NSDictionary *dictionary) {
return [USDictionaryWrapper wrap:dictionary].values.unwrap;
};
}
+ (void (^)(NSDictionary *, UnderscoreDictionaryIteratorBlock))dictEach
{
return ^(NSDictionary *dictionary, UnderscoreDictionaryIteratorBlock block) {
Underscore.dict(dictionary).each(block);
};
}
+ (NSDictionary *(^)(NSDictionary *, UnderscoreDictionaryMapBlock))dictMap
{
return ^(NSDictionary *dictionary, UnderscoreDictionaryMapBlock block) {
return Underscore.dict(dictionary).map(block).unwrap;
};
}
+ (NSDictionary *(^)(NSDictionary *, NSArray *))pick
{
return ^(NSDictionary *dictionary, NSArray *keys) {
return [USDictionaryWrapper wrap:dictionary].pick(keys).unwrap;
};
}
+ (NSDictionary *(^)(NSDictionary *, NSDictionary *))extend
{
return ^(NSDictionary *dictionary, NSDictionary *source) {
return [USDictionaryWrapper wrap:dictionary].extend(source).unwrap;
};
}
+ (NSDictionary *(^)(NSDictionary *, NSDictionary *))defaults
{
return ^(NSDictionary *dictionary, NSDictionary *defaults) {
return [USDictionaryWrapper wrap:dictionary].defaults(defaults).unwrap;
};
}
+ (NSDictionary *(^)(NSDictionary *, UnderscoreTestBlock))filterKeys
{
return ^(NSDictionary *dictionary, UnderscoreTestBlock block) {
return [USDictionaryWrapper wrap:dictionary].filterKeys(block).unwrap;
};
}
+ (NSDictionary *(^)(NSDictionary *, UnderscoreTestBlock))filterValues
{
return ^(NSDictionary *dictionary, UnderscoreTestBlock block) {
return [USDictionaryWrapper wrap:dictionary].filterValues(block).unwrap;
};
}
+ (NSDictionary *(^)(NSDictionary *, UnderscoreTestBlock))rejectKeys
{
return ^(NSDictionary *dictionary, UnderscoreTestBlock block) {
return [USDictionaryWrapper wrap:dictionary].rejectKeys(block).unwrap;
};
}
+ (NSDictionary *(^)(NSDictionary *, UnderscoreTestBlock))rejectValues
{
return ^(NSDictionary *dictionary, UnderscoreTestBlock block) {
return [USDictionaryWrapper wrap:dictionary].rejectValues(block).unwrap;
};
}
@end

View file

@ -0,0 +1,7 @@
//
// Prefix header for all source files of the 'Underscore' target in the 'Underscore' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#endif

View file

@ -0,0 +1,50 @@
//
// Underscore.h
// Underscore
//
// Created by Robert Böhnke on 4/29/12.
// Copyright (C) 2012 Robert Böhnke
//
// 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>
#import "USConstants.h"
#import "USArrayWrapper.h"
#import "USDictionaryWrapper.h"
@interface Underscore : NSObject
+ (UnderscoreTestBlock(^)(UnderscoreTestBlock))negate;
+ (UnderscoreTestBlock(^)(id obj))isEqual;
+ (UnderscoreTestBlock)isArray;
+ (UnderscoreTestBlock)isDictionary;
+ (UnderscoreTestBlock)isNull;
+ (UnderscoreTestBlock)isNumber;
+ (UnderscoreTestBlock)isString;
+ (UnderscoreSortBlock)compare;
- (id)init __deprecated;
@end
#import "Underscore+Functional.h"

100
media/ios/Underscore/Underscore.m Executable file
View file

@ -0,0 +1,100 @@
//
// Underscore.m
// Underscore
//
// Created by Robert Böhnke on 5/14/12.
// Copyright (C) 2012 Robert Böhnke
//
// 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 "Underscore.h"
#if !__has_feature(objc_arc)
# error Underscore.m requires Automatic Reference Counting to be enabled
#endif
@implementation Underscore
+ (UnderscoreTestBlock (^)(UnderscoreTestBlock))negate
{
return ^UnderscoreTestBlock (UnderscoreTestBlock test) {
return ^BOOL (id obj) {
return !test(obj);
};
};
}
+ (UnderscoreTestBlock(^)(id obj))isEqual
{
return ^UnderscoreTestBlock (id obj) {
return ^BOOL (id other) {
return [obj isEqual:other];
};
};
}
+ (UnderscoreTestBlock)isArray
{
return ^BOOL (id obj) {
return [obj isKindOfClass:[NSArray class]];
};
}
+ (UnderscoreTestBlock)isDictionary
{
return ^BOOL (id obj) {
return [obj isKindOfClass:[NSDictionary class]];
};
}
+ (UnderscoreTestBlock)isNull
{
return ^BOOL (id obj) {
return [obj isKindOfClass:[NSNull class]];
};
}
+ (UnderscoreTestBlock)isNumber
{
return ^BOOL (id obj) {
return [obj isKindOfClass:[NSNumber class]];
};
}
+ (UnderscoreTestBlock)isString
{
return ^BOOL (id obj) {
return [obj isKindOfClass:[NSString class]];
};
}
+ (UnderscoreSortBlock)compare
{
return ^NSComparisonResult(id a, id b){
return [a compare:b];
};
}
- (id)init
{
return [super init];
}
@end