No description
This repository has been archived on 2025-08-18. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Find a file
2010-06-18 17:57:32 +02:00
lib added documentation about :plist_filename 2010-06-18 17:57:32 +02:00
init.rb first commit 2010-06-12 17:59:50 +02:00
MIT-LICENSE first commit 2010-06-12 17:59:50 +02:00
README added documentation about :plist_filename 2010-06-18 17:57:32 +02:00

Plistifier
==========

Adds the ActiveRecord#to_plist and Array#to_plist methods similar to ActiveRecord#to_xml.
The :only, :except, :methods, and :include options are supported. Additionally you can use
the :plist_filename option to change the default name for download.

It too ads the :plist option to the ActiveRecord::Base#render method. With help of that
you get binary plist files which you can easy use in your iPhone.


Install
=======

script/plugin install git://github.com/jeena/plistifier.git


Example
=======

In your PostController use for example:

	def index
	  @posts = Post.all

	  respond_to do |format|
	    format.html # index.html.erb
	    format.xml  { render :xml => @posts }
	    format.plist { render :plist => @posts, :only => [:id, :title] }
	  end
	end

	def show
	  @post = Post.find(params[:id])

	  respond_to do |format|
	    format.html # show.html.erb
	    format.xml  { render :xml => @post }
			format.plist { render :plist => @post }
	  end
	end
	
	def show
	  @post = Post.find(params[:id])

	  respond_to do |format|
			format.plist { render :plist => @post, :plist_filename => "a-testfile.plist" }
	  end
	end
	
On the iPhone use for example:

	NSURL *url = [NSURL URLWithString:@"http://example.com/posts.plist"];
	NSArray *posts = [[NSArray alloc] initWithContentsOfURL:url];
	NSLog(@"Title: %@", [[posts objectAtIndex:0] objectForKey:@"title"]);
	

Thanks
======

This plugin uses Christian Kruses CFPropertyList http://github.com/ckruse/CFPropertyList
to generate Plists.

This plugin started as a copy of http://github.com/chuyeow/jsonifier/ I just changed it to
support and added the CFPropertyList stuff.


Copyright (c) 2010 Jeena Paradies, released under the MIT license