Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 610 lines (573 sloc) 26.178 kB
5e5ea55 @groue v1.13.0
authored
1 // The MIT License
2 //
3 // Copyright (c) 2012 Gwendal Roué
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22
23 #import <Foundation/Foundation.h>
24 #import "GRMustacheAvailabilityMacros.h"
25 #import "GRMustache.h"
26
27 @class GRMustacheTemplate;
28 @class GRMustacheTemplateRepository;
29
459f57b @groue v4.1.0
authored
30 /**
0d322bc @groue v4.1.1
authored
31 * The protocol for a GRMustacheTemplateRepository's dataSource.
32 *
33 * The dataSource's responsability is to provide Mustache template strings for
34 * template and partial names.
35 *
36 * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/template_repositories.md
37 *
38 * @see GRMustacheTemplateRepository
39 *
40 * @since v1.13
459f57b @groue v4.1.0
authored
41 */
5e5ea55 @groue v1.13.0
authored
42 @protocol GRMustacheTemplateRepositoryDataSource <NSObject>
43 @required
459f57b @groue v4.1.0
authored
44
0d322bc @groue v4.1.1
authored
45
46 ////////////////////////////////////////////////////////////////////////////////
47 /// @name Building Template IDs from Template Names
48 ////////////////////////////////////////////////////////////////////////////////
49
459f57b @groue v4.1.0
authored
50 /**
0d322bc @groue v4.1.1
authored
51 * Returns a template ID, that is to say an object that uniquely identifies a
52 * template or a template partial.
53 *
54 * The class of this ID is opaque: your implementation of a
55 * GRMustacheTemplateRepositoryDataSource would define, for itself, what kind of
56 * object would identity a template or a partial.
57 *
58 * For instance, a file-based data source may use NSString objects containing
59 * paths to the templates.
60 *
61 * You should try to choose "human-readable" template IDs. That is because
62 * template IDs are embedded in the description of errors that may happen during
63 * a template processing, in order to help the library user locate, and fix, the
64 * faulting template.
65 *
66 * Whenever relevant, template and partial hierarchies are supported via the
67 * _baseTemplateID_ parameter: it contains the template ID of the enclosing
68 * template, or nil when the data source is asked for a template ID for a
69 * partial that is referred from a raw template string (see
70 * [GRMustacheTemplateRepository templateFromString:error:]).
71 *
72 * Not all data sources have to implement hierarchies: they can simply ignore
73 * this parameter.
74 *
75 * The returned value can be nil: the library user would then eventually get an
76 * NSError of domain GRMustacheErrorDomain and code
77 * GRMustacheErrorCodeTemplateNotFound.
78 *
79 * @param templateRepository The GRMustacheTemplateRepository asking for a
80 * template ID.
81 * @param name The name of the template or template partial.
82 * @param baseTemplateID The template ID of the enclosing template, or nil.
83 *
84 * @return a template ID
85 *
86 * @since v1.13
459f57b @groue v4.1.0
authored
87 */
88 - (id<NSCopying>)templateRepository:(GRMustacheTemplateRepository *)templateRepository templateIDForName:(NSString *)name relativeToTemplateID:(id)baseTemplateID AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
89
0d322bc @groue v4.1.1
authored
90
91 ////////////////////////////////////////////////////////////////////////////////
92 /// @name Providing Template Strings from Template IDs
93 ////////////////////////////////////////////////////////////////////////////////
94
459f57b @groue v4.1.0
authored
95 /**
0d322bc @groue v4.1.1
authored
96 * Provided with a template ID that comes from
97 * templateRepository:templateIDForName:relativeToTemplateID:,
98 * returns a Mustache template string.
99 *
100 * For instance, a file-based data source may interpret the template ID as a
101 * NSString object containing paths to the template, and return the file
102 * content.
103 *
104 * As usually, whenever this method returns nil, the _outError_ parameter should
105 * point to a valid NSError. This NSError would eventually reach the library
106 * user.
107 *
108 * @param templateRepository The GRMustacheTemplateRepository asking for a
109 * Mustache template string.
110 * @param templateID The template ID of the template
111 * @param outError If there is an error returning a template string,
112 * upon return contains nil, or an NSError object
113 * that describes the problem.
114 *
115 * @return a Mustache template string
116 *
117 * @since v1.13
459f57b @groue v4.1.0
authored
118 */
6337526 @groue v4.0.0
authored
119 - (NSString *)templateRepository:(GRMustacheTemplateRepository *)templateRepository templateStringForTemplateID:(id)templateID error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
120 @end
121
459f57b @groue v4.1.0
authored
122
123 /**
0d322bc @groue v4.1.1
authored
124 * Given a data source that provides Mustache template strings, a
125 * GRMustacheTemplateRepository's responsability is to provide
126 * GRMustacheTemplate instances.
127 *
128 * You may provide your own template string data source. However common cases
129 * such as loading templates from URLs, files, bundle resources, and
130 * dictionaries, are already implemented.
131 *
132 * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/template_repositories.md
133 *
134 * @see GRMustacheTemplate
135 * @see GRMustacheTemplateRepositoryDataSource
136 *
137 * @since v1.13
459f57b @groue v4.1.0
authored
138 */
5e5ea55 @groue v1.13.0
authored
139 @interface GRMustacheTemplateRepository : NSObject {
140 @private
141 id<GRMustacheTemplateRepositoryDataSource> _dataSource;
142 NSMutableDictionary *_templateForTemplateID;
143 id _currentlyParsedTemplateID;
144 }
459f57b @groue v4.1.0
authored
145
ed879f3 @groue v2.0.0
authored
146 #if !TARGET_OS_IPHONE || __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
459f57b @groue v4.1.0
authored
147
0d322bc @groue v4.1.1
authored
148 ////////////////////////////////////////////////////////////////////////////////
149 /// @name Building Repositories for Templates stored in the file system
150 ////////////////////////////////////////////////////////////////////////////////
151
459f57b @groue v4.1.0
authored
152 /**
0d322bc @groue v4.1.1
authored
153 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
154 * from files of extension .mustache, encoded in UTF8, stored in the provided
155 * base URL.
156 *
157 * For instance:
158 *
159 * // Creates a repository for templates stored in /path/to/templates
160 * NSURL *baseURL = [NSURL fileURLWithPath:@"/path/to/templates"];
161 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBaseURL:baseURL];
162 *
163 * // Returns a template for the file stored in
164 * // /path/to/templates/profile.mustache
165 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
166 *
167 * A partial tag `{{>partial}}` loads a partial template stored in a file named
168 * `partial.mustache`, located in the enclosing template's directory.
169 *
170 * You may use the slash `/`, and `..`, in order to navigate the URL
171 * hierarchical system: `{{>partials/achievements}}` would load
172 * /path/to/templates/partials/achievements.mustache, if invoked from
173 * /path/to/templates/profile.mustache.
174 *
175 * When you ask the repository to parse a raw template string, partials are
176 * loaded from the base URL:
177 *
178 * // The partial would be loaded from
179 * // /path/to/templates/partials/achievements.mustache
180 * GRMustacheTemplate *template = [repository templateFromString:@"{{>partials/achievements}}" error:NULL];
181 *
182 * @param URL the base URL where to look templates from.
183 *
184 * @return a GRMustacheTemplateRepository
185 *
186 * @since v1.13
459f57b @groue v4.1.0
authored
187 */
6337526 @groue v4.0.0
authored
188 + (id)templateRepositoryWithBaseURL:(NSURL *)URL AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
459f57b @groue v4.1.0
authored
189
190 /**
0d322bc @groue v4.1.1
authored
191 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
192 * from files of provided extension, encoded in UTF8, stored in the provided
193 * base URL.
194 *
195 * For instance:
196 *
197 * // Creates a repository for templates of extension `.txt` stored in
198 * // /path/to/templates
199 * NSURL *baseURL = [NSURL fileURLWithPath:@"/path/to/templates"];
200 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBaseURL:baseURL
201 * templateExtension:@"txt"];
202 *
203 * // Returns a template for the file stored in
204 * // /path/to/templates/profile.txt
205 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
206 *
207 * A partial tag `{{>partial}}` loads a partial template stored in a file named
208 * `partial.txt`, located in the enclosing template's directory.
209 *
210 * You may use the slash `/`, and `..`, in order to navigate the URL
211 * hierarchical system: `{{>partials/achievements}}` would load
212 * /path/to/templates/partials/achievements.txt, if invoked from
213 * /path/to/templates/profile.txt.
214 *
215 * When you ask the repository to parse a raw template string, partials are
216 * loaded from the base URL:
217 *
218 * // The partial would be loaded from
219 * // /path/to/templates/partials/achievements.txt
220 * GRMustacheTemplate *template = [repository templateFromString:@"{{>partials/achievements}}" error:NULL];
221 *
222 * @param URL The base URL where to look templates from.
223 * @param ext The extension of template files.
224 *
225 * @return a GRMustacheTemplateRepository
226 *
227 * @since v1.13
459f57b @groue v4.1.0
authored
228 */
6337526 @groue v4.0.0
authored
229 + (id)templateRepositoryWithBaseURL:(NSURL *)URL templateExtension:(NSString *)ext AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
459f57b @groue v4.1.0
authored
230
231 /**
0d322bc @groue v4.1.1
authored
232 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
233 * from files of provided extension, encoded in the provided encoding, stored in
234 * the provided base URL.
235 *
236 * For instance:
237 *
238 * // Creates a repository for templates of extension `.txt` stored in
239 * // /path/to/templates, encoded with NSMacOSRomanStringEncoding:
240 * NSURL *baseURL = [NSURL fileURLWithPath:@"/path/to/templates"];
241 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBaseURL:baseURL
242 * templateExtension:@"txt"
243 * encoding:NSMacOSRomanStringEncoding];
244 *
245 * // Returns a template for the file stored in
246 * // /path/to/templates/profile.txt
247 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
248 *
249 * A partial tag `{{>partial}}` loads a partial template stored in a file named
250 * `partial.txt`, located in the enclosing template's directory.
251 *
252 * You may use the slash `/`, and `..`, in order to navigate the URL
253 * hierarchical system: `{{>partials/achievements}}` would load
254 * /path/to/templates/partials/achievements.txt, if invoked from
255 * /path/to/templates/profile.txt.
256 *
257 * When you ask the repository to parse a raw template string, partials are
258 * loaded from the base URL:
259 *
260 * // The partial would be loaded from
261 * // /path/to/templates/partials/achievements.txt
262 * GRMustacheTemplate *template = [repository templateFromString:@"{{>partials/achievements}}" error:NULL];
263 *
264 * @param URL The base URL where to look templates from.
265 * @param ext The extension of template files.
266 * @param encoding The encoding of template files.
267 *
268 * @return a GRMustacheTemplateRepository
269 *
270 * @since v1.13
459f57b @groue v4.1.0
authored
271 */
6337526 @groue v4.0.0
authored
272 + (id)templateRepositoryWithBaseURL:(NSURL *)URL templateExtension:(NSString *)ext encoding:(NSStringEncoding)encoding AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
ed879f3 @groue v2.0.0
authored
273 #endif /* if !TARGET_OS_IPHONE || __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000 */
5e5ea55 @groue v1.13.0
authored
274
459f57b @groue v4.1.0
authored
275 /**
0d322bc @groue v4.1.1
authored
276 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
277 * from files of extension .mustache, encoded in UTF8, stored in the provided
278 * directory.
279 *
280 * For instance:
281 *
282 * // Creates a repository for templates stored in /path/to/templates
283 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithDirectory:@"/path/to/templates"];
284 *
285 * // Returns a template for the file stored in
286 * // /path/to/templates/profile.mustache
287 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
288 *
289 * A partial tag `{{>partial}}` loads a partial template stored in a file named
290 * `partial.mustache`, located in the enclosing template's directory.
291 *
292 * You may use the slash `/`, and `..`, in order to navigate the hierarchical
293 * file system: `{{>partials/achievements}}` would load
294 * /path/to/templates/partials/achievements.mustache, if invoked from
295 * /path/to/templates/profile.mustache.
296 *
297 * When you ask the repository to parse a raw template string, partials are
298 * loaded from the base directory:
299 *
300 * // The partial would be loaded from
301 * // /path/to/templates/partials/achievements.mustache
302 * GRMustacheTemplate *template = [repository templateFromString:@"{{>partials/achievements}}" error:NULL];
303 *
304 * @param path The path of the directory that stores templates.
305 *
306 * @return a GRMustacheTemplateRepository
307 *
308 * @since v1.13
459f57b @groue v4.1.0
authored
309 */
6337526 @groue v4.0.0
authored
310 + (id)templateRepositoryWithDirectory:(NSString *)path AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
459f57b @groue v4.1.0
authored
311
312 /**
0d322bc @groue v4.1.1
authored
313 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
314 * from files of provided extension, encoded in UTF8, stored in the provided
315 * directory.
316 *
317 * For instance:
318 *
319 * // Creates a repository for templates of extension `.txt` stored in
320 * // /path/to/templates
321 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithDirectory:@"/path/to/templates"
322 * templateExtension:@"txt"];
323 *
324 * // Returns a template for the file stored in
325 * // /path/to/templates/profile.txt
326 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
327 *
328 * A partial tag `{{>partial}}` loads a partial template stored in a file named
329 * `partial.txt`, located in the enclosing template's directory.
330 *
331 * You may use the slash `/`, and `..`, in order to navigate the hierarchical
332 * file system: `{{>partials/achievements}}` would load
333 * /path/to/templates/partials/achievements.txt, if invoked from
334 * /path/to/templates/profile.txt.
335 *
336 * When you ask the repository to parse a raw template string, partials are
337 * loaded from the base directory:
338 *
339 * // The partial would be loaded from
340 * // /path/to/templates/partials/achievements.txt
341 * GRMustacheTemplate *template = [repository templateFromString:@"{{>partials/achievements}}" error:NULL];
342 *
343 * @param path The path of the directory that stores templates.
344 * @param ext The extension of template files.
345 *
346 * @return a GRMustacheTemplateRepository
347 *
348 * @since v1.13
459f57b @groue v4.1.0
authored
349 */
6337526 @groue v4.0.0
authored
350 + (id)templateRepositoryWithDirectory:(NSString *)path templateExtension:(NSString *)ext AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
459f57b @groue v4.1.0
authored
351
352 /**
0d322bc @groue v4.1.1
authored
353 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
354 * from files of provided extension, encoded in the provided encoding, stored in
355 * the provided directory.
356 *
357 * For instance:
358 *
359 * // Creates a repository for templates of extension `.txt` stored in
360 * // /path/to/templates, encoded with NSMacOSRomanStringEncoding:
361 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithDirectory:@"/path/to/templates"
362 * templateExtension:@"txt"
363 * encoding:NSMacOSRomanStringEncoding];
364 *
365 * // Returns a template for the file stored in
366 * // /path/to/templates/profile.txt
367 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
368 *
369 * A partial tag `{{>partial}}` loads a partial template stored in a file named
370 * `partial.txt`, located in the enclosing template's directory.
371 *
372 * You may use the slash `/`, and `..`, in order to navigate the hierarchical
373 * file system: `{{>partials/achievements}}` would load
374 * /path/to/templates/partials/achievements.txt, if invoked from
375 * /path/to/templates/profile.txt.
376 *
377 * When you ask the repository to parse a raw template string, partials are
378 * loaded from the base directory:
379 *
380 * // The partial would be loaded from
381 * // /path/to/templates/partials/achievements.txt
382 * GRMustacheTemplate *template = [repository templateFromString:@"{{>partials/achievements}}" error:NULL];
383 *
384 * @param path The path of the directory that stores templates.
385 * @param ext The extension of template files.
386 * @param encoding The encoding of template files.
387 *
388 * @return a GRMustacheTemplateRepository
389 *
390 * @since v1.13
459f57b @groue v4.1.0
authored
391 */
6337526 @groue v4.0.0
authored
392 + (id)templateRepositoryWithDirectory:(NSString *)path templateExtension:(NSString *)ext encoding:(NSStringEncoding)encoding AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
393
0d322bc @groue v4.1.1
authored
394
395 ////////////////////////////////////////////////////////////////////////////////
396 /// @name Building Repositories for Templates stored as NSBundle resources
397 ////////////////////////////////////////////////////////////////////////////////
398
459f57b @groue v4.1.0
authored
399 /**
0d322bc @groue v4.1.1
authored
400 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
401 * from resources of extension .mustache, encoded in UTF8, stored in the
402 * provided bundle.
403 *
404 * For instance:
405 *
406 * // Creates a repository for templates stored in the main bundle:
407 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBundle:[NSBundle mainBundle]];
408 *
409 * // Returns a template for the resource profile.mustache
410 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
411 *
412 * You may provide nil for the bundle parameter: the repository will use the
413 * main bundle.
414 *
415 * A partial tag `{{>partial}}` loads a partial template from the
416 * `partial.mustache` resource in the bundle.
417 *
418 * @param bundle The bundle that stores templates as resources.
419 *
420 * @return a GRMustacheTemplateRepository
421 *
422 * @since v1.13
459f57b @groue v4.1.0
authored
423 */
6337526 @groue v4.0.0
authored
424 + (id)templateRepositoryWithBundle:(NSBundle *)bundle AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
459f57b @groue v4.1.0
authored
425
426 /**
0d322bc @groue v4.1.1
authored
427 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
428 * from resources of provided extension, encoded in UTF8, stored in the provided
429 * bundle.
430 *
431 * For instance:
432 *
433 * // Creates a repository for templates of extension `.txt` stored in the
434 * // main bundle:
435 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBundle:[NSBundle mainBundle]
436 * templateExtension:@"txt"];
437 *
438 * // Returns a template for the resource profile.txt
439 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
440 *
441 * You may provide nil for the bundle parameter: the repository will use the
442 * main bundle.
443 *
444 * A partial tag `{{>partial}}` loads a partial template from the `partial.txt`
445 * resource in the bundle.
446 *
447 * @param bundle The bundle that stores templates as resources.
448 * @param ext The extension of template files.
449 *
450 * @return a GRMustacheTemplateRepository
451 *
452 * @since v1.13
459f57b @groue v4.1.0
authored
453 */
6337526 @groue v4.0.0
authored
454 + (id)templateRepositoryWithBundle:(NSBundle *)bundle templateExtension:(NSString *)ext AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
459f57b @groue v4.1.0
authored
455
456 /**
0d322bc @groue v4.1.1
authored
457 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
458 * from resources of provided extension, encoded in the provided encoding,
459 * stored in the provided bundle.
460 *
461 * For instance:
462 *
463 * // Creates a repository for templates of extension `.txt` stored in the
464 * // main bundle, encoded with NSMacOSRomanStringEncoding:
465 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBundle:[NSBundle mainBundle]
466 * templateExtension:@"txt"
467 * encoding:NSMacOSRomanStringEncoding];
468 *
469 * // Returns a template for the resource profile.txt
470 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
471 *
472 * You may provide nil for the bundle parameter: the repository will use the
473 * main bundle.
474 *
475 * A partial tag `{{>partial}}` loads a partial template from the `partial.txt`
476 * resource in the bundle.
477 *
478 * @param bundle The bundle that stores templates as resources.
479 * @param ext The extension of template files.
480 * @param encoding The encoding of template files.
481 *
482 * @return a GRMustacheTemplateRepository
483 *
484 * @since v1.13
459f57b @groue v4.1.0
authored
485 */
6337526 @groue v4.0.0
authored
486 + (id)templateRepositoryWithBundle:(NSBundle *)bundle templateExtension:(NSString *)ext encoding:(NSStringEncoding)encoding AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
487
0d322bc @groue v4.1.1
authored
488
489 ////////////////////////////////////////////////////////////////////////////////
490 /// @name Building Repositories for Templates stored in Memory
491 ////////////////////////////////////////////////////////////////////////////////
492
459f57b @groue v4.1.0
authored
493 /**
0d322bc @groue v4.1.1
authored
494 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
495 * from a dictionary whose keys are template names, and values template strings.
496 *
497 * For instance:
498 *
499 * NSDictionary *partialsDictionary = [NSDictionary dictionaryWithObject:@"It works." forKey:@"partial"];
500 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithPartialsDictionary:partialsDictionary];
501 *
502 * // Two templates that would render "It works."
503 * GRMustacheTemplate *template1 = [repository templateForName:@"partial" error:NULL];
504 * GRMustacheTemplate *template2 = [repository templateFromString:@"{{>partial}}" error:NULL];
505 *
506 * @param partialsDictionary A dictionary of whose keys are template names, and
507 * values Mustache template strings.
508 *
509 * @return a GRMustacheTemplateRepository
510 *
511 * @since v1.13
459f57b @groue v4.1.0
authored
512 */
6337526 @groue v4.0.0
authored
513 + (id)templateRepositoryWithPartialsDictionary:(NSDictionary *)partialsDictionary AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
514
0d322bc @groue v4.1.1
authored
515
516 ////////////////////////////////////////////////////////////////////////////////
517 /// @name Building Repositories using a custom Data Source
518 ////////////////////////////////////////////////////////////////////////////////
519
459f57b @groue v4.1.0
authored
520 /**
0d322bc @groue v4.1.1
authored
521 * Returns a GRMustacheTemplateRepository.
522 *
523 * Until it is provided with a data source, it is unable to load template by
524 * names, and unable to process partial tags such as `{{>partial}}`:
525 *
526 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepository];
527 * NSError *error;
528 *
529 * // Returns nil, and sets error to an NSError of domain
530 * // GRMustacheErrorDomain, code GRMustacheErrorCodeTemplateNotFound.
531 * [repository templateForName:@"foo" error:&error];
532 *
533 * // Returns nil, and sets error to an NSError of domain GRMustacheErrorDomain,
534 * // code GRMustacheErrorCodeTemplateNotFound.
535 * [repository templateFromString:@"{{>partial}}" error:&error];
536 *
537 * It is, however, able to process Mustache template strings without any
538 * partial:
539 *
540 * GRMustacheTemplate *template = [repository templateFromString:@"Hello {{name}}!" error:NULL];
541 *
542 * You will give it a data source conforming to the
543 * GRMustacheTemplateRepositoryDataSource protocol in order to load template and
544 * partials by name:
545 *
546 * repository.dataSource = ...;
547 *
548 * // Returns a template built from the string provided by the dataSource.
549 * [repository templateForName:@"foo" error:NULL];
550 *
551 * @return a GRMustacheTemplateRepository
552 *
553 * @see GRMustacheTemplateRepositoryDataSource
554 *
555 * @since v1.13
459f57b @groue v4.1.0
authored
556 */
6337526 @groue v4.0.0
authored
557 + (id)templateRepository AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
558
459f57b @groue v4.1.0
authored
559 /**
0d322bc @groue v4.1.1
authored
560 * The repository's data source.
561 *
562 * @see GRMustacheTemplateRepositoryDataSource
563 *
564 * @since v1.13
565 */
566 @property (nonatomic, assign) id<GRMustacheTemplateRepositoryDataSource> dataSource AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
567
568
569 ////////////////////////////////////////////////////////////////////////////////
570 /// @name Getting Templates out of a Repository
571 ////////////////////////////////////////////////////////////////////////////////
572
573
574 /**
575 * Returns a template identified by its name.
576 *
577 * Depending on the way the repository has been created, the name identifies a
578 * URL, a file path, a key in a dictionary, or whatever is relevant to the
579 * repository's data source.
580 *
581 * @param name The template name
582 * @param outError If there is an error loading or parsing template and
583 * partials, upon return contains an NSError object that
584 * describes the problem.
585 *
586 * @return a GRMustacheTemplate
587 *
588 * @since v1.13
459f57b @groue v4.1.0
authored
589 */
6337526 @groue v4.0.0
authored
590 - (GRMustacheTemplate *)templateForName:(NSString *)name error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
459f57b @groue v4.1.0
authored
591
592 /**
0d322bc @groue v4.1.1
authored
593 * Returns a template built from the provided Mustache template string.
594 *
595 * Depending on the way the repository has been created, partial tags such as
596 * `{{>partial}}` load partial templates from URLs, file paths, keys in a
597 * dictionary, or whatever is relevant to the repository's data source.
598 *
599 * @param templateString A Mustache template string
600 * @param outError If there is an error loading or parsing template and
601 * partials, upon return contains an NSError object that
602 * describes the problem.
603 *
604 * @return a GRMustacheTemplate
605 *
606 * @since v1.13
459f57b @groue v4.1.0
authored
607 */
6337526 @groue v4.0.0
authored
608 - (GRMustacheTemplate *)templateFromString:(NSString *)templateString error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_4_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
609 @end
Something went wrong with that request. Please try again.