forked from mattgemmell/MGTemplateEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppController.m
77 lines (55 loc) · 2.17 KB
/
AppController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// AppController.m
// MGTemplateEngine
//
// Created by Matt Gemmell on 19/05/2008.
// Copyright 2008 Instinctive Code. All rights reserved.
//
#import "AppController.h"
#import "MGTemplateEngine.h"
#import "ICUTemplateMatcher.h"
@implementation AppController
- (void)awakeFromNib
{
// Set up template engine with your chosen matcher.
MGTemplateEngine *engine = [MGTemplateEngine templateEngine];
[engine setDelegate:self];
[engine setMatcher:[ICUTemplateMatcher matcherWithTemplateEngine:engine]];
// Set up any needed global variables.
// Global variables persist for the life of the engine, even when processing multiple templates.
[engine setObject:@"Hi there!" forKey:@"hello"];
// Get path to template.
NSString *templatePath = [[NSBundle mainBundle] pathForResource:@"sample_template" ofType:@"txt"];
// Set up some variables for this specific template.
NSDictionary *variables = [NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObjects:
@"matt", @"iain", @"neil", @"chris", @"steve", nil], @"guys",
[NSDictionary dictionaryWithObjectsAndKeys:@"baz", @"bar", nil], @"foo",
nil];
// Process the template and display the results.
NSString *result = [engine processTemplateInFileAtPath:templatePath withVariables:variables];
NSLog(@"Processed template:\r%@", result);
[NSApp terminate:self];
}
// ****************************************************************
//
// Methods below are all optional MGTemplateEngineDelegate methods.
//
// ****************************************************************
- (void)templateEngine:(MGTemplateEngine *)engine blockStarted:(NSDictionary *)blockInfo
{
//NSLog(@"Started block %@", [blockInfo objectForKey:BLOCK_NAME_KEY]);
}
- (void)templateEngine:(MGTemplateEngine *)engine blockEnded:(NSDictionary *)blockInfo
{
//NSLog(@"Ended block %@", [blockInfo objectForKey:BLOCK_NAME_KEY]);
}
- (void)templateEngineFinishedProcessingTemplate:(MGTemplateEngine *)engine
{
//NSLog(@"Finished processing template.");
}
- (void)templateEngine:(MGTemplateEngine *)engine encounteredError:(NSError *)error isContinuing:(BOOL)continuing;
{
NSLog(@"Template error: %@", error);
}
@end