Skip to content
Newer
Older
100644 55 lines (30 sloc) 3.21 KB
4dc441a @groue Guides/introduction.md is the documentation root: update all links
authored Aug 25, 2012
1 [up](introduction.md), [next](runtime/context_stack.md)
1a1555f @groue guides wip
authored Jan 25, 2012
2
6aa657e @groue guides wip
authored Jan 25, 2012
3 GRMustache runtime
4 ==================
1a1555f @groue guides wip
authored Jan 25, 2012
5
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored May 4, 2012
6 ## Overview
1a1555f @groue guides wip
authored Jan 25, 2012
7
4f79605 @groue Document the rendering of lists by variable tags.
authored Sep 29, 2012
8 Basically, there are only two methods and one protocol that you have to care about when providing data to GRMustache:
1a1555f @groue guides wip
authored Jan 25, 2012
9
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored May 4, 2012
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 Jan 25, 2012
11
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored May 4, 2012
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 Jan 25, 2012
13
4f79605 @groue Document the rendering of lists by variable tags.
authored Sep 29, 2012
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.
15
16 Both variable tags `{{items}}` and section tags `{{#items}}...{{/items}}` can loop. You'll read more on this topic in the [loops.md](runtime/loops.md) guide.
3d83fb0 @groue GitHub Flavored Markdown
authored Mar 5, 2012
17
86dfa82 @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored May 4, 2012
18 For instance, let's consider the following code:
19
20 ```obcj
8dcc514 @groue Use Objective-C literals in guides
authored Aug 22, 2012
21 NSDictionary *dictionary = @{ @"count": @2 };
3022841 @groue Clarity
authored Jun 16, 2012
22 NSString *templateString = @"I have {{count}} arms.";
86dfa82 @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored May 4, 2012
23 NSString *rendering = [GRMustacheTemplate renderObject:dictionary fromString:templateString error:NULL];
24 ```
25
3f83518 @groue Use Objective-C literals in guides
authored Aug 22, 2012
26 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 Jun 16, 2012
27 2. The `description` method of the NSNumber returns a string: `@"2"`.
28 3. This string is inserted into the rendering: `@"I have 2 arms"`.
3d83fb0 @groue GitHub Flavored Markdown
authored Mar 5, 2012
29
4f79605 @groue Document the rendering of lists by variable tags.
authored Sep 29, 2012
30 Two other "advanced" protocols let you implement some custom rendering:
31
32 - `GRMustacheVariableTagHelper`: when a value provided with `valueForKey:` conforms to this protocol, variable tags lets the value perform its own custom rendering. See [variable_tag_helpers.md](variable_tag_helpers.md).
33
34 - `GRMustacheSectionTagHelper`: when a value provided with `valueForKey:` conforms to this protocol, section tags lets the value perform its own custom rendering. See [section_tag_helpers.md](section_tag_helpers.md).
35
d31d8cf @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored May 4, 2012
36
37 ## In Detail
38
86dfa82 @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored May 4, 2012
39 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 Mar 2, 2012
40
41 - [context_stack.md](runtime/context_stack.md)
42
ed26c85 @groue v5.3.0
authored Sep 26, 2012
43 This guide digs into Mustache section tags such as `{{#section}}...{{/section}}`, and the key lookup mechanism.
f5fb58f @groue wording
authored Mar 2, 2012
44
45 - [loops.md](runtime/loops.md)
46
86dfa82 @groue runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
authored May 4, 2012
47 Learn how to render template sections as many times as there are objects in enumerable objects such as arrays.
f5fb58f @groue wording
authored Mar 2, 2012
48
49 - [booleans.md](runtime/booleans.md)
50
51 Control whether a Mustache section should render or not.
52
1a1555f @groue guides wip
authored Jan 25, 2012
53
4dc441a @groue Guides/introduction.md is the documentation root: update all links
authored Aug 25, 2012
54 [up](introduction.md), [next](runtime/context_stack.md)
Something went wrong with that request. Please try again.