Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

-writeJavascriptWithContent:

  • Loading branch information...
commit 3bcec248afbb0a556fd1697a2fd8f32ca43c3252 1 parent 8c20ada
@mikeabdullah mikeabdullah authored
Showing with 11 additions and 3 deletions.
  1. +1 −0  KSHTMLWriter.h
  2. +10 −3 KSHTMLWriter.m
View
1  KSHTMLWriter.h
@@ -136,6 +136,7 @@ extern NSString *KSHTMLWriterDocTypeHTML_5;
- (void)writeJavascriptWithSrc:(NSString *)src encoding:(NSStringEncoding)encoding;
- (void)writeJavascriptWithSrc:(NSString *)src charset:(NSString *)charset;
- (void)writeJavascript:(NSString *)script useCDATA:(BOOL)useCDATA;
+- (void)writeJavascriptWithContent:(void (^)(void))content;
- (void)startJavascriptElementWithSrc:(NSString *)src; // src may be nil
// Like -startCDATA and -endCDATA, but wrapped in a javascript comment so don't risk tripping up a browser's interpreter
View
13 KSHTMLWriter.m
@@ -318,14 +318,21 @@ - (void)writeJavascriptWithSrc:(NSString *)src charset:(NSString *)charset; // s
- (void)writeJavascript:(NSString *)script useCDATA:(BOOL)useCDATA;
{
- [self startJavascriptElementWithSrc:nil];
- {{
+ [self writeJavascriptWithContent:^{
+
if (useCDATA) [self startJavascriptCDATA];
[self writeHTMLString:script];
if (useCDATA) [self endJavascriptCDATA];
[self increaseIndentationLevel]; // compensate for -decreaseIndentationLevel
- }}
+ }];
+}
+
+- (void)writeJavascriptWithContent:(void (^)(void))content;
+{
+ [self startJavascriptElementWithSrc:nil];
+ content();
+ [self increaseIndentationLevel]; // compensate for -decreaseIndentationLevel
[self endElement];
}
Please sign in to comment.
Something went wrong with that request. Please try again.