Skip to content
Browse files

Added documentation and rolled buildString into first call to generat…

…edAttributedString
  • Loading branch information...
1 parent 00d135f commit 8f76cf7724ef80e8aa9261adc8842b06e259f355 @odrobnik odrobnik committed Jun 21, 2012
Showing with 35 additions and 6 deletions.
  1. +28 −4 Core/Source/DTHTMLAttributedStringBuilder.h
  2. +7 −2 Core/Source/DTHTMLAttributedStringBuilder.m
View
32 Core/Source/DTHTMLAttributedStringBuilder.h
@@ -1,5 +1,5 @@
//
-// DTHTMLDocument.h
+// DTHTMLAttributedStringBuilder.h
// DTCoreText
//
// Created by Oliver Drobnik on 21.01.12.
@@ -12,16 +12,40 @@
typedef void(^DTHTMLAttributedStringBuilderWillFlushCallback)(DTHTMLElement *);
+
+/**
+ Class for building an `NSAttributedString` from an HTML document.
+ */
@interface DTHTMLAttributedStringBuilder : NSObject <DTHTMLParserDelegate>
-- (id)initWithHTML:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary **)dict;
+/**
+ @name Creating an Attributed String Builder
+ */
+
+/**
+ Initializes and returns a new `NSAttributedString` object from the HTML contained in the given object and base URL.
+ @param data The data in HTML format from which to create the attributed string.
+ @param options Specifies how the document should be loaded. Contains values described in “Option keys for importing documents.”
+ @param docAttributes Currently not in used.
+ @returns Returns an initialized object, or `nil` if the data can’t be decoded.
+ */
+- (id)initWithHTML:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary **)docAttributes;
+
-- (BOOL)buildString;
+/**
+ @name Generating Attributed Strings
+ */
+/**
+ Creates the attributed string when called the first time.
+ @returns An `NSAttributedString` representing the HTML document passed in the initializer.
+ */
- (NSAttributedString *)generatedAttributedString;
-// this block is called before the element is written to the output attributed string
+/**
+ This block is called before the element is written to the output attributed string
+ */
@property (nonatomic, copy) DTHTMLAttributedStringBuilderWillFlushCallback willFlushCallback;
@end
View
9 Core/Source/DTHTMLAttributedStringBuilder.m
@@ -55,7 +55,7 @@ @implementation DTHTMLAttributedStringBuilder
DTHTMLAttributedStringBuilderWillFlushCallback _willFlushCallback;
}
-- (id)initWithHTML:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary **)dict
+- (id)initWithHTML:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary **)docAttributes
{
self = [super init];
if (self)
@@ -83,7 +83,7 @@ - (void)dealloc
dispatch_release(_stringParsingGroup);
}
-- (BOOL)buildString
+- (BOOL)_buildString
{
// only with valid data
if (![_data length])
@@ -255,6 +255,11 @@ - (BOOL)buildString
- (NSAttributedString *)generatedAttributedString
{
+ if (!tmpString)
+ {
+ [self _buildString];
+ }
+
return tmpString;
}

0 comments on commit 8f76cf7

Please sign in to comment.
Something went wrong with that request. Please try again.