Skip to content

Commit

Permalink
[css] Addressed constant naming convention and converted category to …
Browse files Browse the repository at this point in the history
…simple C methods. Also added dictionary support to view builder
  • Loading branch information
Max Metral committed Feb 20, 2013
1 parent 11212aa commit c5a4ad0
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 93 deletions.
12 changes: 6 additions & 6 deletions examples/css/CSSDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
C743F6E716D1F4EB00A933B7 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = C743F6E316D1F4EB00A933B7 /* [email protected] */; };
C743F6F416D29F2500A933B7 /* NIUserInterfaceString.m in Sources */ = {isa = PBXBuildFile; fileRef = C743F6F316D29F2500A933B7 /* NIUserInterfaceString.m */; };
C7B9283F16D2B45A001BF61C /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C7B9283D16D2B45A001BF61C /* Localizable.strings */; };
C7B9284B16D2F736001BF61C /* NSInvocation+NimbusCore.m in Sources */ = {isa = PBXBuildFile; fileRef = C7B9284A16D2F736001BF61C /* NSInvocation+NimbusCore.m */; };
C7B9284B16D2F736001BF61C /* NIInvocationHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = C7B9284A16D2F736001BF61C /* NIInvocationHelpers.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -181,8 +181,8 @@
C743F6F316D29F2500A933B7 /* NIUserInterfaceString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NIUserInterfaceString.m; path = ../../src/css/src/NIUserInterfaceString.m; sourceTree = "<group>"; };
C743F6F516D2AAC200A933B7 /* NIUserInterfaceString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NIUserInterfaceString.h; path = ../../src/css/src/NIUserInterfaceString.h; sourceTree = "<group>"; };
C7B9283E16D2B45A001BF61C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = resources/en.lproj/Localizable.strings; sourceTree = "<group>"; };
C7B9284916D2F736001BF61C /* NSInvocation+NimbusCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSInvocation+NimbusCore.h"; path = "../../src/core/src/NSInvocation+NimbusCore.h"; sourceTree = "<group>"; };
C7B9284A16D2F736001BF61C /* NSInvocation+NimbusCore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSInvocation+NimbusCore.m"; path = "../../src/core/src/NSInvocation+NimbusCore.m"; sourceTree = "<group>"; };
C7B9284916D2F736001BF61C /* NIInvocationHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NIInvocationHelpers.h; path = ../../src/core/src/NIInvocationHelpers.h; sourceTree = "<group>"; };
C7B9284A16D2F736001BF61C /* NIInvocationHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NIInvocationHelpers.m; path = ../../src/core/src/NIInvocationHelpers.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -291,8 +291,8 @@
66832D41144214DA003E413C /* Core */ = {
isa = PBXGroup;
children = (
C7B9284916D2F736001BF61C /* NSInvocation+NimbusCore.h */,
C7B9284A16D2F736001BF61C /* NSInvocation+NimbusCore.m */,
C7B9284916D2F736001BF61C /* NIInvocationHelpers.h */,
C7B9284A16D2F736001BF61C /* NIInvocationHelpers.m */,
66832DAE14434FB2003E413C /* NICommonMetrics.h */,
66832DAF14434FB2003E413C /* NICommonMetrics.m */,
66832DB014434FB2003E413C /* NIDataStructures.h */,
Expand Down Expand Up @@ -524,7 +524,7 @@
66D2FE2915941EEB00B2BEFD /* AFXMLRequestOperation.m in Sources */,
66D2FE2A15941EEB00B2BEFD /* UIImageView+AFNetworking.m in Sources */,
C743F6F416D29F2500A933B7 /* NIUserInterfaceString.m in Sources */,
C7B9284B16D2F736001BF61C /* NSInvocation+NimbusCore.m in Sources */,
C7B9284B16D2F736001BF61C /* NIInvocationHelpers.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions examples/css/CSSDemo/RootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#import "RootViewController.h"
#import "UIView+NIStyleable.h"
#import "NIUserInterfaceString.h"
#import "NSInvocation+NimbusCore.h"
#import "NIInvocationHelpers.h"

#import "AppDelegate.h"

Expand Down Expand Up @@ -66,7 +66,7 @@ - (void)loadView {
],
[[UILabel alloc] init], @".rightMiddleLabel", NILocalizedStringWithDefault(@"RightLabel", @"Right Middle Label"),
[[UILabel alloc] init], @".bottomLabel", NILocalizedStringWithDefault(@"BottomLabel", @"Bottom Left Label"),
_button = [UIButton buttonWithType:UIButtonTypeCustom], [NSInvocation invocationWithTarget: self selector: @selector(buttonPress)], NILocalizedStringWithDefault(@"TestButton", @"Test Button"), @"#TestButton"
_button = [UIButton buttonWithType:UIButtonTypeCustom], NIInvocationWithInstanceTarget(self, @selector(buttonPress)), NILocalizedStringWithDefault(@"TestButton", @"Test Button"), @"#TestButton"
] inDOM:_dom];

for (int i = 1; i <= 7; i++) {
Expand Down
20 changes: 10 additions & 10 deletions src/Nimbus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@
C743F6EA16D2652F00A933B7 /* NIUserInterfaceString.h in Headers */ = {isa = PBXBuildFile; fileRef = C743F6E816D2652F00A933B7 /* NIUserInterfaceString.h */; };
C743F6EB16D2652F00A933B7 /* NIUserInterfaceString.m in Sources */ = {isa = PBXBuildFile; fileRef = C743F6E916D2652F00A933B7 /* NIUserInterfaceString.m */; };
C743F6EC16D2652F00A933B7 /* NIUserInterfaceString.m in Sources */ = {isa = PBXBuildFile; fileRef = C743F6E916D2652F00A933B7 /* NIUserInterfaceString.m */; };
C7B9284316D2F563001BF61C /* NSInvocation+NimbusCore.h in Headers */ = {isa = PBXBuildFile; fileRef = C7B9284116D2F563001BF61C /* NSInvocation+NimbusCore.h */; };
C7B9284416D2F563001BF61C /* NSInvocation+NimbusCore.m in Sources */ = {isa = PBXBuildFile; fileRef = C7B9284216D2F563001BF61C /* NSInvocation+NimbusCore.m */; };
C7B9284516D2F563001BF61C /* NSInvocation+NimbusCore.m in Sources */ = {isa = PBXBuildFile; fileRef = C7B9284216D2F563001BF61C /* NSInvocation+NimbusCore.m */; };
C7B9284316D2F563001BF61C /* NIInvocationHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = C7B9284116D2F563001BF61C /* NIInvocationHelpers.h */; };
C7B9284416D2F563001BF61C /* NIInvocationHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = C7B9284216D2F563001BF61C /* NIInvocationHelpers.m */; };
C7B9284516D2F563001BF61C /* NIInvocationHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = C7B9284216D2F563001BF61C /* NIInvocationHelpers.m */; };
DB3A231713FD4B8E00614220 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 66A03C1A13E6E85E00B514F3 /* SenTestingKit.framework */; };
DB3A231913FD4B8E00614220 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 66A03C0C13E6E85E00B514F3 /* Foundation.framework */; };
DB3A231D13FD4B8E00614220 /* libNimbusAttributedLabel.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DB3A230913FD4B8E00614220 /* libNimbusAttributedLabel.a */; };
Expand Down Expand Up @@ -975,8 +975,8 @@
66FE7D6813FB83620061B987 /* NimbusModelsTests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "NimbusModelsTests-Info.plist"; sourceTree = "<group>"; };
C743F6E816D2652F00A933B7 /* NIUserInterfaceString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NIUserInterfaceString.h; path = css/src/NIUserInterfaceString.h; sourceTree = SOURCE_ROOT; };
C743F6E916D2652F00A933B7 /* NIUserInterfaceString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NIUserInterfaceString.m; path = css/src/NIUserInterfaceString.m; sourceTree = SOURCE_ROOT; };
C7B9284116D2F563001BF61C /* NSInvocation+NimbusCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSInvocation+NimbusCore.h"; sourceTree = "<group>"; };
C7B9284216D2F563001BF61C /* NSInvocation+NimbusCore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSInvocation+NimbusCore.m"; sourceTree = "<group>"; };
C7B9284116D2F563001BF61C /* NIInvocationHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NIInvocationHelpers.h; sourceTree = "<group>"; };
C7B9284216D2F563001BF61C /* NIInvocationHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NIInvocationHelpers.m; sourceTree = "<group>"; };
DB3A230913FD4B8E00614220 /* libNimbusAttributedLabel.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libNimbusAttributedLabel.a; sourceTree = BUILT_PRODUCTS_DIR; };
DB3A231613FD4B8E00614220 /* NimbusAttributedLabelTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NimbusAttributedLabelTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
DB3A233213FD4BE500614220 /* NIAttributedLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NIAttributedLabel.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1762,8 +1762,8 @@
6675E4B21455FCC5007D172F /* NIViewRecycler.m */,
66A03CB713E6EFAF00B514F3 /* NSString+NimbusCore.h */,
66A03C6313E6E8D100B514F3 /* NSString+NimbusCore.m */,
C7B9284116D2F563001BF61C /* NSInvocation+NimbusCore.h */,
C7B9284216D2F563001BF61C /* NSInvocation+NimbusCore.m */,
C7B9284116D2F563001BF61C /* NIInvocationHelpers.h */,
C7B9284216D2F563001BF61C /* NIInvocationHelpers.m */,
);
name = src;
path = core/src;
Expand Down Expand Up @@ -2212,7 +2212,7 @@
669819DB159B927B00C2D3EF /* NISnapshotRotation.h in Headers */,
66C1D83D16B9CE90003E855B /* NIImageUtilities.h in Headers */,
66C1D8C116B9ED65003E855B /* NIButtonUtilities.h in Headers */,
C7B9284316D2F563001BF61C /* NSInvocation+NimbusCore.h in Headers */,
C7B9284316D2F563001BF61C /* NIInvocationHelpers.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -3485,7 +3485,7 @@
669819DC159B927B00C2D3EF /* NISnapshotRotation.m in Sources */,
66C1D83E16B9CE90003E855B /* NIImageUtilities.m in Sources */,
66C1D8C216B9ED65003E855B /* NIButtonUtilities.m in Sources */,
C7B9284416D2F563001BF61C /* NSInvocation+NimbusCore.m in Sources */,
C7B9284416D2F563001BF61C /* NIInvocationHelpers.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -3506,7 +3506,7 @@
66E8CED214D089E500600592 /* NICommonMetricsTests.m in Sources */,
6607851C14D245BF00FE3283 /* NINetworkActivityTests.m in Sources */,
6607852014D33EAA00FE3283 /* NIStateTests.m in Sources */,
C7B9284516D2F563001BF61C /* NSInvocation+NimbusCore.m in Sources */,
C7B9284516D2F563001BF61C /* NIInvocationHelpers.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
* NSInvocation extensions to make them easier to construct in concise code for things like button handlers
* and such.
*/
@interface NSInvocation (NimbusCore)

