Skip to content

Production-ready {{ Mustache }} templates for MacOS Cocoa and iOS

License

Notifications You must be signed in to change notification settings

pierlis/GRMustache

 
 

Repository files navigation

GRMustache

GRMustache is a flexible and production-ready implementation of Mustache templates for MacOS Cocoa and iOS.

GRMustache targets iOS down to version 4.3, MacOS down to 10.6 Snow Leopard (with or without garbage collection), and only depends on the Foundation framework.

January 30, 2013: GRMustache 6.3.0 is out. Release notes

Don't miss a single release: follow @GRMustache on Twitter.

How To

1. Setup your Xcode project

Option 1: CocoaPods

Dear CocoaPods users, append pod 'GRMustache', '~> 6.3' to your Podfile.

Option 2: Static Library

The distribution includes pre-built static libraries:

Clone the repository with the git clone https://github.com/groue/GRMustache.git command.

  • For MacOS development, add include/GRMustache.h and lib/libGRMustache6-MacOS.a to your project.
  • For iOS development, add include/GRMustache.h and lib/libGRMustache6-iOS.a to your project.

If you have GRMustache files copied in your project, you'll need to copy all header files of the include directory, not only GRMustache.h.

The armv6 slice is not included. In order to target this architecture, you have to compile GRMustache yourself (see below), or to use CocoaPods (see above).

Option 3: Compiling the raw sources

You may also embed the raw GRMustache sources in your project:

$ git clone https://github.com/groue/GRMustache.git
$ cd GRMustache
$ git checkout v6.3.0  # checkout the latest stable release
$ git submodule update --init src/vendor/groue/jrswizzle

Add all files of src/classes plus src/vendor/groue/jrswizzle/JRSwizzle.* to your project.

If your project uses ARC, flag the source files with the -fno-objc-arc compiler flag (how to).

In your own sources, avoid importing header files whose name ends with _private.h: those are private headers that may change, without notice, in future releases.

2. Start rendering templates

#import "GRMustache.h"

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

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

GRMustachio by Jonathan Mitchell is "A super simple, interactive GRMustache based application". It can help you design and test your templates.

Documentation

Mustache syntax

Guides

Introduction:

  • Introduction: a tour of the library features, and most common use cases.

Loading templates:

Rendering templates:

Advanced GRMustache:

Compatibility with other Mustache implementations:

Sample code

Reference

  • Reference: the GRMustache reference, automatically generated from inline documentation, for fun and profit, by appledoc.

Internals

  • Forking: the forking guide tells you everything about GRMustache organization.

FAQ

  • Q: Is it possible to render array indexes? Customize first and last elements? Distinguish odd and even items, play fizzbuzz?

    A: Yes, yes, and yes

  • Q: Is it possible to format numbers and dates?

    A: Yes

  • Q: Is it possible to render partial templates whose name is only known at runtime?

    A: Yes

  • Q: Does GRMustache provide any layout or template inheritance facility?

    A: Yes

  • Q: Is it possible to localize templates?

    A: Yes

  • Q: Is it possible to render default values for missing keys?

    A: Yes

  • Q: Is it possible to disable HTML escaping?

    A: Yes

  • 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 the Runtime Guide.

  • Q: Why does GRMustache need JRSwizzle?

    A: GRMustache does not need it, and this swizzling is a mere convenience that will not ship in your released binary:

    You may be happy having GRMustache swizzle valueForUndefinedKey: in the NSObject class when you invoke [GRMustache preventNSUndefinedKeyExceptionAttack]: it allows you to debug your application without being interrupted by the NSUndefinedKeyException that may be raised and caught by template rendering. The use case is described in the Runtime Guide.

What other people say

@JeffSchilling:

I'm loving grmustache

@basilshkara:

Oh man GRMustache saved my ass once again. Awesome lib.

@guiheneuf:

GRMustache filters extension saved us from great escaping PITAs. Thanks @groue.

@orj:

Thank fucking christ for decent iOS developers who ship .lib files in their Github repos. #GRMustache

@SebastienPeek

@issya should see the HTML template I built, pretty wicked. GRMustache is the best.

@mugginsoft

Using GRMustache (Cocoa) for template processing. Looks like a top quality library. Good developer and good units tests. Get it on GitHub.

Popular projects & apps using GRMustache

  • tomaz/appledoc: Objective-c code Apple style documentation set generator
  • mapbox/mapbox-ios-sdk: MapBox iOS SDK, an open source alternative to MapKit
  • CarterA/Tribo: Extremely fast static site generator written in Objective-C
  • AutoLib uses GRMustache and spullara/mustache.java for rendering an identical set of Mustache templates on iOS and Android.
  • CinéObs uses GRMustache for RSS feeds rendering
  • Fotopedia, the first collaborative photo encyclopedia
  • FunGolf GPS, a golf app with 3D maps
  • KosmicTask, an integrated scripting environment for OS X that supports more than 20 scripting languages.

Contribution wish-list

Please look for an open issue that smiles at you!

... And I wish somebody would review the non-native English of the documentation and guides.

Forking

Please fork. You'll learn useful information in the Forking Guide.

License

Released under the MIT License.

About

Production-ready {{ Mustache }} templates for MacOS Cocoa and iOS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 95.9%
  • C 3.1%
  • Racket 1.0%