Browse code

ShouldFilterPlainText dazu, fixed main() usage output

Nat! authored on 17-08-2014 19:43:35
Showing 10 changed files
... ...
@@ -27,6 +27,11 @@ __FILTER__                      The currently installed filter chain
27 27
 __FILTER_STACK__                The previous filter chains
28 28
 __SELF_REPLACEMENT__            The object that the identifier 'self' gets 
29 29
                                 replaced with
30
+__SHOULD_FILTER_PLAINTEXT__     The filter will be applied to plain text (default 
31
+                                is YES, for Twig compatibility.)
32
+
33
+__ARGV__                        (Optional) command line arguments passed in 
34
+                                by mulle-scion
30 35
 
31 36
 Predefined Variables
32 37
 ====================
... ...
@@ -20,6 +20,14 @@ through the currently active filter.
20 20
 
21 21
 {% low=@"low" %}
22 22
 {% filter uppercaseString %}
23
-{% high = filter( low) %}
23
+   {% high = filter( low) %}
24 24
 {% endfilter %}
25 25
 {{ low }} -> {{ high }}
26
+
27
+Set the variable __SHOULD_FILTER_PLAINTEXT__ to NO to avoid filtering plaintext
28
+
29
+{% __SHOULD_FILTER_PLAINTEXT__ = NO %}
30
+{% filter uppercaseString %}
31
+  This won't get filtered, but {{ "this" }}. Convenient to wrap around HTML
32
+  code for example and setting the filter to htmlEscapedString.
33
+{% endfilter %}
... ...
@@ -140,15 +140,20 @@ static int   mulle_mongoose_begin_request( struct mg_connection *conn)
140 140
    int                 rval;
141 141
    NSData              *utf8Data;
142 142
    NSString            *string;
143
-   
143
+   NSMutableString     *tmp;
144
+
144 145
    pool   = [NSAutoreleasePool new];
145 146
 NS_DURING
146 147
    rval   = _mulle_mongoose_begin_request( conn);
147 148
 NS_HANDLER
148 149
    string = [[localException description] htmlEscapedString];
149
-   string = [string stringByReplacingOccurrencesOfString:@"\n"
150
-                                              withString:@"<BR>"];
151
-   utf8Data = [string dataUsingEncoding:NSUTF8StringEncoding];
150
+   tmp    = [[string mutableCopy] autorelease];
151
+   [tmp replaceOccurrencesOfString:@"\n"
152
+                        withString:@"<BR>"
153
+                           options:NSLiteralSearch
154
+                             range:NSMakeRange( 0, [tmp length])];
155
+
156
+   utf8Data = [tmp dataUsingEncoding:NSUTF8StringEncoding];
152 157
    mulle_write_response( conn, (void *) [utf8Data bytes], [utf8Data length]);
153 158
    rval = 1;
154 159
 NS_ENDHANDLER
... ...
@@ -181,8 +181,7 @@
181 181
    if( [identifier isEqualToString:@"filter"])
182 182
    {
183 183
       NSString   *string;
184
-      id         value;
185
-      
184
+
186 185
       MulleScionPrintingValidateArgumentCount( arguments, 1, locals);
187 186
       value  = MulleScionPrintingValidatedArgument( arguments, 0, Nil, locals);
188 187
       string = [value mulleScionDescriptionWithLocalVariables:locals];
... ...
@@ -53,6 +53,7 @@ static BOOL fileExists( NSString *fileName)
53 53
    return( [manager fileExistsAtPath:path]);
54 54
 }
55 55
 
56
+
56 57
 - (id) initWithContentsOfFile:(NSString *) fileName
57 58
                       options:(NSDictionary *) info
