Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 47 lines (26 sloc) 2.653 kB
4dc441a @groue Guides/introduction.md is the documentation root: update all links
authored
1 [up](introduction.md), [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 NSFastEnum…
authored
6 ## Overview
1a1555f @groue guides wip
authored
7
3022841 @groue Clarity
authored
8 There are only three methods that you have to care about when providing data to GRMustache:
1a1555f @groue guides wip
authored
9
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored
10 - `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
11
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored
12 - `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
13
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored
14 - `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
15
86dfa82 @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored
16 For instance, let's consider the following code:
17
18 ```obcj
8dcc514 @groue Use Objective-C literals in guides
authored
19 NSDictionary *dictionary = @{ @"count": @2 };
3022841 @groue Clarity
authored
20 NSString *templateString = @"I have {{count}} arms.";
86dfa82 @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored
21 NSString *rendering = [GRMustacheTemplate renderObject:dictionary fromString:templateString error:NULL];
22 ```
23
3f83518 @groue Use Objective-C literals in guides
authored
24 1. When GRMustache renders the `{{count}}` tag, it invokes `valueForKey:` with the key `@"count"` on the dictionary. It gets an NSNumber of value 2 as a result.
3022841 @groue Clarity
authored
25 2. The `description` method of the NSNumber returns a string: `@"2"`.
26 3. This string is inserted into the rendering: `@"I have 2 arms"`.
3d83fb0 @groue GitHub Flavored Markdown
authored
27
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored
28
29 ## In Detail
30
86dfa82 @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored
31 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
32
33 - [context_stack.md](runtime/context_stack.md)
34
ed26c85 @groue v5.3.0
authored
35 This guide digs into Mustache section tags such as `{{#section}}...{{/section}}`, and the key lookup mechanism.
f5fb58f @groue wording
authored
36
37 - [loops.md](runtime/loops.md)
38
86dfa82 @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored
39 Learn how to render template sections as many times as there are objects in enumerable objects such as arrays.
f5fb58f @groue wording
authored
40
41 - [booleans.md](runtime/booleans.md)
42
43 Control whether a Mustache section should render or not.
44
1a1555f @groue guides wip
authored
45
4dc441a @groue Guides/introduction.md is the documentation root: update all links
authored
46 [up](introduction.md), [next](runtime/context_stack.md)
Something went wrong with that request. Please try again.