Skip to content

Commit

Permalink
Allow escaping of ScionTags.
Browse files Browse the repository at this point in the history
Unify NSString and URL convenience methods
  • Loading branch information
codeon-nat committed Aug 20, 2015
1 parent 1726aa9 commit ef90323
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 169 deletions.
17 changes: 17 additions & 0 deletions RELEASENOTES
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
1852.0

*** API change ***

Redesigned the "convenience interface". Sorry but I just disliked the
proliferation of code, that separated NSURL and NSString by type. I used the
power of ObjC and simplified this without having to resort to degenerics ;)
In other words the +descriptionWithTemplateURL: method family is gone, just use
+descriptionWithTemplateFile: with either NSString or NSURL.

I apparently goofed up the documentation in 1851 and made an incompatible change
so that mulle-scion choked up on its own documentation templates. Ahem. That
has been fixed, so that MulleScion now skips all scion tags, that are
immediately _followed_ by a backtick ` or a backquote \. This ought to be
harmless in my opinion, but results may vary.


1851.0

*** BIG CHANGE!!! FILTER REDESIGNED ***
Expand Down
40 changes: 17 additions & 23 deletions src/MulleScion.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
#import "MulleScionParser.h"
#import "MulleScionPrintingException.h"

@protocol MulleScionStringOrURL
@end

@interface NSString (MulleScionStringOrURL) <MulleScionStringOrURL>
@end

@interface NSURL (MulleScionStringOrURL) <MulleScionStringOrURL>
@end

/*
* The convenience interface. If you don't want to think, use this:
Expand All @@ -57,44 +65,30 @@
*/
@interface MulleScionTemplate ( Convenience)

- (id) initWithFile:(NSString *) fileName; // template or archive
- (id) initWithFile:(NSString *) fileName; // template or archive

- (id) initWithContentsOfFile:(NSString *) fileName; // template
- (id) initWithContentsOfFile:(NSObject <MulleScionStringOrURL> *) fileName;

- (NSString *) descriptionWithDataSource:(id) dataSource
localVariables:(NSDictionary *) locals;

+ (NSString *) descriptionWithTemplateFile:(NSString *) fileName
+ (NSString *) descriptionWithTemplateFile:(NSObject <MulleScionStringOrURL> *) location
dataSource:(id <MulleScionDataSource>) dataSource;
+ (NSString *) descriptionWithTemplateURL:(NSURL *) url
dataSource:(id <MulleScionDataSource>) dataSource;

+ (NSString *) descriptionWithTemplateFile:(NSString *) fileName
+ (NSString *) descriptionWithTemplateFile:(NSObject <MulleScionStringOrURL> *) location
dataSource:(id <MulleScionDataSource>) dataSource
localVariables:(NSDictionary *) locals;
+ (NSString *) descriptionWithTemplateURL:(NSURL *) url
dataSource:(id <MulleScionDataSource>) dataSource
localVariables:(NSDictionary *) locals;

+ (NSString *) descriptionWithTemplateFile:(NSString *) fileName
propertyListFile:(NSString *) plistFileName
localVariables:(NSDictionary *) locals;
+ (NSString *) descriptionWithTemplateURL:(NSURL *) url
propertyListURL:(NSURL *) plistUrl
+ (NSString *) descriptionWithTemplateFile:(NSObject <MulleScionStringOrURL> *) fileName
propertyListFile:(NSObject <MulleScionStringOrURL> *) plistFileName
localVariables:(NSDictionary *) locals;

+ (NSString *) descriptionWithTemplateFile:(NSString *) fileName
propertyListFile:(NSString *) plistFileName;
+ (NSString *) descriptionWithTemplateURL:(NSURL *) url
propertyListURL:(NSURL *) plistUrl;
+ (NSString *) descriptionWithTemplateFile:(NSObject <MulleScionStringOrURL> *) fileName
propertyListFile:(NSObject <MulleScionStringOrURL> *) plistFileName;


+ (BOOL) writeToOutput:(id <MulleScionOutput>) output
templateFile:(NSString *) fileName
dataSource:(id <MulleScionDataSource>) dataSource
localVariables:(NSDictionary *) locals;
+ (BOOL) writeToOutput:(id <MulleScionOutput>) output
templateURL:(NSURL *) url
templateFile:(NSObject <MulleScionStringOrURL> *) fileName
dataSource:(id <MulleScionDataSource>) dataSource
localVariables:(NSDictionary *) locals;

Expand Down
153 changes: 37 additions & 116 deletions src/MulleScion.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,13 @@
@implementation MulleScionTemplate ( Convenience)

+ (BOOL) writeToOutput:(id <MulleScionOutput>) output
templateURL:(NSURL *) url
templateFile:(NSObject <MulleScionStringOrURL> *) fileName
dataSource:(id <MulleScionDataSource>) dataSource
localVariables:(NSDictionary *) locals
{
MulleScionTemplate *template;

template = [[[MulleScionTemplate alloc] initWithContentsOfURL:url] autorelease];
if( ! template)
return( NO);

[template writeToOutput:output
dataSource:dataSource
localVariables:locals];

return( YES);
}


+ (BOOL) writeToOutput:(id <MulleScionOutput>) output
templateFile:(NSString *) fileName
dataSource:(id <MulleScionDataSource>) dataSource
localVariables:(NSDictionary *) locals
{
MulleScionTemplate *template;

template = [[[MulleScionTemplate alloc] initWithFile:fileName] autorelease];
template = [[[MulleScionTemplate alloc] initWithContentsOfFile:fileName] autorelease];
if( ! template)
return( NO);

Expand All @@ -89,21 +70,7 @@ + (BOOL) writeToOutput:(id <MulleScionOutput>) output
}


+ (NSString *) descriptionWithTemplateURL:(NSURL *) url
dataSource:(id <MulleScionDataSource>) dataSource
localVariables:(NSDictionary *) locals
{
MulleScionTemplate *template;

template = [[[MulleScionTemplate alloc] initWithContentsOfURL:url] autorelease];
if( ! template)
return( nil);
return( [template descriptionWithDataSource:dataSource
localVariables:locals]);
}


+ (NSString *) descriptionWithTemplateFile:(NSString *) fileName
+ (NSString *) descriptionWithTemplateFile:(NSObject <MulleScionStringOrURL> *) fileName
dataSource:(id <MulleScionDataSource>) dataSource
localVariables:(NSDictionary *) locals
{
Expand All @@ -117,7 +84,7 @@ + (NSString *) descriptionWithTemplateFile:(NSString *) fileName
}


+ (NSString *) descriptionWithTemplateFile:(NSString *) fileName
+ (NSString *) descriptionWithTemplateFile:(NSObject <MulleScionStringOrURL> *) fileName
dataSource:(id <MulleScionDataSource>) dataSource
{
return( [self descriptionWithTemplateFile:fileName
Expand All @@ -126,49 +93,20 @@ + (NSString *) descriptionWithTemplateFile:(NSString *) fileName
}


+ (NSString *) descriptionWithTemplateURL:(NSURL *) fileName
dataSource:(id <MulleScionDataSource>) dataSource
{
return( [self descriptionWithTemplateURL:fileName
dataSource:dataSource
localVariables:nil]);
}


static id acquirePropertyList( NSString *s)
static id acquirePropertyList( NSObject <MulleScionStringOrURL> *s)
{
NSData *data;
NSString *error;
id plist;

data = [NSData dataWithContentsOfFile:s];
if( ! data)
{
NSLog( @"failed to open: %@", s);
return( data);
}

error = nil;
plist = [NSPropertyListSerialization propertyListFromData:data
mutabilityOption:NSPropertyListImmutable
format:NULL
errorDescription:&error];
if( ! plist)
NSLog( @"property list failure: %@", error);
return( plist);
}


static id acquirePropertyListURL( NSURL *url)
{
NSData *data;
NSString *error;
id plist;
if( [s isKindOfClass:[NSURL class]])
data = [NSData dataWithContentsOfURL:(NSURL *) s];
else
data = [NSData dataWithContentsOfFile:(NSString *) s];

data = [NSData dataWithContentsOfURL:url];
if( ! data)
{
NSLog( @"failed to open: %@", url);
NSLog( @"failed to open: %@", s);
return( data);
}

Expand All @@ -183,8 +121,8 @@ static id acquirePropertyListURL( NSURL *url)
}


+ (NSString *) descriptionWithTemplateFile:(NSString *) fileName
propertyListFile:(NSString *) plistFileName
+ (NSString *) descriptionWithTemplateFile:(NSObject <MulleScionStringOrURL> *) fileName
propertyListFile:(NSObject <MulleScionStringOrURL> *) plistFileName
localVariables:(NSDictionary *) locals
{
MulleScionTemplate *template;
Expand All @@ -193,62 +131,26 @@ + (NSString *) descriptionWithTemplateFile:(NSString *) fileName
template = [[[MulleScionTemplate alloc] initWithContentsOfFile:fileName] autorelease];
if( ! template)
return( nil);
plist = acquirePropertyList( plistFileName);
if( ! plist)
return( nil);
return( [template descriptionWithDataSource:plist
localVariables:(NSDictionary *) locals]);
}


+ (NSString *) descriptionWithTemplateURL:(NSURL *) url
propertyListURL:(NSURL *) plistUrl
localVariables:(NSDictionary *) locals
{
MulleScionTemplate *template;
id plist;

template = [[[MulleScionTemplate alloc] initWithContentsOfURL:url] autorelease];
if( ! template)
return( nil);
plist = acquirePropertyListURL( plistUrl);
plist = acquirePropertyList( plistFileName);
if( ! plist)
return( nil);
return( [template descriptionWithDataSource:plist
localVariables:locals]);
}


+ (NSString *) descriptionWithTemplateFile:(NSString *) fileName
propertyListFile:(NSString *) plistFileName

+ (NSString *) descriptionWithTemplateFile:(NSObject <MulleScionStringOrURL> *) fileName
propertyListFile:(NSObject <MulleScionStringOrURL> *) plistFileName
{
return( [self descriptionWithTemplateFile:fileName
propertyListFile:plistFileName
localVariables:nil]);
}


+ (NSString *) descriptionWithTemplateURL:(NSURL *) url
propertyListURL:(NSURL *) plistUrl
{
return( [self descriptionWithTemplateURL:url
propertyListURL:plistUrl
localVariables:nil]);
}


- (id) initWithFile:(NSString *) fileName
{
if( [MulleScionTemplate isArchivedTemplatePath:fileName])
self = [self initWithContentsOfArchive:fileName];
else
self = [self initWithContentsOfFile:fileName];

return( self);
}


- (id) initWithContentsOfFile:(NSString *) fileName
- (id) _initWithContentsOfFile:(NSString *) fileName
{
MulleScionParser *parser;
#ifndef DONT_HAVE_MULLE_SCION_CACHING
Expand Down Expand Up @@ -289,7 +191,7 @@ - (id) initWithContentsOfFile:(NSString *) fileName
}


- (id) initWithContentsOfURL:(NSURL *) url
- (id) _initWithContentsOfURL:(NSURL *) url
{
MulleScionParser *parser;
#ifndef DONT_HAVE_MULLE_SCION_CACHING
Expand Down Expand Up @@ -330,6 +232,25 @@ - (id) initWithContentsOfURL:(NSURL *) url
}


- (id) initWithContentsOfFile:(NSObject <MulleScionStringOrURL> *) fileName
{
if( [fileName isKindOfClass:[NSURL class]])
return( [self _initWithContentsOfURL:(NSURL *) fileName]);
return( [self _initWithContentsOfFile:(NSString *) fileName]);
}


- (id) initWithFile:(NSString *) fileName
{
if( [MulleScionTemplate isArchivedTemplatePath:fileName])
self = [self initWithContentsOfArchive:fileName];
else
self = [self _initWithContentsOfFile:fileName];

return( self);
}


static MulleScionPrinter *createPrinterWithDatasource( id dataSource)
{
// if( ! dataSource)
Expand Down
Loading

0 comments on commit ef90323

Please sign in to comment.