Skip to content

Commit

Permalink
refactored all the class methods to be on a singleton object
Browse files Browse the repository at this point in the history
  • Loading branch information
Marin Usalj committed Dec 7, 2012
1 parent dc4777c commit 60a60dd
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 138 deletions.
38 changes: 19 additions & 19 deletions NUI/Core/NUIAppearance.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ @implementation NUIAppearance

+ (void)initializeWithStylesheet:(NSString *)stylesheet
{
[NUISettings loadStylesheet:stylesheet];
[STYLESHEET loadStylesheet:stylesheet];

[self initUINavigationBar];
[self initUIBarButtonItem];
Expand All @@ -29,16 +29,16 @@ + (void)initUINavigationBar
[[UINavigationBar appearance] setTitleTextAttributes:titleTextAttributes];
}

if ([NUISettings hasProperty:@"background-image" withClass:ui_class_name]) {
[[UINavigationBar appearance] setBackgroundImage:[NUISettings getImage:@"background-image" withClass:ui_class_name] forBarMetrics:UIBarMetricsDefault];
if ([STYLESHEET hasProperty:@"background-image" withClass:ui_class_name]) {
[[UINavigationBar appearance] setBackgroundImage:[STYLESHEET getImage:@"background-image" withClass:ui_class_name] forBarMetrics:UIBarMetricsDefault];
}

if ([NUISettings hasProperty:@"background-tint-color" withClass:ui_class_name]) {
[[UINavigationBar appearance] setTintColor:[NUISettings getColor:@"background-tint-color" withClass:ui_class_name]];
if ([STYLESHEET hasProperty:@"background-tint-color" withClass:ui_class_name]) {
[[UINavigationBar appearance] setTintColor:[STYLESHEET getColor:@"background-tint-color" withClass:ui_class_name]];
}

if ([NUISettings hasProperty:@"background-color" withClass:ui_class_name]) {
[[UINavigationBar appearance] setBackgroundImage:[NUISettings getImageFromColor:@"background-color" withClass:ui_class_name] forBarMetrics:UIBarMetricsDefault];
if ([STYLESHEET hasProperty:@"background-color" withClass:ui_class_name]) {
[[UINavigationBar appearance] setBackgroundImage:[STYLESHEET getImageFromColor:@"background-color" withClass:ui_class_name] forBarMetrics:UIBarMetricsDefault];
}

}
Expand All @@ -55,31 +55,31 @@ + (void)initUIBarButtonItem
[[ui_class appearance] setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
}

if ([NUISettings hasProperty:@"background-color" withClass:ui_class_name]) {
UIImage *backgroundColorImage = [NUIGraphics barButtonWithColor:[NUISettings getColor:@"background-color" withClass:ui_class_name]];
if ([STYLESHEET hasProperty:@"background-color" withClass:ui_class_name]) {
UIImage *backgroundColorImage = [NUIGraphics barButtonWithColor:[STYLESHEET getColor:@"background-color" withClass:ui_class_name]];
[[UIBarButtonItem appearance] setBackgroundImage:backgroundColorImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}

if ([NUISettings hasProperty:@"background-tint-color" withClass:ui_class_name]) {
[[ui_class appearance] setTintColor:[NUISettings getColor:@"background-tint-color" withClass:ui_class_name]];
if ([STYLESHEET hasProperty:@"background-tint-color" withClass:ui_class_name]) {
[[ui_class appearance] setTintColor:[STYLESHEET getColor:@"background-tint-color" withClass:ui_class_name]];
}

if ([NUISettings hasProperty:@"background-image" withClass:ui_class_name]) {
[[ui_class appearance] setBackgroundImage:[NUISettings getImage:@"background-image" withClass:ui_class_name] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
if ([STYLESHEET hasProperty:@"background-image" withClass:ui_class_name]) {
[[ui_class appearance] setBackgroundImage:[STYLESHEET getImage:@"background-image" withClass:ui_class_name] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}

NSString *ui_back_class_name = @"UIBackBarButtonItem";

if ([NUISettings hasProperty:@"background-color" withClass:ui_back_class_name]) {
UIImage *backBackgroundColorImage = [NUIGraphics backButtonWithColor:[NUISettings getColor:@"background-color" withClass:ui_back_class_name]];
if ([STYLESHEET hasProperty:@"background-color" withClass:ui_back_class_name]) {
UIImage *backBackgroundColorImage = [NUIGraphics backButtonWithColor:[STYLESHEET getColor:@"background-color" withClass:ui_back_class_name]];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backBackgroundColorImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
} else if ([NUISettings hasProperty:@"background-color" withClass:ui_class_name]) {
UIImage *backBackgroundColorImage = [NUIGraphics backButtonWithColor:[NUISettings getColor:@"background-color" withClass:ui_class_name]];
} else if ([STYLESHEET hasProperty:@"background-color" withClass:ui_class_name]) {
UIImage *backBackgroundColorImage = [NUIGraphics backButtonWithColor:[STYLESHEET getColor:@"background-color" withClass:ui_class_name]];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backBackgroundColorImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}

if ([NUISettings hasProperty:@"background-image" withClass:ui_back_class_name]) {
[[ui_class appearance] setBackButtonBackgroundImage:[NUISettings getImage:@"background-image" withClass:ui_back_class_name] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
if ([STYLESHEET hasProperty:@"background-image" withClass:ui_back_class_name]) {
[[ui_class appearance] setBackButtonBackgroundImage:[STYLESHEET getImage:@"background-image" withClass:ui_back_class_name] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}

}
Expand Down
26 changes: 14 additions & 12 deletions NUI/Core/NUISettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@
#import "NUIConverter.h"
#import "NUIStyleParser.h"

#define STYLESHEET [NUISettings instance]

@interface NUISettings : NSObject

#pragma mark - Initialization
+ (void)loadStylesheet:(NSString*)name;
+ (NUISettings*)instance;
- (void)loadStylesheet:(NSString*)name;

#pragma mark - Public
+ (BOOL)hasProperty:(NSString*)property withClass:(NSString*)class_name;
+ (id)get:(NSString*)property withClass:(NSString*)class_name;
+ (BOOL)getBoolean:(NSString*)property withClass:(NSString*)class_name;
+ (float)getFloat:(NSString*)property withClass:(NSString*)class_name;
+ (CGSize)getSize:(NSString*)property withClass:(NSString*)class_name;
+ (UIOffset)getOffset:(NSString*)property withClass:(NSString*)class_name;
+ (UITextBorderStyle)getBorderStyle:(NSString*)property withClass:(NSString*)class_name;
+ (UIColor*)getColor:(NSString*)property withClass:(NSString*)class_name;
+ (UIColor*)getColorFromImage:(NSString*)property withClass:(NSString*)class_name;
+ (UIImage*)getImage:(NSString*)property withClass:(NSString*)class_name;
+ (UIImage*)getImageFromColor:(NSString*)property withClass:(NSString*)class_name;
- (BOOL)hasProperty:(NSString*)property withClass:(NSString*)class_name;
- (id)get:(NSString*)property withClass:(NSString*)class_name;
- (BOOL)getBoolean:(NSString*)property withClass:(NSString*)class_name;
- (float)getFloat:(NSString*)property withClass:(NSString*)class_name;
- (CGSize)getSize:(NSString*)property withClass:(NSString*)class_name;
- (UIOffset)getOffset:(NSString*)property withClass:(NSString*)class_name;
- (UITextBorderStyle)getBorderStyle:(NSString*)property withClass:(NSString*)class_name;
- (UIColor*)getColor:(NSString*)property withClass:(NSString*)class_name;
- (UIColor*)getColorFromImage:(NSString*)property withClass:(NSString*)class_name;
- (UIImage*)getImage:(NSString*)property withClass:(NSString*)class_name;
- (UIImage*)getImageFromColor:(NSString*)property withClass:(NSString*)class_name;

@end
38 changes: 19 additions & 19 deletions NUI/Core/NUISettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ @implementation NUISettings
static NUISettings *singleton;


+ (void)loadStylesheet:(NSString *)name
- (void)loadStylesheet:(NSString *)name
{
self.instance.stylesheet = [[NUIStyleParser new] getStylesFromFile:name];
self.stylesheet = [[NUIStyleParser new] getStylesFromFile:name];
}

+ (BOOL)hasProperty:(NSString*)property withExplicitClass:(NSString*)class_name
- (BOOL)hasProperty:(NSString*)property withExplicitClass:(NSString*)class_name
{
NSDictionary *ruleSet = self.instance.stylesheet[class_name];
NSDictionary *ruleSet = self.stylesheet[class_name];
if (ruleSet == nil || ruleSet[property] == nil) {
return NO;
}
return YES;
}

+ (BOOL)hasProperty:(NSString*)property withClass:(NSString*)class_name
- (BOOL)hasProperty:(NSString*)property withClass:(NSString*)class_name
{
NSArray *classes = [self getClasses:class_name];
for (NSString *inherited_class in classes) {
Expand All @@ -42,13 +42,13 @@ + (BOOL)hasProperty:(NSString*)property withClass:(NSString*)class_name
return NO;
}

+ (id)get:(NSString*)property withExplicitClass:(NSString*)class_name
- (id)get:(NSString*)property withExplicitClass:(NSString*)class_name
{
NSDictionary *ruleSet = self.instance.stylesheet[class_name];
NSDictionary *ruleSet = self.stylesheet[class_name];
return ruleSet[property];
}

+ (id)get:(NSString*)property withClass:(NSString*)class_name
- (id)get:(NSString*)property withClass:(NSString*)class_name
{
NSArray *classes = [self getClasses:class_name];
for (NSString *inherited_class in classes) {
Expand All @@ -59,52 +59,52 @@ + (id)get:(NSString*)property withClass:(NSString*)class_name
return nil;
}

+ (BOOL)getBoolean:(NSString*)property withClass:(NSString*)class_name
- (BOOL)getBoolean:(NSString*)property withClass:(NSString*)class_name
{
return [NUIConverter toBoolean:[self get:property withClass:class_name]];
}

+ (float)getFloat:(NSString*)property withClass:(NSString*)class_name
{
- (float)getFloat:(NSString*)property withClass:(NSString*)class_name
{
return [NUIConverter toFloat:[self get:property withClass:class_name]];
}

+ (CGSize)getSize:(NSString*)property withClass:(NSString*)class_name
- (CGSize)getSize:(NSString*)property withClass:(NSString*)class_name
{
return [NUIConverter toSize:[self get:property withClass:class_name]];
}

+ (UIOffset)getOffset:(NSString*)property withClass:(NSString*)class_name
- (UIOffset)getOffset:(NSString*)property withClass:(NSString*)class_name
{
return [NUIConverter toOffset:[self get:property withClass:class_name]];
}

+ (UITextBorderStyle)getBorderStyle:(NSString*)property withClass:(NSString*)class_name
- (UITextBorderStyle)getBorderStyle:(NSString*)property withClass:(NSString*)class_name
{
return [NUIConverter toBorderStyle:[self get:property withClass:class_name]];
}

+ (UIColor*)getColor:(NSString*)property withClass:(NSString*)class_name
- (UIColor*)getColor:(NSString*)property withClass:(NSString*)class_name
{
return [NUIConverter toColor:[self get:property withClass:class_name]];
}

+ (UIColor*)getColorFromImage:(NSString*)property withClass:(NSString*)class_name
- (UIColor*)getColorFromImage:(NSString*)property withClass:(NSString*)class_name
{
return [NUIConverter toColorFromImageName:[self get:property withClass:class_name]];
}

+ (UIImage*)getImageFromColor:(NSString*)property withClass:(NSString*)class_name
- (UIImage*)getImageFromColor:(NSString*)property withClass:(NSString*)class_name
{
return [NUIConverter toImageFromColorName:[self get:property withClass:class_name]];
}

+ (UIImage*)getImage:(NSString*)property withClass:(NSString*)class_name
- (UIImage*)getImage:(NSString*)property withClass:(NSString*)class_name
{
return [NUIConverter toImageFromImageName:[self get:property withClass:class_name]];
}

+ (NSArray*)getClasses:(NSString*)class_name
- (NSArray*)getClasses:(NSString*)class_name
{
NSArray *classes = [[[class_name componentsSeparatedByString: @":"] reverseObjectEnumerator] allObjects];
return classes;
Expand Down
16 changes: 8 additions & 8 deletions NUI/Core/NUIUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ + (NSDictionary*)titleTextAttributesForClass:(NSString*)class_name
{
NSMutableDictionary *titleTextAttributes = [NSMutableDictionary dictionary];

if ([NUISettings hasProperty:@"font-name" withClass:class_name]) {
[titleTextAttributes setObject:[UIFont fontWithName:[NUISettings get:@"font-name" withClass:class_name] size:[NUISettings getFloat:@"font-size" withClass:class_name]] forKey:UITextAttributeFont];
if ([STYLESHEET hasProperty:@"font-name" withClass:class_name]) {
[titleTextAttributes setObject:[UIFont fontWithName:[STYLESHEET get:@"font-name" withClass:class_name] size:[STYLESHEET getFloat:@"font-size" withClass:class_name]] forKey:UITextAttributeFont];
}

if ([NUISettings hasProperty:@"font-color" withClass:class_name]) {
[titleTextAttributes setObject:[NUISettings getColor:@"font-color" withClass:class_name] forKey:UITextAttributeTextColor];
if ([STYLESHEET hasProperty:@"font-color" withClass:class_name]) {
[titleTextAttributes setObject:[STYLESHEET getColor:@"font-color" withClass:class_name] forKey:UITextAttributeTextColor];
}

if ([NUISettings hasProperty:@"text-shadow-color" withClass:class_name]) {
[titleTextAttributes setObject:[NUISettings getColor:@"text-shadow-color" withClass:class_name] forKey:UITextAttributeTextShadowColor];
if ([STYLESHEET hasProperty:@"text-shadow-color" withClass:class_name]) {
[titleTextAttributes setObject:[STYLESHEET getColor:@"text-shadow-color" withClass:class_name] forKey:UITextAttributeTextShadowColor];
}

if ([NUISettings hasProperty:@"text-shadow-offset" withClass:class_name]) {
[titleTextAttributes setObject:[NSValue valueWithUIOffset:[NUISettings getOffset:@"text-shadow-offset" withClass:class_name]] forKey:UITextAttributeTextShadowOffset];
if ([STYLESHEET hasProperty:@"text-shadow-offset" withClass:class_name]) {
[titleTextAttributes setObject:[NSValue valueWithUIOffset:[STYLESHEET getOffset:@"text-shadow-offset" withClass:class_name]] forKey:UITextAttributeTextShadowOffset];
}

return titleTextAttributes;
Expand Down
12 changes: 6 additions & 6 deletions NUI/Core/Renderers/NUIBarButtonItemRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ @implementation NUIBarButtonItemRenderer
+ (void)render:(UIBarButtonItem*)item withClass:(NSString*)class_name
{

if ([NUISettings hasProperty:@"background-image" withClass:class_name]) {
[item setBackgroundImage:[NUISettings getImage:@"background-image" withClass:class_name] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
if ([STYLESHEET hasProperty:@"background-image" withClass:class_name]) {
[item setBackgroundImage:[STYLESHEET getImage:@"background-image" withClass:class_name] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}

if ([NUISettings hasProperty:@"background-tint-color" withClass:class_name]) {
[item setTintColor:[NUISettings getColor:@"background-tint-color" withClass:class_name]];
if ([STYLESHEET hasProperty:@"background-tint-color" withClass:class_name]) {
[item setTintColor:[STYLESHEET getColor:@"background-tint-color" withClass:class_name]];
}
if ([NUISettings hasProperty:@"background-color" withClass:class_name]) {
UIImage *backgroundColorImage = [NUIGraphics barButtonWithColor:[NUISettings getColor:@"background-color" withClass:class_name]];
if ([STYLESHEET hasProperty:@"background-color" withClass:class_name]) {
UIImage *backgroundColorImage = [NUIGraphics barButtonWithColor:[STYLESHEET getColor:@"background-color" withClass:class_name]];
[item setBackgroundImage:backgroundColorImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}

Expand Down
Loading

0 comments on commit 60a60dd

Please sign in to comment.