Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

init to_csv plugin

  • Loading branch information...
commit ffdc8cd292a9c6a844e8f94b643b2b5bac89630c 0 parents
wenke.liang authored
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2010 [name of plugin creator]
+
+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.
28 README
@@ -0,0 +1,28 @@
+== to_csv plugin
+
+Introduction goes here.
+
+
+== Usage
+
+ @posts.to_csv
+
+
+== Example
+
+# class PostsController < ApplicationController
+# def index
+# @posts = Post.all
+#
+# respond_to do |format|
+# format.csv { send_data(@posts.to_csv) }
+# #format.csv {
+# # filename = "posts-#{Time.now.strftime("%Y%m%d%H%M%S")}.csv"
+# # send_data(@posts.to_csv, :type => "text/csv; charset=utf-8; header=present", :filename => filename)
+# }
+# end
+# end
+# end
+
+
+Copyright (c) 2010 Wenke Liang, released under the MIT license
23 Rakefile
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the to_csv plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the to_csv plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'ToCsv'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
1  init.rb
@@ -0,0 +1 @@
+require 'to_csv'
1  install.rb
@@ -0,0 +1 @@
+# Install hook code here
31 lib/to_csv.rb
@@ -0,0 +1,31 @@
+class Array
+
+# Example
+#
+# class PostsController < ApplicationController
+# def index
+# @posts = Post.all
+#
+# respond_to do |format|
+# format.csv { send_data(@posts.to_csv) }
+# #format.csv {
+# # filename = "posts-#{Time.now.strftime("%Y%m%d%H%M%S")}.csv"
+# # send_data(@posts.to_csv, :type => "text/csv; charset=utf-8; header=present", :filename => filename)
+# }
+# end
+# end
+# end
+
+ def to_csv
+ if self.any?
+ #columns = self.first.class.content_columns
+ columns = self.first.class.columns
+ header = columns.collect(&:human_name)
+ contents = []
+ self.each do |obj|
+ contents << columns.collect{ |column| obj.send(column.name) }.join(', ')
+ end
+ header.join(', ') + "\n" + contents.join("\n")
+ end
+ end
+end
4 tasks/to_csv_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :to_csv do
+# # Task goes here
+# end
3  test/test_helper.rb
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case'
8 test/to_csv_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class ToCsvTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
1  uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here
Please sign in to comment.
Something went wrong with that request. Please try again.