/**
* Construct an NSInvocation with an instance of an object and a selector
*/
+ (id)invocationWithTarget:(NSObject*)targetObject selector:(SEL)selector;
extern NSInvocation* NIInvocationWithInstanceTarget(NSObject* target, SEL selector);

/**
* Construct an NSInvocation for a class method given a class object and a selector
*/
+ (id)invocationWithClass:(Class)targetClass selector:(SEL)selector;
@end
extern NSInvocation* NIInvocationWithClassTarget(Class targetClass, SEL selector);
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@
// Copyright (c) 2013 Jeff Verkoeyen. All rights reserved.
//

#import "NSInvocation+NimbusCore.h"
#import "NIInvocationHelpers.h"
#import <objc/runtime.h>

NI_FIX_CATEGORY_BUG(NSInvocation_NimbusCore)

@implementation NSInvocation (NimbusCore)

+ (id)invocationWithTarget:(NSObject*)targetObject selector:(SEL)selector {
NSInvocation *NIInvocationWithInstanceTarget(NSObject *targetObject, SEL selector) {
NSMethodSignature* sig = [targetObject methodSignatureForSelector:selector];
NSInvocation* inv = [NSInvocation invocationWithMethodSignature:sig];
[inv setTarget:targetObject];
[inv setSelector:selector];
return inv;
}

+ (id)invocationWithClass:(Class)targetClass selector:(SEL)selector {
NSInvocation* NIInvocationWithClassTarget(Class targetClass, SEL selector) {
Method method = class_getInstanceMethod(targetClass, selector);
struct objc_method_description* desc = method_getDescription(method);
if (desc == NULL || desc->name == NULL)
Expand All @@ -31,5 +27,3 @@ + (id)invocationWithClass:(Class)targetClass selector:(SEL)selector {
[inv setSelector:selector];
return inv;
}

@end
6 changes: 3 additions & 3 deletions src/css/src/NICSSRuleset.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ typedef struct {
} NICSSUnit;

typedef enum {
BUTTON_ADJUST_NONE = 0,
BUTTON_ADJUST_HIGHLIGHTED = 1,
BUTTON_ADJUST_DISABLED = 2
NICSSButtonAdjustNone = 0,
NICSSButtonAdjustHighlighted = 1,
NICSSButtonAdjustDisabled = 2
} NICSSButtonAdjust;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/css/src/NICSSRuleset.m
Original file line number Diff line number Diff line change
Expand Up @@ -1160,12 +1160,12 @@ +(CGFloat)pixelsFromCssValue: (NSArray*) cssValues
///////////////////////////////////////////////////////////////////////////////////////////////////
+(NICSSButtonAdjust)buttonAdjustFromCssValue: (NSArray*) cssValues
{
NICSSButtonAdjust a = BUTTON_ADJUST_NONE;
NICSSButtonAdjust a = NICSSButtonAdjustNone;
for (NSString* token in cssValues) {
if ([token caseInsensitiveCompare:@"highlighted"] == NSOrderedSame) {
a |= BUTTON_ADJUST_HIGHLIGHTED;
a |= NICSSButtonAdjustHighlighted;
} else if ([token caseInsensitiveCompare:@"disabled"] == NSOrderedSame) {
a |= BUTTON_ADJUST_DISABLED;
a |= NICSSButtonAdjustDisabled;
}
}
return a;
Expand Down
15 changes: 15 additions & 0 deletions src/css/src/NIDOM.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ _dom = [[NIDOM alloc] initWithStylesheet:stylesheet];

-(UIView*)viewById: (NSString*) viewId;

@property (nonatomic,unsafe_unretained) id target;
@end

/** @name Creating NIDOMs */
Expand Down Expand Up @@ -177,3 +178,17 @@ _dom = [[NIDOM alloc] initWithStylesheet:stylesheet];
*
* @fn NIDOM::addCssClass:toView:
*/

/** @name Dynamic View Construction */

/**
* Using the [UIView buildSubviews:inDOM:] extension allows you to build view
* hierarchies from JSON (or anything able to convert to NSDictionary/NSArray
* of simple types) documents, mostly for prototyping. Those documents can
* specify selectors, and those selectors need a target. This target property
* will be the target for all selectors in a given DOM. Truth is it only matters
* during buildSubviews, so in theory you could set and reset it across multiple
* build calls if you wanted to.
*
* @fn NIDOM::target
*/
4 changes: 2 additions & 2 deletions src/css/src/UIButton+NIStyleable.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ - (void)applyButtonStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM:(NIDOM *)dom {
if ([ruleSet hasContentInsets]) { self.contentEdgeInsets = ruleSet.contentInsets; }
if ([ruleSet hasImageInsets]) { self.imageEdgeInsets = ruleSet.imageInsets; }
if ([ruleSet hasButtonAdjust]) {
self.adjustsImageWhenDisabled = ((ruleSet.buttonAdjust & BUTTON_ADJUST_DISABLED) != 0);
self.adjustsImageWhenHighlighted = ((ruleSet.buttonAdjust & BUTTON_ADJUST_HIGHLIGHTED) != 0);
self.adjustsImageWhenDisabled = ((ruleSet.buttonAdjust & NICSSButtonAdjustDisabled) != 0);
self.adjustsImageWhenHighlighted = ((ruleSet.buttonAdjust & NICSSButtonAdjustHighlighted) != 0);
}
}

Expand Down
20 changes: 14 additions & 6 deletions src/css/src/UIView+NIStyleable.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
@class NICSSRuleset;
@class NIDOM;

extern NSString* const NICSSViewKey;
extern NSString* const NICSSViewIdKey;
extern NSString* const NICSSViewCssClassKey;
extern NSString* const NICSSViewTextKey;
extern NSString* const NICSSViewTagKey;
extern NSString* const NICSSViewTargetSelectorKey;
extern NSString* const NICSSViewSubviewsKey;
extern NSString* const NICSSViewAccessibilityLabelKey;

@interface UIView (NIStyleable)

/**
Expand All @@ -37,24 +46,23 @@
*/
- (void)applyViewStyleWithRuleSet:(NICSSRuleset *)ruleSet inDOM: (NIDOM*) dom;

/**
* Convenience method to add a set of views to this view
*/
- (void)addSubviews: (NSArray*) views;

/**
* Build a view hierarchy. The array is a list of view specs, where viewSpec is a loosely formatted
* sequence delineated by UIViews. After a UIView, the type of the next object determines what is done
* with it:
* UIView instance - following values will be applied to this UIView (other than Class, which "starts anew")
* Class - a UIView subclass that will be alloc'ed and init'ed
* NSString starting with a hash - view id (for style application)
* NSString starting with a dot - CSS Class (for style application)
* NSString starting with a dot - CSS Class (for style application) (you can do this multiple times per view)
* NSString - accessibility label for the view.
* NIUserInterfaceString - .text or .title(normal) on a button. Asserts otherwise
* NSNumber - tag
* NSInvocation - selector for TouchUpInside (e.g. on a UIButton)
* NSArray - passed to build on the active UIView and results added as subviews
* NSDictionary - if you're squeamish about this whole Javascript duck typing auto detecting fancyness
* you can pass a boring old dictionary with named values:
* NICSSViewKey, NICSSViewIdKey, NICSSViewCssClassKey, NICSSViewTextKey, NICSSViewTagKey,
* NICSSViewTargetSelectorKey, NICSSViewSubviewsKey, NICSSViewAccessibilityLabelKey
*
* Example (including inline setting of self properties):
* [self.view buildSubviews: @[
Expand Down
Loading

0 comments on commit c5a4ad0

Please sign in to comment.