Skip to content
Newer
Older
100644 611 lines (574 sloc) 25.5 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 *
7ac295f @groue v5.4.0
authored
61 * You should try to choose "human-readable" template IDs, because template IDs
62 * are embedded in the description of errors that may happen during a template
63 * processing, in order to help the library user locate, and fix, the faulting
64 * template.
65 *
0d322bc @groue v4.1.1
authored
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.
7ac295f @groue v5.4.0
authored
74 *
75 * Data sources that implement hierarchies have to implement their own support
76 * for absolute partial paths.
77 *
78 * The return value of this method can be nil: the library user would then
79 * eventually get an NSError of domain GRMustacheErrorDomain and code
0d322bc @groue v4.1.1
authored
80 * GRMustacheErrorCodeTemplateNotFound.
7ac295f @groue v5.4.0
authored
81 *
0d322bc @groue v4.1.1
authored
82 * @param templateRepository The GRMustacheTemplateRepository asking for a
83 * template ID.
84 * @param name The name of the template or template partial.
85 * @param baseTemplateID The template ID of the enclosing template, or nil.
86 *
87 * @return a template ID
88 *
89 * @since v1.13
459f57b @groue v4.1.0
authored
90 */
7924382 @groue v5.0.0
authored
91 - (id<NSCopying>)templateRepository:(GRMustacheTemplateRepository *)templateRepository templateIDForName:(NSString *)name relativeToTemplateID:(id)baseTemplateID AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
459f57b @groue v4.1.0
authored
92
0d322bc @groue v4.1.1
authored
93
94 ////////////////////////////////////////////////////////////////////////////////
95 /// @name Providing Template Strings from Template IDs
96 ////////////////////////////////////////////////////////////////////////////////
97
459f57b @groue v4.1.0
authored
98 /**
0d322bc @groue v4.1.1
authored
99 * Provided with a template ID that comes from
100 * templateRepository:templateIDForName:relativeToTemplateID:,
101 * returns a Mustache template string.
102 *
103 * For instance, a file-based data source may interpret the template ID as a
104 * NSString object containing paths to the template, and return the file
105 * content.
106 *
107 * As usually, whenever this method returns nil, the _outError_ parameter should
108 * point to a valid NSError. This NSError would eventually reach the library
109 * user.
110 *
111 * @param templateRepository The GRMustacheTemplateRepository asking for a
112 * Mustache template string.
113 * @param templateID The template ID of the template
114 * @param outError If there is an error returning a template string,
115 * upon return contains nil, or an NSError object
116 * that describes the problem.
117 *
118 * @return a Mustache template string
119 *
120 * @since v1.13
459f57b @groue v4.1.0
authored
121 */
7924382 @groue v5.0.0
authored
122 - (NSString *)templateRepository:(GRMustacheTemplateRepository *)templateRepository templateStringForTemplateID:(id)templateID error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
123 @end
124
459f57b @groue v4.1.0
authored
125
126 /**
0d322bc @groue v4.1.1
authored
127 * Given a data source that provides Mustache template strings, a
128 * GRMustacheTemplateRepository's responsability is to provide
129 * GRMustacheTemplate instances.
130 *
131 * You may provide your own template string data source. However common cases
132 * such as loading templates from URLs, files, bundle resources, and
133 * dictionaries, are already implemented.
134 *
135 * **Companion guide:** https://github.com/groue/GRMustache/blob/master/Guides/template_repositories.md
136 *
137 * @see GRMustacheTemplate
138 * @see GRMustacheTemplateRepositoryDataSource
139 *
140 * @since v1.13
459f57b @groue v4.1.0
authored
141 */
5e5ea55 @groue v1.13.0
authored
142 @interface GRMustacheTemplateRepository : NSObject {
143 @private
144 id<GRMustacheTemplateRepositoryDataSource> _dataSource;
145 NSMutableDictionary *_templateForTemplateID;
146 id _currentlyParsedTemplateID;
147 }
459f57b @groue v4.1.0
authored
148
149
0d322bc @groue v4.1.1
authored
150 ////////////////////////////////////////////////////////////////////////////////
151 /// @name Building Repositories for Templates stored in the file system
152 ////////////////////////////////////////////////////////////////////////////////
153
459f57b @groue v4.1.0
authored
154 /**
0d322bc @groue v4.1.1
authored
155 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
156 * from files of extension .mustache, encoded in UTF8, stored in the provided
157 * base URL.
158 *
159 * For instance:
160 *
161 * // Creates a repository for templates stored in /path/to/templates
162 * NSURL *baseURL = [NSURL fileURLWithPath:@"/path/to/templates"];
163 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBaseURL:baseURL];
164 *
165 * // Returns a template for the file stored in
166 * // /path/to/templates/profile.mustache
167 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
168 *
169 * A partial tag `{{>partial}}` loads a partial template stored in a file named
170 * `partial.mustache`, located in the enclosing template's directory.
171 *
172 * You may use the slash `/`, and `..`, in order to navigate the URL
173 * hierarchical system: `{{>partials/achievements}}` would load
174 * /path/to/templates/partials/achievements.mustache, if invoked from
175 * /path/to/templates/profile.mustache.
176 *
177 * When you ask the repository to parse a raw template string, partials are
178 * loaded from the base URL:
179 *
180 * // The partial would be loaded from
181 * // /path/to/templates/partials/achievements.mustache
182 * GRMustacheTemplate *template = [repository templateFromString:@"{{>partials/achievements}}" error:NULL];
183 *
184 * @param URL the base URL where to look templates from.
185 *
186 * @return a GRMustacheTemplateRepository
187 *
188 * @since v1.13
459f57b @groue v4.1.0
authored
189 */
7924382 @groue v5.0.0
authored
190 + (id)templateRepositoryWithBaseURL:(NSURL *)URL AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
459f57b @groue v4.1.0
authored
191
192 /**
0d322bc @groue v4.1.1
authored
193 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
194 * from files of provided extension, encoded in UTF8, stored in the provided
195 * base URL.
196 *
197 * For instance:
198 *
199 * // Creates a repository for templates of extension `.txt` stored in
200 * // /path/to/templates
201 * NSURL *baseURL = [NSURL fileURLWithPath:@"/path/to/templates"];
202 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBaseURL:baseURL
203 * templateExtension:@"txt"];
204 *
205 * // Returns a template for the file stored in
206 * // /path/to/templates/profile.txt
207 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
208 *
209 * A partial tag `{{>partial}}` loads a partial template stored in a file named
210 * `partial.txt`, located in the enclosing template's directory.
211 *
212 * You may use the slash `/`, and `..`, in order to navigate the URL
213 * hierarchical system: `{{>partials/achievements}}` would load
214 * /path/to/templates/partials/achievements.txt, if invoked from
215 * /path/to/templates/profile.txt.
216 *
217 * When you ask the repository to parse a raw template string, partials are
218 * loaded from the base URL:
219 *
220 * // The partial would be loaded from
221 * // /path/to/templates/partials/achievements.txt
222 * GRMustacheTemplate *template = [repository templateFromString:@"{{>partials/achievements}}" error:NULL];
223 *
224 * @param URL The base URL where to look templates from.
225 * @param ext The extension of template files.
226 *
227 * @return a GRMustacheTemplateRepository
228 *
229 * @since v1.13
459f57b @groue v4.1.0
authored
230 */
7924382 @groue v5.0.0
authored
231 + (id)templateRepositoryWithBaseURL:(NSURL *)URL templateExtension:(NSString *)ext AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
459f57b @groue v4.1.0
authored
232
233 /**
0d322bc @groue v4.1.1
authored
234 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
235 * from files of provided extension, encoded in the provided encoding, stored in
236 * the provided base URL.
237 *
238 * For instance:
239 *
240 * // Creates a repository for templates of extension `.txt` stored in
241 * // /path/to/templates, encoded with NSMacOSRomanStringEncoding:
242 * NSURL *baseURL = [NSURL fileURLWithPath:@"/path/to/templates"];
243 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBaseURL:baseURL
244 * templateExtension:@"txt"
245 * encoding:NSMacOSRomanStringEncoding];
246 *
247 * // Returns a template for the file stored in
248 * // /path/to/templates/profile.txt
249 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
250 *
251 * A partial tag `{{>partial}}` loads a partial template stored in a file named
252 * `partial.txt`, located in the enclosing template's directory.
253 *
254 * You may use the slash `/`, and `..`, in order to navigate the URL
255 * hierarchical system: `{{>partials/achievements}}` would load
256 * /path/to/templates/partials/achievements.txt, if invoked from
257 * /path/to/templates/profile.txt.
258 *
259 * When you ask the repository to parse a raw template string, partials are
260 * loaded from the base URL:
261 *
262 * // The partial would be loaded from
263 * // /path/to/templates/partials/achievements.txt
264 * GRMustacheTemplate *template = [repository templateFromString:@"{{>partials/achievements}}" error:NULL];
265 *
266 * @param URL The base URL where to look templates from.
267 * @param ext The extension of template files.
268 * @param encoding The encoding of template files.
269 *
270 * @return a GRMustacheTemplateRepository
271 *
272 * @since v1.13
459f57b @groue v4.1.0
authored
273 */
7924382 @groue v5.0.0
authored
274 + (id)templateRepositoryWithBaseURL:(NSURL *)URL templateExtension:(NSString *)ext encoding:(NSStringEncoding)encoding AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
275
459f57b @groue v4.1.0
authored
276 /**
0d322bc @groue v4.1.1
authored
277 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
278 * from files of extension .mustache, encoded in UTF8, stored in the provided
279 * directory.
280 *
281 * For instance:
282 *
283 * // Creates a repository for templates stored in /path/to/templates
284 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithDirectory:@"/path/to/templates"];
285 *
286 * // Returns a template for the file stored in
287 * // /path/to/templates/profile.mustache
288 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
289 *
290 * A partial tag `{{>partial}}` loads a partial template stored in a file named
291 * `partial.mustache`, located in the enclosing template's directory.
292 *
293 * You may use the slash `/`, and `..`, in order to navigate the hierarchical
294 * file system: `{{>partials/achievements}}` would load
295 * /path/to/templates/partials/achievements.mustache, if invoked from
296 * /path/to/templates/profile.mustache.
297 *
298 * When you ask the repository to parse a raw template string, partials are
299 * loaded from the base directory:
300 *
301 * // The partial would be loaded from
302 * // /path/to/templates/partials/achievements.mustache
303 * GRMustacheTemplate *template = [repository templateFromString:@"{{>partials/achievements}}" error:NULL];
304 *
305 * @param path The path of the directory that stores templates.
306 *
307 * @return a GRMustacheTemplateRepository
308 *
309 * @since v1.13
459f57b @groue v4.1.0
authored
310 */
7924382 @groue v5.0.0
authored
311 + (id)templateRepositoryWithDirectory:(NSString *)path AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
459f57b @groue v4.1.0
authored
312
313 /**
0d322bc @groue v4.1.1
authored
314 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
315 * from files of provided extension, encoded in UTF8, stored in the provided
316 * directory.
317 *
318 * For instance:
319 *
320 * // Creates a repository for templates of extension `.txt` stored in
321 * // /path/to/templates
322 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithDirectory:@"/path/to/templates"
323 * templateExtension:@"txt"];
324 *
325 * // Returns a template for the file stored in
326 * // /path/to/templates/profile.txt
327 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
328 *
329 * A partial tag `{{>partial}}` loads a partial template stored in a file named
330 * `partial.txt`, located in the enclosing template's directory.
331 *
332 * You may use the slash `/`, and `..`, in order to navigate the hierarchical
333 * file system: `{{>partials/achievements}}` would load
334 * /path/to/templates/partials/achievements.txt, if invoked from
335 * /path/to/templates/profile.txt.
336 *
337 * When you ask the repository to parse a raw template string, partials are
338 * loaded from the base directory:
339 *
340 * // The partial would be loaded from
341 * // /path/to/templates/partials/achievements.txt
342 * GRMustacheTemplate *template = [repository templateFromString:@"{{>partials/achievements}}" error:NULL];
343 *
344 * @param path The path of the directory that stores templates.
345 * @param ext The extension of template files.
346 *
347 * @return a GRMustacheTemplateRepository
348 *
349 * @since v1.13
459f57b @groue v4.1.0
authored
350 */
7924382 @groue v5.0.0
authored
351 + (id)templateRepositoryWithDirectory:(NSString *)path templateExtension:(NSString *)ext AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
459f57b @groue v4.1.0
authored
352
353 /**
0d322bc @groue v4.1.1
authored
354 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
355 * from files of provided extension, encoded in the provided encoding, stored in
356 * the provided directory.
357 *
358 * For instance:
359 *
360 * // Creates a repository for templates of extension `.txt` stored in
361 * // /path/to/templates, encoded with NSMacOSRomanStringEncoding:
362 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithDirectory:@"/path/to/templates"
363 * templateExtension:@"txt"
364 * encoding:NSMacOSRomanStringEncoding];
365 *
366 * // Returns a template for the file stored in
367 * // /path/to/templates/profile.txt
368 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
369 *
370 * A partial tag `{{>partial}}` loads a partial template stored in a file named
371 * `partial.txt`, located in the enclosing template's directory.
372 *
373 * You may use the slash `/`, and `..`, in order to navigate the hierarchical
374 * file system: `{{>partials/achievements}}` would load
375 * /path/to/templates/partials/achievements.txt, if invoked from
376 * /path/to/templates/profile.txt.
377 *
378 * When you ask the repository to parse a raw template string, partials are
379 * loaded from the base directory:
380 *
381 * // The partial would be loaded from
382 * // /path/to/templates/partials/achievements.txt
383 * GRMustacheTemplate *template = [repository templateFromString:@"{{>partials/achievements}}" error:NULL];
384 *
385 * @param path The path of the directory that stores templates.
386 * @param ext The extension of template files.
387 * @param encoding The encoding of template files.
388 *
389 * @return a GRMustacheTemplateRepository
390 *
391 * @since v1.13
459f57b @groue v4.1.0
authored
392 */
7924382 @groue v5.0.0
authored
393 + (id)templateRepositoryWithDirectory:(NSString *)path templateExtension:(NSString *)ext encoding:(NSStringEncoding)encoding AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
394
0d322bc @groue v4.1.1
authored
395
396 ////////////////////////////////////////////////////////////////////////////////
397 /// @name Building Repositories for Templates stored as NSBundle resources
398 ////////////////////////////////////////////////////////////////////////////////
399
459f57b @groue v4.1.0
authored
400 /**
0d322bc @groue v4.1.1
authored
401 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
402 * from resources of extension .mustache, encoded in UTF8, stored in the
403 * provided bundle.
404 *
405 * For instance:
406 *
407 * // Creates a repository for templates stored in the main bundle:
408 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBundle:[NSBundle mainBundle]];
409 *
410 * // Returns a template for the resource profile.mustache
411 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
412 *
413 * You may provide nil for the bundle parameter: the repository will use the
414 * main bundle.
415 *
416 * A partial tag `{{>partial}}` loads a partial template from the
417 * `partial.mustache` resource in the bundle.
418 *
419 * @param bundle The bundle that stores templates as resources.
420 *
421 * @return a GRMustacheTemplateRepository
422 *
423 * @since v1.13
459f57b @groue v4.1.0
authored
424 */
7924382 @groue v5.0.0
authored
425 + (id)templateRepositoryWithBundle:(NSBundle *)bundle AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
459f57b @groue v4.1.0
authored
426
427 /**
0d322bc @groue v4.1.1
authored
428 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
429 * from resources of provided extension, encoded in UTF8, stored in the provided
430 * bundle.
431 *
432 * For instance:
433 *
434 * // Creates a repository for templates of extension `.txt` stored in the
435 * // main bundle:
436 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBundle:[NSBundle mainBundle]
437 * templateExtension:@"txt"];
438 *
439 * // Returns a template for the resource profile.txt
440 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
441 *
442 * You may provide nil for the bundle parameter: the repository will use the
443 * main bundle.
444 *
445 * A partial tag `{{>partial}}` loads a partial template from the `partial.txt`
446 * resource in the bundle.
447 *
448 * @param bundle The bundle that stores templates as resources.
449 * @param ext The extension of template files.
450 *
451 * @return a GRMustacheTemplateRepository
452 *
453 * @since v1.13
459f57b @groue v4.1.0
authored
454 */
7924382 @groue v5.0.0
authored
455 + (id)templateRepositoryWithBundle:(NSBundle *)bundle templateExtension:(NSString *)ext AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
459f57b @groue v4.1.0
authored
456
457 /**
0d322bc @groue v4.1.1
authored
458 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
459 * from resources of provided extension, encoded in the provided encoding,
460 * stored in the provided bundle.
461 *
462 * For instance:
463 *
464 * // Creates a repository for templates of extension `.txt` stored in the
465 * // main bundle, encoded with NSMacOSRomanStringEncoding:
466 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithBundle:[NSBundle mainBundle]
467 * templateExtension:@"txt"
468 * encoding:NSMacOSRomanStringEncoding];
469 *
470 * // Returns a template for the resource profile.txt
471 * GRMustacheTemplate *template = [repository templateForName:@"profile" error:NULL];
472 *
473 * You may provide nil for the bundle parameter: the repository will use the
474 * main bundle.
475 *
476 * A partial tag `{{>partial}}` loads a partial template from the `partial.txt`
477 * resource in the bundle.
478 *
479 * @param bundle The bundle that stores templates as resources.
480 * @param ext The extension of template files.
481 * @param encoding The encoding of template files.
482 *
483 * @return a GRMustacheTemplateRepository
484 *
485 * @since v1.13
459f57b @groue v4.1.0
authored
486 */
7924382 @groue v5.0.0
authored
487 + (id)templateRepositoryWithBundle:(NSBundle *)bundle templateExtension:(NSString *)ext encoding:(NSStringEncoding)encoding AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
488
0d322bc @groue v4.1.1
authored
489
490 ////////////////////////////////////////////////////////////////////////////////
491 /// @name Building Repositories for Templates stored in Memory
492 ////////////////////////////////////////////////////////////////////////////////
493
459f57b @groue v4.1.0
authored
494 /**
0d322bc @groue v4.1.1
authored
495 * Returns a GRMustacheTemplateRepository that loads Mustache template strings
496 * from a dictionary whose keys are template names, and values template strings.
497 *
498 * For instance:
499 *
500 * NSDictionary *partialsDictionary = [NSDictionary dictionaryWithObject:@"It works." forKey:@"partial"];
501 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepositoryWithPartialsDictionary:partialsDictionary];
502 *
503 * // Two templates that would render "It works."
504 * GRMustacheTemplate *template1 = [repository templateForName:@"partial" error:NULL];
505 * GRMustacheTemplate *template2 = [repository templateFromString:@"{{>partial}}" error:NULL];
506 *
507 * @param partialsDictionary A dictionary of whose keys are template names, and
508 * values Mustache template strings.
509 *
510 * @return a GRMustacheTemplateRepository
511 *
512 * @since v1.13
459f57b @groue v4.1.0
authored
513 */
7924382 @groue v5.0.0
authored
514 + (id)templateRepositoryWithPartialsDictionary:(NSDictionary *)partialsDictionary AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
515
0d322bc @groue v4.1.1
authored
516
517 ////////////////////////////////////////////////////////////////////////////////
518 /// @name Building Repositories using a custom Data Source
519 ////////////////////////////////////////////////////////////////////////////////
520
459f57b @groue v4.1.0
authored
521 /**
0d322bc @groue v4.1.1
authored
522 * Returns a GRMustacheTemplateRepository.
523 *
524 * Until it is provided with a data source, it is unable to load template by
525 * names, and unable to process partial tags such as `{{>partial}}`:
526 *
527 * GRMustacheTemplateRepository *repository = [GRMustacheTemplateRepository templateRepository];
528 * NSError *error;
529 *
530 * // Returns nil, and sets error to an NSError of domain
531 * // GRMustacheErrorDomain, code GRMustacheErrorCodeTemplateNotFound.
532 * [repository templateForName:@"foo" error:&error];
533 *
534 * // Returns nil, and sets error to an NSError of domain GRMustacheErrorDomain,
535 * // code GRMustacheErrorCodeTemplateNotFound.
536 * [repository templateFromString:@"{{>partial}}" error:&error];
537 *
538 * It is, however, able to process Mustache template strings without any
539 * partial:
540 *
541 * GRMustacheTemplate *template = [repository templateFromString:@"Hello {{name}}!" error:NULL];
542 *
543 * You will give it a data source conforming to the
544 * GRMustacheTemplateRepositoryDataSource protocol in order to load template and
545 * partials by name:
546 *
547 * repository.dataSource = ...;
548 *
549 * // Returns a template built from the string provided by the dataSource.
550 * [repository templateForName:@"foo" error:NULL];
551 *
552 * @return a GRMustacheTemplateRepository
553 *
554 * @see GRMustacheTemplateRepositoryDataSource
555 *
556 * @since v1.13
459f57b @groue v4.1.0
authored
557 */
7924382 @groue v5.0.0
authored
558 + (id)templateRepository AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
559
459f57b @groue v4.1.0
authored
560 /**
0d322bc @groue v4.1.1
authored
561 * The repository's data source.
562 *
563 * @see GRMustacheTemplateRepositoryDataSource
564 *
565 * @since v1.13
566 */
7924382 @groue v5.0.0
authored
567 @property (nonatomic, assign) id<GRMustacheTemplateRepositoryDataSource> dataSource AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
0d322bc @groue v4.1.1
authored
568
569
570 ////////////////////////////////////////////////////////////////////////////////
571 /// @name Getting Templates out of a Repository
572 ////////////////////////////////////////////////////////////////////////////////
573
574
575 /**
576 * Returns a template identified by its name.
577 *
578 * Depending on the way the repository has been created, the name identifies a
579 * URL, a file path, a key in a dictionary, or whatever is relevant to the
580 * repository's data source.
581 *
582 * @param name The template name
583 * @param outError If there is an error loading or parsing template and
584 * partials, upon return contains an NSError object that
585 * describes the problem.
586 *
587 * @return a GRMustacheTemplate
588 *
589 * @since v1.13
459f57b @groue v4.1.0
authored
590 */
7924382 @groue v5.0.0
authored
591 - (GRMustacheTemplate *)templateForName:(NSString *)name error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
459f57b @groue v4.1.0
authored
592
593 /**
0d322bc @groue v4.1.1
authored
594 * Returns a template built from the provided Mustache template string.
595 *
596 * Depending on the way the repository has been created, partial tags such as
597 * `{{>partial}}` load partial templates from URLs, file paths, keys in a
598 * dictionary, or whatever is relevant to the repository's data source.
599 *
600 * @param templateString A Mustache template string
601 * @param outError If there is an error loading or parsing template and
602 * partials, upon return contains an NSError object that
603 * describes the problem.
604 *
605 * @return a GRMustacheTemplate
606 *
607 * @since v1.13
459f57b @groue v4.1.0
authored
608 */
7924382 @groue v5.0.0
authored
609 - (GRMustacheTemplate *)templateFromString:(NSString *)templateString error:(NSError **)outError AVAILABLE_GRMUSTACHE_VERSION_5_0_AND_LATER;
5e5ea55 @groue v1.13.0
authored
610 @end
Something went wrong with that request. Please try again.