Skip to content

Commit

Permalink
Initial commit: simple xls + test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Mar 15, 2011
0 parents commit 004081f
Show file tree
Hide file tree
Showing 48 changed files with 719 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .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 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/.rakeTasks

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions 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 changes: 110 additions & 0 deletions 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 changes: 24 additions & 0 deletions 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 changes: 21 additions & 0 deletions 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 changes: 7 additions & 0 deletions 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 changes: 21 additions & 0 deletions 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 changes: 2 additions & 0 deletions 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 changes: 3 additions & 0 deletions lib/to_spreadsheet/version.rb
@@ -0,0 +1,3 @@
module ToSpreadsheet
VERSION = '0.9'
end
23 changes: 23 additions & 0 deletions 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 changes: 10 additions & 0 deletions 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 changes: 88 additions & 0 deletions 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 change: 1 addition & 0 deletions test/test_app/README
@@ -0,0 +1 @@
Test app for rails_spreadsheet gem
7 changes: 7 additions & 0 deletions 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 changes: 3 additions & 0 deletions test/test_app/app/controllers/application_controller.rb
@@ -0,0 +1,3 @@
class ApplicationController < ActionController::Base
protect_from_forgery
end
7 changes: 7 additions & 0 deletions 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 changes: 3 additions & 0 deletions test/test_app/app/models/contact.rb
@@ -0,0 +1,3 @@
class Contact < ActiveRecord::Base
# name, website, age
end

0 comments on commit 004081f

Please sign in to comment.