GithubHelp home page GithubHelp logo

macdownapp / handlebars-objc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bertrand/handlebars-objc

3.0 5.0 5.0 1.08 MB

handlebars-objc is a feature-complete implementation of Handlebars.js for Objective-C

License: MIT License

HTML 39.88% CSS 1.32% Ruby 0.35% Objective-C 57.44% Shell 1.01%

handlebars-objc's Introduction

Build Status

handlebars-objc

handlebars-objc is a feature complete implementation of Handlebars.js v2.0 for Objective-C that is and will remain 100% compatible with the Javascript version.

What is Handlebars?

(Please see the main Handlebars site for a more thorough description of what Handlebars is).

In general, you should use handlebars if you need to generate text documents (HTML documents, for instance) and you want to maintain a clean separation between your views (the templates) and your model.

An increasingly popular option is to use Mustache for this purpose. Mustache is a very simple templating language available in most languages.

Unfortunately, using Mustache rapidly becomes an implementation nightmare when trying to implement localization, formatting of dates, and many other basic user interface needs. Developers quickly find themselves adding view-specific data into their model to circumvent the limitations of their templating system.

Handlebars is a pragmatic superset of Mustache that addresses most shortcomings of its ancestor with the addition of helpers and block helpers.

Helpers are small rendering functions provided by the hosting application that can be used in templates.

Helpers generally help formatting raw data from your models (think iso 8601 dates), while block helpers provide support for custom iterators and conditional constructs.

Block helpers have even been used to implement a clean cache-compatible compositional view system in Ruby on Rails at Fotonauts: the Reporter application (http://www.fotopedia.com/reporter) uses a compositional view system and is able to render its page exactly the same way server-side and client-side. It is written in Ruby, renders server-side templates within a Java front end using Handlebars.java and renders the exact same templates client-side using Handlebars.js.

All this thanks to Handlebars and a handful of very simple helpers shared between the Java and Javascript implementation.

Handlebars implementations are available for Javascript, Java, Ruby (via therubyracer) and PHP.

In short, if you're looking for a templating system with a clean view/model separation and want to render them in Objective-C and in Javascript (or Java), Handlebars is probably what you need.

Please note that some implementations of Mustache provide extensions similar to Handlebars, and if you intend to render your templates only on a Mac or an iPhone, I strongly suggest you take a look at GRMustache. GRMustache is a fantastic library.

Getting Started

Integrate handlebars-objc into your project

You have 3 options:

Render your first template

Add this import clause to your objective-C implementation:

#import <HBHandlebars/HBHandlebars.h>

Then add:

NSError* error = nil;
NSString* result = [HBHandlebars renderTemplateString:@"Hello {{value}}!" 
                                          withContext:@{ @"value" : @"Bertrand"} 
                                                error:&error]; 
NSLog(@"handlebars template evaluated to : %@", result); 

Run your application, and in your logs you should see "Hello Bertrand!".

Congratulations! You've just rendered your first Handlebars template.

Going Further

If you like to read reference documentation, read the Handlebars public API reference documentation.

Since handlebars-objc if fully compatible with handlebars.js, please refer to handlebars.js documentation for a complete description of handlebars syntax.

The doc folder contains some guides that will help you learn how to use handlebars-objc step by step:

handlebars-objc's People

Contributors

azu avatar bertrand avatar guillaumealgis avatar jonfriskics avatar luketheobscure avatar maximelm avatar nicolas-cherel avatar psclcosta avatar randomsequence avatar uranusjr avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

handlebars-objc's Issues

Swift support?

Looking at using Handlebars or something similar in an iOS app being written in Swift. What pitfalls do you think I should watch out for here or that I might be able to help fix?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.