Permalink
Browse files

Refactor inline writing decisions across an instance & class method.

  • Loading branch information...
1 parent a84c9d5 commit 89aba474ea2ba3dddb868b37d3225ac8442f88ba @mikeabdullah mikeabdullah committed Jun 7, 2012
Showing with 14 additions and 5 deletions.
  1. +2 −2 KSHTMLWriter.m
  2. +5 −1 KSXMLWriter.h
  3. +7 −2 KSXMLWriter.m
View
4 KSHTMLWriter.m
@@ -421,7 +421,7 @@ - (BOOL)elementCanBeEmpty:(NSString *)tagName;
return NO;
}
-- (BOOL)canWriteElementInline:(NSString *)elementName;
++ (BOOL)shouldPrettyPrintElementInline:(NSString *)elementName;
{
switch ([elementName length])
{
@@ -488,7 +488,7 @@ - (BOOL)canWriteElementInline:(NSString *)elementName;
break;
}
- return [super canWriteElementInline:elementName];
+ return [super shouldPrettyPrintElementInline:elementName];
}
- (BOOL)validateElement:(NSString *)element;
View
6 KSXMLWriter.h
@@ -149,10 +149,14 @@
#pragma mark Inline Writing
+
- (BOOL)isWritingInline;
- (void)startWritingInline;
- (void)stopWritingInline;
-- (BOOL)canWriteElementInline:(NSString *)tagName;
+
+// Class method is a general rule; instance method takes into account current indent level etc.
+- (BOOL)canWriteElementInline:(NSString *)element;
++ (BOOL)shouldPrettyPrintElementInline:(NSString *)element;
#pragma mark String Encoding
View
9 KSXMLWriter.m
@@ -307,10 +307,15 @@ - (NSString *)validateAttribute:(NSString *)name value:(NSString *)value ofEleme
#pragma mark Elements Stack
-- (BOOL)canWriteElementInline:(NSString *)tagName;
+- (BOOL)canWriteElementInline:(NSString *)element;
{
// In standard XML, no elements can be inline, unless it's the start of the doc
- return (_inlineWritingLevel == 0);
+ return (_inlineWritingLevel == 0 || [[self class] shouldPrettyPrintElementInline:element]);
+}
+
++ (BOOL)shouldPrettyPrintElementInline:(NSString *)element;
+{
+ return NO;
}
- (NSArray *)openElements; { return [[_openElements copy] autorelease]; }

0 comments on commit 89aba47

Please sign in to comment.