Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 53 lines (29 sloc) 2.98 kb
90b8751 @groue guide links get crazy
authored
1 [up](../../../../GRMustache), [next](runtime/context_stack.md)
1a1555f @groue guides wip
authored
2
6aa657e @groue guides wip
authored
3 GRMustache runtime
4 ==================
1a1555f @groue guides wip
authored
5
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnumera...
authored
6 ## Overview
1a1555f @groue guides wip
authored
7
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnumera...
authored
8 `valueForKey:`, `description`, `<NSFastEnumeration>`.
9
10 Those are the only interfaces that you have to care about when providing data to GRMustache.
1a1555f @groue guides wip
authored
11
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnumera...
authored
12 - `valueForKey:` is the standard [Key-Value Coding](http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/KeyValueCoding.html) method, that GRMustache invokes when looking for the data that will be rendered. Basically, for a `{{name}}` tag to be rendered, all you need to provide is an NSDictionary with the `@"name"` key, or an object declaring the `name` property.
1a1555f @groue guides wip
authored
13
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnumera...
authored
14 - `description` is the standard [NSObject](http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html) method, that GRMustache invokes when rendering the data it has fetched from `valueForKey:`. Most classes of Apple frameworks already have sensible implementations of `description`: NSString, NSNumber, etc. You generally won't have to think a lot about it.
1a1555f @groue guides wip
authored
15
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnumera...
authored
16 - `NSFastEnumeration` is the standard protocol for [enumerable objects](http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocFastEnumeration.html). The most obvious enumerable is NSArray. There are others, and you may provide your own. Objects that conform to the `NSFastEnumeration` protocol are the base of GRMustache loops. You'll read more on this topic in the [loops.md](runtime/loops.md) guide.
3d83fb0 @groue GitHub Flavored Markdown
authored
17
86dfa82 @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnumera...
authored
18 For instance, let's consider the following code:
19
20 ```obcj
21 NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"Arthur" forKey:@"name"];
22 NSString *templateString = @"Hello {{name}}!";
23 NSString *rendering = [GRMustacheTemplate renderObject:dictionary fromString:templateString error:NULL];
24 ```
25
26 1. When GRMustache renders the `{{name}}` tag, it invokes `valueForKey:` with the key `@"name"` on the dictionary. It gets `@"Arthur"` as a result.
27 2. The `description` method of NSString returns the string itself: `@"Arthur"`.
28 3. Hence we'll get the expected rendering: `@"Hello Arthur!"`.
3d83fb0 @groue GitHub Flavored Markdown
authored
29
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnumera...
authored
30
31 ## In Detail
32
86dfa82 @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnumera...
authored
33 Mustache does a little more than rendering plain `{{name}}` tags. Let's review Mustache features and how GRMustache help you leverage them.
f5fb58f @groue wording
authored
34
35 - [context_stack.md](runtime/context_stack.md)
36
86dfa82 @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnumera...
authored
37 This guide digs into Mustache sections such as `{{#section}}...{{/section}}`, and the key lookup mechanism.
f5fb58f @groue wording
authored
38
39 - [loops.md](runtime/loops.md)
40
86dfa82 @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnumera...
authored
41 Learn how to render template sections as many times as there are objects in enumerable objects such as arrays.
f5fb58f @groue wording
authored
42
43 - [booleans.md](runtime/booleans.md)
44
45 Control whether a Mustache section should render or not.
46
47 - [helpers.md](runtime/helpers.md)
48
49 Mustache has "lambda sections". These are sections that allow you to execute custom code, and implement nifty features like caching, filtering, whatever, on portions of your templates.
50
1a1555f @groue guides wip
authored
51
90b8751 @groue guide links get crazy
authored
52 [up](../../../../GRMustache), [next](runtime/context_stack.md)
Something went wrong with that request. Please try again.