first commit

This commit is contained in:
Jeena Paradies 2010-06-12 17:59:50 +02:00
commit 2bba8c5fee
122 changed files with 8389 additions and 0 deletions

47
lib/rails_extensions.rb Normal file
View file

@ -0,0 +1,47 @@
require "cfpropertylist/rbCFPropertyList"
class Array
def to_plist(options = {})
options[:plist_format] ||= CFPropertyList::List::FORMAT_BINARY
array = []
self.each do |a|
if a.is_a? ActiveRecord::Base
array << a.to_hash(options)
else
array << a
end
end
plist = CFPropertyList::List.new
plist.value = CFPropertyList.guess(array)
plist.to_str(options[:plist_format])
end
end
module ActionController
class Base
def render_with_plist(options = nil, extra_options = {}, &block)
if plist = options[:plist]
if plist.is_a? Array
filename = plist.first.class.name
else
filename = "#{plist.class.name}-#{plist.id}"
end
send_data(
plist.to_plist(options),
:type => Mime::PLIST,
:filename => "#{filename}.plist",
:disposition => 'inline'
)
else
render_without_plist(options, extra_options, &block)
end
end
alias_method_chain :render, :plist
end
end