Skip to content

Commit

Permalink
Added documentation and rolled buildString into first call to generat…
Browse files Browse the repository at this point in the history
…edAttributedString
  • Loading branch information
odrobnik committed Jun 21, 2012
1 parent 00d135f commit 8f76cf7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
32 changes: 28 additions & 4 deletions Core/Source/DTHTMLAttributedStringBuilder.h
@@ -1,5 +1,5 @@
//
// DTHTMLDocument.h
// DTHTMLAttributedStringBuilder.h
// DTCoreText
//
// Created by Oliver Drobnik on 21.01.12.
Expand All @@ -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
9 changes: 7 additions & 2 deletions Core/Source/DTHTMLAttributedStringBuilder.m
Expand Up @@ -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)
Expand Down Expand Up @@ -83,7 +83,7 @@ - (void)dealloc
dispatch_release(_stringParsingGroup);
}

- (BOOL)buildString
- (BOOL)_buildString
{
// only with valid data
if (![_data length])
Expand Down Expand Up @@ -255,6 +255,11 @@ - (BOOL)buildString

- (NSAttributedString *)generatedAttributedString
{
if (!tmpString)
{
[self _buildString];
}

return tmpString;
}

Expand Down

0 comments on commit 8f76cf7

Please sign in to comment.