Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

101 lines (57 sloc) 5.124 kb

GRMustache

GRMustache is an Objective-C implementation of the Mustache logic-less template language.

The Mustache syntax: http://mustache.github.com/mustache.5.html.

Breaking news on Twitter: http://twitter.com/GRMustache

How To

1. Download and add to your Xcode project

$ git clone https://github.com/groue/GRMustache.git
  • For MacOS 10.6+ development, add include/GRMustache.h and lib/libGRMustache4-MacOS.a to your project.
  • For iOS3+ development, add include/GRMustache.h and lib/libGRMustache4-iOS.a to your project.

Alternatively, you may use CocoaPods: append dependency 'GRMustache' to your Podfile. In its current version, CocoaPods exposes private headers that you should not rely on, because future versions of GRMustache may change them, without notice, in an incompatible fashion. Make sure you only import GRMustache.h.

2. Import "GRMustache.h" and start rendering templates

#import "GRMustache.h"

// Renders "Hello Arthur!"
NSString *rendering = [GRMustacheTemplate renderObject:[Person personWithName:@"Arthur"]
                                            fromString:@"Hello {{name}}!"
                                                 error:NULL];

// Renders from a resource
NSString *rendering = [GRMustacheTemplate renderObject:[Person personWithName:@"Arthur"]
                                          fromResource:@"Profile"  // loads `Profile.mustache`
                                                bundle:nil
                                                 error:NULL];

Documentation

GRMustache online documentation is provided as guides and sample code:

FAQ

  • Q: How do I render array indexes?

    A: Check Guides/sample_code/indexes.md

  • Q: How do I implement filters, format numbers, dates, etc?

    A: Check documentation of Mustache lambda sections first. If it would not help, maybe you'll get some inspiration from the number formatting sample code. If you are still stuck after those, go and look for a closed issue that covers your need. Finally, open a new issue :-)

  • Q: How do I render default values for missing keys?

    A: This can be done by providing your template a delegate: check Guides/delegate.md.

  • Q: I have a bunch of template partials that live in memory, not in the file system. How do I include them?

    A: Check Guides/template_repositories.md.

  • Q: What is this NSUndefinedKeyException stuff?

    A: When GRMustache has to try several objects until it finds the one that provides a {{key}}, several NSUndefinedKeyException are raised and caught. Let us double guess you: it's likely that you wish Xcode would stop breaking on those exceptions. This use case is covered in Guides/runtime/context_stack.md.

Contribution wish-list

I wish somebody would review my non-native English, and clean up the guides, if you ask.

Forking

Please fork. You'll learn useful information in Guides/forking.md.

License

Released under the MIT License

Copyright (c) 2012 Gwendal Roué

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Jump to Line
Something went wrong with that request. Please try again.