Skip to content
Browse files

Initial commit: simple xls + test environment

  • Loading branch information...
0 parents commit 004081fb2662e507e5ea3c98c121688027714933 @glebm committed Mar 15, 2011
Showing with 719 additions and 0 deletions.
  1. +9 −0 .gitignore
  2. +1 −0 .idea/.name
  3. +7 −0 .idea/.rakeTasks
  4. +13 −0 Gemfile
  5. +110 −0 Gemfile.lock
  6. +24 −0 LICENSE
  7. +21 −0 Rakefile
  8. +7 −0 lib/to_spreadsheet.rb
  9. +21 −0 lib/to_spreadsheet/action_pack_renderers.rb
  10. +2 −0 lib/to_spreadsheet/mime_types.rb
  11. +3 −0 lib/to_spreadsheet/version.rb
  12. +23 −0 lib/to_spreadsheet/xls.rb
  13. +10 −0 test/test_app/Gemfile
  14. +88 −0 test/test_app/Gemfile.lock
  15. +1 −0 test/test_app/README
  16. +7 −0 test/test_app/Rakefile
  17. +3 −0 test/test_app/app/controllers/application_controller.rb
  18. +7 −0 test/test_app/app/controllers/contacts_controller.rb
  19. +3 −0 test/test_app/app/models/contact.rb
  20. +24 −0 test/test_app/app/views/contacts/_table.erb
  21. +1 −0 test/test_app/app/views/contacts/index.html.erb
  22. +1 −0 test/test_app/app/views/contacts/index.xls.erb
  23. +7 −0 test/test_app/app/views/layouts/application.html.erb
  24. +4 −0 test/test_app/config.ru
  25. +15 −0 test/test_app/config/application.rb
  26. +6 −0 test/test_app/config/boot.rb
  27. +22 −0 test/test_app/config/database.yml
  28. +5 −0 test/test_app/config/environment.rb
  29. +26 −0 test/test_app/config/environments/development.rb
  30. +49 −0 test/test_app/config/environments/production.rb
  31. +35 −0 test/test_app/config/environments/test.rb
  32. +7 −0 test/test_app/config/initializers/backtrace_silencers.rb
  33. +10 −0 test/test_app/config/initializers/inflections.rb
  34. +5 −0 test/test_app/config/initializers/mime_types.rb
  35. +7 −0 test/test_app/config/initializers/secret_token.rb
  36. +8 −0 test/test_app/config/initializers/session_store.rb
  37. +5 −0 test/test_app/config/locales/en.yml
  38. +4 −0 test/test_app/config/routes.rb
  39. +15 −0 test/test_app/db/migrate/01_create_contacts.rb
  40. +21 −0 test/test_app/db/schema.rb
  41. +7 −0 test/test_app/db/seeds.rb
  42. +6 −0 test/test_app/script/rails
  43. +5 −0 test/test_app/test/fixtures/contacts.yml
  44. +14 −0 test/test_app/test/integration/rails_integration_test.rb
  45. +7 −0 test/test_app/test/test_helper.rb
  46. +7 −0 test/test_app/test/unit/contact_test.rb
  47. +1 −0 test/test_helper.rb
  48. +35 −0 to_spreadsheet.gemspec
