Skip to content

Commit

Permalink
runtime.md guide focuses on valueForKey:, description, and NSFastEnum…
Browse files Browse the repository at this point in the history
…eration protocol
  • Loading branch information
groue committed May 4, 2012
1 parent dd8f13e commit d31d8cf
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions Guides/runtime.md
Expand Up @@ -3,30 +3,28 @@
GRMustache runtime GRMustache runtime
================== ==================


GRMustache rendering is the combination of a template and of an object that will provide the data. This guide describes this interaction in detail. ## Overview


Generally speaking, GRMustache will look for values in your data objects through the standard Key-Value Coding `valueForKey:` method. `valueForKey:`, `description`, `<NSFastEnumeration>`.

Those are the only interfaces that you have to care about when providing data to GRMustache.


You can thus provide rendering methods with NSDictionary instances, or custom objects with properties or methods whose name match the keys in the template tags. - `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.


```objc - `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.
// This template waits for a `name` key:
GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:@"{{name}}" error:NULL];


// Those two objects provide this `name` key: - `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.
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"dictionary" forKey:@"name"];
Person *arthur = [Person personWithName:@"arthur"];


// "dictionary" You do not need to know more in order to talk to GRMustache.
[template renderObject:dictionary];


// "arthur"
[template renderObject:arthur]; ## In Detail
```
Mustache does a little more than rendering plain `{{tags}}`. Let's review Mustache features and how GRMustache help you leverage them.


- [context_stack.md](runtime/context_stack.md) - [context_stack.md](runtime/context_stack.md)


This guide digs into the key lookup mechanism. This guide digs into Mustache `{{#sections}}`, and the key lookup mechanism.


- [loops.md](runtime/loops.md) - [loops.md](runtime/loops.md)


Expand Down

0 comments on commit d31d8cf

Please sign in to comment.