58 59
 {
... ...
@@ -54,6 +54,7 @@ extern NSString   *MulleScionCurrentLineKey;
54 54
 extern NSString   *MulleScionCurrentFunctionKey;
55 55
 extern NSString   *MulleScionArgumentsKey;
56 56
 extern NSString   *MulleScionVersionKey;
57
+extern NSString   *MulleScionShouldFilterPlainTextKey;
57 58
 
58 59
 extern NSString   *MulleScionForOpenerKey;
59 60
 extern NSString   *MulleScionForSeparatorKey;
... ...
@@ -71,6 +71,7 @@ NSString   *MulleScionCurrentFileKey          = @"__FILE__";
71 71
 NSString   *MulleScionPreviousFilesKey        = @"__FILE_STACK__";
72 72
 NSString   *MulleScionCurrentFilterKey        = @"__FILTER__";
73 73
 NSString   *MulleScionPreviousFiltersKey      = @"__FILTER_STACK__";
74
+NSString   *MulleScionShouldFilterPlainTextKey = @"__SHOULD_FILTER_PLAINTEXT__";
74 75
 NSString   *MulleScionCurrentFunctionKey      = @"__FUNCTION__";
75 76
 NSString   *MulleScionCurrentLineKey          = @"__LINE__";
76 77
 NSString   *MulleScionRenderOutputKey         = @"__OUTPUT__";
... ...
@@ -311,7 +312,6 @@ void   MulleScionRenderString( NSString *value,
311 312
 
312 313
 @implementation MulleScionTemplate ( Printing)
313 314
 
314
-
315 315
 static void   initLineNumber( NSMutableDictionary *locals)
316 316
 {
317 317
    MulleMutableLineNumber   *nr;
... ...
@@ -392,6 +392,8 @@ static void   updateLineNumber( MulleScionObject *self, NSMutableDictionary *loc
392 392
    // trusted (writing OK, reading ? your choice!)
393 393
    //
394 394
    updateLineNumber( self, locals);
395
+   [locals setObject:[NSNumber numberWithBool:YES]
396
+              forKey:MulleScionShouldFilterPlainTextKey];
395 397
    [locals setObject:s
396 398
               forKey:MulleScionRenderOutputKey];
397 399
    [locals setObject:value_
... ...
@@ -426,8 +428,10 @@ static void   updateLineNumber( MulleScionObject *self, NSMutableDictionary *loc
426 428
    TRACE_RENDER( self, s, locals, dataSource);
427 429
 
428 430
    updateLineNumber( self, locals);
429
-   MulleScionRenderString( value_, s, locals, dataSource);
430
-   
431
+   if( [[locals objectForKey:MulleScionShouldFilterPlainTextKey] boolValue])
432
+      MulleScionRenderString( value_, s, locals, dataSource);
433
+   else
434
+      [s appendString:value_];
431 435
    return( self->next_);
432 436
 }
433 437
 
... ...
@@ -615,8 +615,9 @@ static id   newMulleScionValueObject( Class self, id value, NSUInteger nr)
615 615
    case MulleScionGreaterThan          : return( @">");
616 616
    case MulleScionLessThanOrEqualTo    : return( @"<=");
617 617
    case MulleScionGreaterThanOrEqualTo : return( @">=");
618
-   case MulleScionNoComparison         : return( @"???");  // should never happen!
618
+   case MulleScionNoComparison         : break;  // should never happen!
619 619
    }
620
+   return( @"???");
620 621
 }
621 622
 
622 623
 @end
... ...
@@ -54,7 +54,7 @@
54 54
 #endif
55 55
 
56 56
 
57
-@implementation MulleScionTemplate ( NSCoding)
57
+@implementation MulleScionTemplate ( CompressedArchive)
58 58
 
59 59
 typedef struct
60 60
 {
... ...
@@ -198,12 +198,13 @@ static NSString  *processName( void)
198 198
 
199 199
 static void   usage( void)
200 200
 {
201
-   fprintf( stderr, "%s [-w] <template> [bundle|propertylist|-|none] [-|outputfile] [arguments]\n", [processName() cString]);
201
+   fprintf( stderr, "%s [-w] <template> [bundle|plist|-|none] [-|outputfile] [arguments]\n", [processName() cString]);
202 202
    fprintf( stderr, "v%s\n", MulleScionFrameworkVersion);
203
-   fprintf( stderr, "\t-w: start webserver for /tmp/MulleScionDox\n\n"
204
-   "\ttemplate: a MulleScion template\n"
205
-   "\tbundle: a NSBundle. It's NSPrincipalClass will be used as the datasource\n"
206
-   "\tplist: any kind of plist(5)\n\n"
203
+   fprintf( stderr,
204
+   "\t-w       : start webserver for /tmp/MulleScionDox\n\n"
205
+   "\ttemplate : a MulleScion template\n"
206
+   "\tbundle   : a NSBundle. It's NSPrincipalClass will be used as the datasource\n"
207
+   "\tplist    : any kind of property list, see: plist(5)\n\n"
207 208
    "\targuments: a list of arguments to be made available to the template via __ARGV__\n"
208 209
    );
209 210
 }