Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added square marker style, added appledoc comments

  • Loading branch information...
commit f59d43cb794fa334deea0de3f4afcbc351558d2d 1 parent d65442a
@Cocoanetics authored
Showing with 123 additions and 39 deletions.
  1. +97 −9 Core/Source/DTCSSListStyle.h
  2. +26 −30 Core/Source/DTCSSListStyle.m
View
106 Core/Source/DTCSSListStyle.h
@@ -6,7 +6,9 @@
// Copyright 2011 Drobnik.com. All rights reserved.
//
-#import <Foundation/Foundation.h>
+/**
+ List Styles
+ */
typedef enum
{
@@ -16,6 +18,7 @@ typedef enum
DTCSSListStyleTypeDecimal,
DTCSSListStyleTypeDecimalLeadingZero,
DTCSSListStyleTypeDisc,
+ DTCSSListStyleTypeSquare,
DTCSSListStyleTypeUpperAlpha,
DTCSSListStyleTypeUpperLatin,
DTCSSListStyleTypeLowerAlpha,
@@ -26,6 +29,9 @@ typedef enum
DTCSSListStyleTypeInvalid = NSIntegerMax
} DTCSSListStyleType;
+/**
+ List Marker Positions
+ */
typedef enum
{
DTCSSListStylePositionInherit = 0,
@@ -34,25 +40,69 @@ typedef enum
DTCSSListStylePositionInvalid = NSIntegerMax
} DTCSSListStylePosition;
+
+/**
+ This class is the equivalent of `NSTextList` on Mac with the added handling of the marker position.
+ */
@interface DTCSSListStyle : NSObject
-@property (nonatomic, assign) BOOL inherit;
-@property (nonatomic, assign) DTCSSListStyleType type;
-@property (nonatomic, assign) DTCSSListStylePosition position;
-@property (nonatomic, copy) NSString *imageName;
-+ (DTCSSListStyle *)listStyleWithStyles:(NSDictionary *)styles;
-+ (DTCSSListStyle *)decimalListStyle;
-+ (DTCSSListStyle *)discListStyle;
-+ (DTCSSListStyle *)inheritedListStyle;
+/**
+ @name Getting Types from Strings
+ */
+/**
+ Convert a string into a list style type.
+
+ @param string The string to convert
+ */
+ (DTCSSListStyleType)listStyleTypeFromString:(NSString *)string;
+
+
+/**
+ Convert a string into a marker position.
+
+ @param string The string to convert
+ */
+ (DTCSSListStylePosition)listStylePositionFromString:(NSString *)string;
+/**
+ @name Creating List Styles
+ */
+
+/**
+ Creates a list style from the passed CSS style dictionary
+
+ @param styles A CSS style dictionary from which the construct a suitable list style
+ */
- (id)initWithStyles:(NSDictionary *)styles;
+/**
+ @name Working with CSS Styles
+ */
+
+/**
+ Update the receiver from the CSS styles dictionary passed
+
+ @param styles A dictionary of CSS styles.
+ */
+- (void)updateFromStyleDictionary:(NSDictionary *)styles;
+
+
+/**
+ @name Working with Prefixes
+ */
+
+
+/**
+ Returns the prefix for lists of the receiver's settings.
+
+ @param counter The counter value to use for ordered lists.
+ @returns The prefix string to prepend to list items.
+ */
- (NSString *)prefixWithCounter:(NSInteger)counter;
+
/**
@name Managing Item Numbering
*/
@@ -62,6 +112,7 @@ typedef enum
Sets the starting item number for the text list.
The default value is `1`. This value will be used only for ordered lists, and ignored in other cases.
+
@param itemNum The item number.
*/
- (void)setStartingItemNumber:(NSInteger)itemNum;
@@ -76,5 +127,42 @@ typedef enum
- (NSInteger)startingItemNumber;
+/**
+ @name Getting Information about Lists
+ */
+
+/**
+ Returns if the receiver is an ordered or unordered list
+
+ @returns `YES` if the receiver is ordered, `NO` if it is unordered
+ */
+- (BOOL)isOrdered;
+
+
+/**
+ If the list style is inherited.
+
+ @warn This is not implemented.
+ */
+@property (nonatomic, assign) BOOL inherit;
+
+
+/**
+ The type of the text list
+ */
+@property (nonatomic, assign) DTCSSListStyleType type;
+
+
+/**
+ The position of the marker in the prefix.
+ */
+@property (nonatomic, assign) DTCSSListStylePosition position;
+
+
+/**
+ The image name to use for the marker
+ */
+@property (nonatomic, copy) NSString *imageName;
+
@end
View
56 Core/Source/DTCSSListStyle.m
@@ -37,35 +37,6 @@ @implementation DTCSSListStyle
NSInteger _startingItemNumber;
}
-+ (DTCSSListStyle *)listStyleWithStyles:(NSDictionary *)styles
-{
- return [[DTCSSListStyle alloc] initWithStyles:styles];
-}
-
-+ (DTCSSListStyle *)decimalListStyle
-{
- DTCSSListStyle *style = [[DTCSSListStyle alloc] init];
- style.type = DTCSSListStyleTypeDecimal;
- style.position = DTCSSListStylePositionOutside;
- return style;
-}
-
-+ (DTCSSListStyle *)discListStyle
-{
- DTCSSListStyle *style = [[DTCSSListStyle alloc] init];
- style.type = DTCSSListStyleTypeDisc;
- style.position = DTCSSListStylePositionOutside;
- return style;
-}
-
-+ (DTCSSListStyle *)inheritedListStyle
-{
- DTCSSListStyle *style = [[DTCSSListStyle alloc] init];
- style.inherit = YES;
- return style;
-}
-
-
- (id)initWithStyles:(NSDictionary *)styles
{
self = [super init];
@@ -105,7 +76,11 @@ + (DTCSSListStyleType)listStyleTypeFromString:(NSString *)string
else if ([string isEqualToString:@"circle"])
{
return DTCSSListStyleTypeCircle;
- }
+ }
+ else if ([string isEqualToString:@"square"])
+ {
+ return DTCSSListStyleTypeSquare;
+ }
else if ([string isEqualToString:@"decimal"])
{
return DTCSSListStyleTypeDecimal;
@@ -315,6 +290,11 @@ - (NSString *)prefixWithCounter:(NSInteger)counter
token = @"\u25e6";
break;
}
+ case DTCSSListStyleTypeSquare:
+ {
+ token = @"\u25aa";
+ break;
+ }
case DTCSSListStyleTypeDecimal:
{
token = [NSString stringWithFormat:@"%d.", counter];
@@ -365,6 +345,22 @@ - (NSString *)prefixWithCounter:(NSInteger)counter
}
}
+- (BOOL)isOrdered
+{
+ switch (_type)
+ {
+ case DTCSSListStyleTypeDecimal:
+ case DTCSSListStyleTypeDecimalLeadingZero:
+ case DTCSSListStyleTypeUpperAlpha:
+ case DTCSSListStyleTypeUpperLatin:
+ case DTCSSListStyleTypeLowerAlpha:
+ case DTCSSListStyleTypeLowerLatin:
+ return YES;
+
+ default:
+ return NO;
+ }
+}
#pragma mark Properties
Please sign in to comment.
Something went wrong with that request. Please try again.