9 .gitignore
@@ -0,0 +1,9 @@
+.idea/
+.bundle/
+log/*.log
+pkg/
+
+test/test_app/.bundle/
+test/test_app/db/*.sqlite3
+test/test_app/log/*.log
+test/test_app/tmp/
1 .idea/.name
@@ -0,0 +1 @@
+rails_spreadsheets
7 .idea/.rakeTasks
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Settings><!--This file was automatically generated by Ruby plugin.
+You are allowed to:
+1. Remove rake task
+2. Add existing rake tasks
+To add existing rake tasks automatically delete this file and reload the project.
+--><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
13 Gemfile
@@ -0,0 +1,13 @@
+source "http://rubygems.org"
+
+gem "rails", "> 3"
+gem 'spreadsheet'
+gem 'nokogiri'
+
+group :test do
+ gem "capybara", ">= 0.4.0"
+ gem "sqlite3-ruby", :require => "sqlite3"
+ gem "mocha"
+ gem "nokogiri"
+ gem "shoulda"
+end
110 Gemfile.lock
@@ -0,0 +1,110 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.5)
+ actionpack (= 3.0.5)
+ mail (~> 2.2.15)
+ actionpack (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ activesupport (3.0.5)
+ arel (2.0.9)
+ builder (2.1.2)
+ capybara (0.4.1.2)
+ celerity (>= 0.7.9)
+ culerity (>= 0.2.4)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (>= 0.0.27)
+ xpath (~> 0.1.3)
+ celerity (0.8.8)
+ childprocess (0.1.7)
+ ffi (~> 0.6.3)
+ culerity (0.2.15)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ ffi (0.6.3-x86-mingw32)
+ rake (>= 0.8.7)
+ i18n (0.5.0)
+ json_pure (1.5.1)
+ mail (2.2.15)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ mocha (0.9.12)
+ nokogiri (1.4.4.1-x86-mingw32)
+ polyglot (0.3.1)
+ rack (1.2.2)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.5)
+ actionmailer (= 3.0.5)
+ actionpack (= 3.0.5)
+ activerecord (= 3.0.5)
+ activeresource (= 3.0.5)
+ activesupport (= 3.0.5)
+ bundler (~> 1.0)
+ railties (= 3.0.5)
+ railties (3.0.5)
+ actionpack (= 3.0.5)
+ activesupport (= 3.0.5)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ ruby-ole (1.2.11.1)
+ rubyzip (0.9.4)
+ selenium-webdriver (0.1.3)
+ childprocess (~> 0.1.5)
+ ffi (~> 0.6.3)
+ json_pure
+ rubyzip
+ shoulda (2.11.3)
+ spreadsheet (0.6.5.2)
+ ruby-ole (>= 1.0)
+ sqlite3 (1.3.3-x86-mingw32)
+ sqlite3-ruby (1.3.3)
+ sqlite3 (>= 1.3.3)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.25)
+ xpath (0.1.3)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ x86-mingw32
+
+DEPENDENCIES
+ capybara (>= 0.4.0)
+ mocha
+ nokogiri
+ rails (> 3)
+ shoulda
+ spreadsheet
+ sqlite3-ruby
24 LICENSE
@@ -0,0 +1,24 @@
+LICENSE
+
+The MIT License
+
+Copyright 2011 Gleb Mazovetskiy
+
+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.
21 Rakefile
@@ -0,0 +1,21 @@
+# encoding: UTF-8
+require 'rubygems'
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+
+require 'rake'
+require 'rake/rdoctask'
+
+require 'rake/testtask'
+
+Rake::TestTask.new(:test) do |t|
+ Dir.chdir('test/test_app')
+ Kernel.exec('rake db:test:prepare')
+ Kernel.exec('rake test')
+ Dir.chdir('../..')
+end
+
+task :default => :test
7 lib/to_spreadsheet.rb
@@ -0,0 +1,7 @@
+require 'nokogiri'
+require 'to_spreadsheet/action_pack_renderers'
+require 'to_spreadsheet/mime_types'
+
+module ToSpreadsheet
+
+end
21 lib/to_spreadsheet/action_pack_renderers.rb
@@ -0,0 +1,21 @@
+require 'action_controller/metal/renderers'
+require 'action_controller/metal/responder'
+
+require 'to_spreadsheet/xls'
+
+# This will let us do thing like `render :xls => 'index'`
+# This is also how Rails internally implements its :json and :xml renderers
+# Rarely used, nevertheless public API
+ActionController::Renderers.add :xls do |template, options|
+ send_data ToSpreadsheet::XLS.to_io(render_to_string(template, options)).read, :type => :xls
+end
+
+class ActionController::Responder
+ # This sets up a default render call for when you do
+ # respond_to do |format|
+ # format.xls
+ # end
+ def to_xls
+ controller.render :xls => controller.action_name
+ end
+end
2 lib/to_spreadsheet/mime_types.rb
@@ -0,0 +1,2 @@
+require 'action_dispatch/http/mime_type'
+Mime::Type.register "application/vnd.ms-excel", :xls
3 lib/to_spreadsheet/version.rb
@@ -0,0 +1,3 @@
+module ToSpreadsheet
+ VERSION = '0.9'
+end
23 lib/to_spreadsheet/xls.rb
@@ -0,0 +1,23 @@
+module ToSpreadsheet
+ require 'spreadsheet'
+ module XLS
+ extend self
+
+ def to_io(html)
+ spreadsheet = Spreadsheet::Workbook.new
+ Nokogiri::XML::Document.parse(html).xpath('/table').each_with_index do |xml_table, i|
+ sheet = spreadsheet.create_worksheet(:name => xml_table.css('caption').inner_text.presence || "Sheet #{i + 1}")
+ xml_table.css('tr').each_with_index do |row_node, row|
+ row_node.css('th,td').each_with_index do |col_node, col|
+ text = col_node.inner_text
+ sheet[row,col] = text
+ end
+ end
+ end
+ io = StringIO.new
+ spreadsheet.write(io)
+ io.rewind
+ io
+ end
+ end
+end
10 test/test_app/Gemfile
@@ -0,0 +1,10 @@
+source 'http://rubygems.org'
+
+gem 'rails', '> 3'
+gem 'sqlite3'
+
+gem 'to_spreadsheet', :path => '../..'
+
+group :test do
+ gem 'mocha'
+end
88 test/test_app/Gemfile.lock
@@ -0,0 +1,88 @@
+PATH
+ remote: ../..
+ specs:
+ spreadsheet_renderer (0.9)
+ nokogiri
+ rails
+ spreadsheet
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.5)
+ actionpack (= 3.0.5)
+ mail (~> 2.2.15)
+ actionpack (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ activesupport (3.0.5)
+ arel (2.0.9)
+ builder (2.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.5.0)
+ mail (2.2.15)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ mocha (0.9.12)
+ nokogiri (1.4.4.1-x86-mingw32)
+ polyglot (0.3.1)
+ rack (1.2.2)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.5)
+ actionmailer (= 3.0.5)
+ actionpack (= 3.0.5)
+ activerecord (= 3.0.5)
+ activeresource (= 3.0.5)
+ activesupport (= 3.0.5)
+ bundler (~> 1.0)
+ railties (= 3.0.5)
+ railties (3.0.5)
+ actionpack (= 3.0.5)
+ activesupport (= 3.0.5)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ ruby-ole (1.2.11.1)
+ spreadsheet (0.6.5.2)
+ ruby-ole (>= 1.0)
+ sqlite3 (1.3.3-x86-mingw32)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.25)
+
+PLATFORMS
+ x86-mingw32
+
+DEPENDENCIES
+ mocha
+ rails (> 3)
+ spreadsheet_renderer!
+ sqlite3
1 test/test_app/README
@@ -0,0 +1 @@
+Test app for rails_spreadsheet gem
7 test/test_app/Rakefile
@@ -0,0 +1,7 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+require 'rake'
+
+TestApp::Application.load_tasks
3 test/test_app/app/controllers/application_controller.rb
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
7 test/test_app/app/controllers/contacts_controller.rb
@@ -0,0 +1,7 @@
+class ContactsController < ApplicationController
+ respond_to :xls, :html
+ def index
+ @contacts = Contact.all
+ respond_with(@contacts)
+ end
+end
3 test/test_app/app/models/contact.rb
@@ -0,0 +1,3 @@
+class Contact < ActiveRecord::Base
+ # name, website, age
+end
24 test/test_app/app/views/contacts/_table.erb
@@ -0,0 +1,24 @@
+<table>
+ <caption>Test caption</caption>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Website</th>
+ <th>Age</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% contacts.each do |contact| %>
+ <tr>
+ <td><%= contact.name %></td>
+ <td><%= contact.website %></td>
+ <td><%= contact.age %></td>
+ </tr>
+ <% end %>
+ </tbody>
+ <tfoot>
+ <tr>
+ <td>footer stuff</td>
+ </tr>
+ </tfoot>
+</table>
1 test/test_app/app/views/contacts/index.html.erb
@@ -0,0 +1 @@
+<%= render 'contacts/table', :contacts => @contacts %>
1 test/test_app/app/views/contacts/index.xls.erb
@@ -0,0 +1 @@
+<%= render 'contacts/table', :contacts => @contacts %>
7 test/test_app/app/views/layouts/application.html.erb
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+<head></head>
+<body>
+<%= yield %>
+</body>
+</html>
4 test/test_app/config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run TestApp::Application
15 test/test_app/config/application.rb
@@ -0,0 +1,15 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
+module TestApp
+ class Application < Rails::Application
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+ end
+end
6 test/test_app/config/boot.rb
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
22 test/test_app/config/database.yml
@@ -0,0 +1,22 @@
+# SQLite version 3.x
+# gem install sqlite3
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
5 test/test_app/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+TestApp::Application.initialize!
26 test/test_app/config/environments/development.rb
@@ -0,0 +1,26 @@
+TestApp::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the webserver when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_view.debug_rjs = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+end
+
49 test/test_app/config/environments/production.rb
@@ -0,0 +1,49 @@
+TestApp::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # The production environment is meant for finished, "live" apps.
+ # Code is not reloaded between requests
+ config.cache_classes = true
+
+ # Full error reports are disabled and caching is turned on
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Specifies the header that your server uses for sending files
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
+
+ # For nginx:
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
+
+ # If you have no front-end server that supports something like X-Sendfile,
+ # just comment this out and Rails will serve the files
+
+ # See everything in the log (default is :info)
+ # config.log_level = :debug
+
+ # Use a different logger for distributed setups
+ # config.logger = SyslogLogger.new
+
+ # Use a different cache store in production
+ # config.cache_store = :mem_cache_store
+
+ # Disable Rails's static asset server
+ # In production, Apache or nginx will already do this
+ config.serve_static_assets = false
+
+ # Enable serving of images, stylesheets, and javascripts from an asset server
+ # config.action_controller.asset_host = "http://assets.example.com"
+
+ # Disable delivery errors, bad email addresses will be ignored
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable threaded mode
+ # config.threadsafe!
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation can not be found)
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners
+ config.active_support.deprecation = :notify
+end
35 test/test_app/config/environments/test.rb
@@ -0,0 +1,35 @@
+TestApp::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Print deprecation notices to the stderr
+ config.active_support.deprecation = :stderr
+end
7 test/test_app/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
10 test/test_app/config/initializers/inflections.rb
@@ -0,0 +1,10 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
5 test/test_app/config/initializers/mime_types.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
7 test/test_app/config/initializers/secret_token.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+TestApp::Application.config.secret_token = 'c362f09b453ec024bd3095ac4dcaa4e2e4205195349962f8ce03094a7644679625ea123c322123a33da3a6bd040998a7df03efcf3073bbc179b2c3ab2f542cc4'
8 test/test_app/config/initializers/session_store.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+TestApp::Application.config.session_store :cookie_store, :key => '_test_app_session'
+
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with "rails generate session_migration")
+# TestApp::Application.config.session_store :active_record_store
5 test/test_app/config/locales/en.yml
@@ -0,0 +1,5 @@
+# Sample localization file for English. Add more files in this directory for other locales.
+# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+en:
+ hello: "Hello world"
4 test/test_app/config/routes.rb
@@ -0,0 +1,4 @@
+TestApp::Application.routes.draw do
+ resources :contacts
+ root :to => redirect("/contacts.html")
+end
15 test/test_app/db/migrate/01_create_contacts.rb
@@ -0,0 +1,15 @@
+class CreateContacts < ActiveRecord::Migration
+ class << self
+ def up
+ create_table :contacts do |t|
+ t.string :name
+ t.string :website
+ t.integer :age
+ end
+ end
+
+ def down
+ drop_table :contacts
+ end
+ end
+end
21 test/test_app/db/schema.rb
@@ -0,0 +1,21 @@
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 1) do
+
+ create_table "contacts", :force => true do |t|
+ t.string "name"
+ t.string "website"
+ t.integer "age"
+ end
+
+end
7 test/test_app/db/seeds.rb
@@ -0,0 +1,7 @@
+# This file should contain all the record creation needed to seed the database with its default values.
+# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
+#
+# Examples:
+#
+# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
+# Mayor.create(:name => 'Daley', :city => cities.first)
6 test/test_app/script/rails
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby.exe
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+require File.expand_path('../../config/boot', __FILE__)
+require 'rails/commands'
5 test/test_app/test/fixtures/contacts.yml
@@ -0,0 +1,5 @@
+--- !omap
+- contact:
+ id: 1
+ name: Gleb Mazovetskiy
+ website: http://glebm.blogspot.com
14 test/test_app/test/integration/rails_integration_test.rb
@@ -0,0 +1,14 @@
+require 'test_helper'
+
+class RailsIntegrationTest < ActionController::IntegrationTest
+ fixtures :all
+ test "html" do
+ get '/contacts'
+ assert_response :success
+ end
+
+ test "xls" do
+ get '/contacts.xls'
+ assert_response :success
+ end
+end
7 test/test_app/test/test_helper.rb
@@ -0,0 +1,7 @@
+ENV["RAILS_ENV"] = "test"
+require File.expand_path('../../config/environment', __FILE__)
+require 'rails/test_help'
+
+class ActiveSupport::TestCase
+ fixtures :all
+end
7 test/test_app/test/unit/contact_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ContactTest < ActiveSupport::TestCase
+ def test_contact
+ assert_equal 1, Contact.count
+ end
+end
1 test/test_helper.rb
@@ -0,0 +1 @@
+require 'test/test_app'
35 to_spreadsheet.gemspec
@@ -0,0 +1,35 @@
+$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
+require 'to_spreadsheet/version'
+
+include_files = ["README*", "LICENSE", "Rakefile", "init.rb",
+ "{lib,tasks,test,rails,generators,shoulda_macros}/**/*"].map do |glob|
+ Dir[glob]
+end.flatten
+
+exclude_files = ["**/*.rbc", "test/s3.yml", "test/debug.log", "test/to_spreadsheet.db", "test/doc", "test/doc/*",
+ "test/pkg", "test/pkg/*", "test/tmp", "test/tmp/*"].map do |glob|
+ Dir[glob]
+end.flatten
+
+
+Gem::Specification.new do |s|
+ s.name = "to_spreadsheet"
+ s.email = "glex.spb@gmail.com"
+ s.author = "Gleb Mazovetskiy"
+ s.homepage = "https://github.com/glebm/to_spreadsheet"
+ s.summary = "Adds various html -> spreadsheet (xls, odt, etc) renderers to Rails."
+ s.description = "Rendering spreadsheets made easy: `respond_to :xls, :html`. `respond_with(@records)`. "
+ s.files = Dir["lib/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
+ s.version = ToSpreadsheet::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.files = include_files - exclude_files
+ s.require_path = "lib"
+ s.test_files = Dir["test/**/test_*.rb"]
+ s.has_rdoc = true
+ s.extra_rdoc_files = Dir["README*"]
+ s.add_dependency 'rails'
+ s.add_dependency 'nokogiri'
+ s.add_dependency 'spreadsheet'
+ s.add_development_dependency 'mocha'
+ s.add_development_dependency 'sqlite3-ruby'
+end

0 comments on commit 004081f

Please sign in to comment.
Something went wrong with that request. Please try again.