to_spreadsheet 0.9 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/README.rdoc +61 -0
  2. data/Rakefile +3 -11
  3. data/lib/to_spreadsheet/action_pack_renderers.rb +1 -0
  4. data/lib/to_spreadsheet/version.rb +1 -1
  5. data/lib/to_spreadsheet/xls.rb +20 -3
  6. metadata +18 -63
  7. data/README +0 -48
  8. data/test/test_app/Gemfile +0 -10
  9. data/test/test_app/Gemfile.lock +0 -88
  10. data/test/test_app/README +0 -1
  11. data/test/test_app/Rakefile +0 -7
  12. data/test/test_app/app/controllers/application_controller.rb +0 -3
  13. data/test/test_app/app/controllers/contacts_controller.rb +0 -7
  14. data/test/test_app/app/models/contact.rb +0 -3
  15. data/test/test_app/app/views/contacts/_table.erb +0 -24
  16. data/test/test_app/app/views/contacts/index.html.erb +0 -1
  17. data/test/test_app/app/views/contacts/index.xls.erb +0 -1
  18. data/test/test_app/app/views/layouts/application.html.erb +0 -7
  19. data/test/test_app/config/application.rb +0 -15
  20. data/test/test_app/config/boot.rb +0 -6
  21. data/test/test_app/config/database.yml +0 -22
  22. data/test/test_app/config/environment.rb +0 -5
  23. data/test/test_app/config/environments/development.rb +0 -26
  24. data/test/test_app/config/environments/production.rb +0 -49
  25. data/test/test_app/config/environments/test.rb +0 -35
  26. data/test/test_app/config/initializers/backtrace_silencers.rb +0 -7
  27. data/test/test_app/config/initializers/inflections.rb +0 -10
  28. data/test/test_app/config/initializers/mime_types.rb +0 -5
  29. data/test/test_app/config/initializers/secret_token.rb +0 -7
  30. data/test/test_app/config/initializers/session_store.rb +0 -8
  31. data/test/test_app/config/locales/en.yml +0 -5
  32. data/test/test_app/config/routes.rb +0 -4
  33. data/test/test_app/config.ru +0 -4
  34. data/test/test_app/db/development.sqlite3 +0 -0
  35. data/test/test_app/db/migrate/01_create_contacts.rb +0 -15
  36. data/test/test_app/db/schema.rb +0 -21
  37. data/test/test_app/db/seeds.rb +0 -7
  38. data/test/test_app/db/test.sqlite3 +0 -0
  39. data/test/test_app/log/development.log +0 -509
  40. data/test/test_app/log/production.log +0 -0
  41. data/test/test_app/log/server.log +0 -0
  42. data/test/test_app/log/test.log +0 -104
  43. data/test/test_app/script/rails +0 -6
  44. data/test/test_app/test/fixtures/contacts.yml +0 -5
  45. data/test/test_app/test/integration/rails_integration_test.rb +0 -14
  46. data/test/test_app/test/test_helper.rb +0 -7
  47. data/test/test_app/test/unit/contact_test.rb +0 -7
  48. data/test/test_helper.rb +0 -1
data/README.rdoc ADDED
@@ -0,0 +1,61 @@
1
+ to_spreadsheet is a gem that lets you render xls from your existing haml/erb views from Rails (>= 3.0).
2
+
3
+ = Installation
4
+
5
+ Add it to your Gemfile:
6
+
7
+ gem 'to_spreadsheet'
8
+
9
+ = Usage
10
+
11
+ In your controller:
12
+
13
+ class MyThingiesController < ApplicationController
14
+ respond_to :xls, :html
15
+
16
+ def index
17
+ @my_thingies = MyThingie.all
18
+ respond_with(@my_thingies)
19
+ end
20
+ end
21
+
22
+ In your view partial:
23
+
24
+ # _my_thingie.haml
25
+ %table
26
+ %caption My thingies
27
+ %thead
28
+ %tr
29
+ %td ID
30
+ %td Name
31
+ %tbody
32
+ - my_thingies.each do |thingie|
33
+ %tr
34
+ %td.number= thingie.id
35
+ %td= thingie.name
36
+ %tfoot
37
+ %tr
38
+ %td(colspan="2") #{my_thingies.length}
39
+
40
+ In your index.xls.haml:
41
+
42
+ = render 'my_thingies', :my_thingies => @my_thingies
43
+
44
+ In your index.html.haml:
45
+
46
+ = link_to 'Download XLS', my_thingies_url(:format => :xls)
47
+ = render 'my_thingies', :my_thingies => @my_thingies
48
+
49
+ == Formatting
50
+
51
+ You can use class names on td/th for typed values. Here is the list of class to type mapping:
52
+
53
+ | /num|int/ | Number format |
54
+ | /datetime/ | DateTime format |
55
+ | /date/ | Date format |
56
+ | /time/ | Time format |
57
+
58
+ == Worksheets
59
+
60
+ Every table in the view will be converted to a separate sheet.
61
+ The sheet title will be assigned to the value of the table's <caption> element if it exists.
data/Rakefile CHANGED
@@ -7,15 +7,7 @@ rescue LoadError
7
7
  end
8
8
 
9
9
  require 'rake'
10
- require 'rake/rdoctask'
10
+ require 'rdoc/task'
11
+ require 'rspec/core/rake_task'
11
12
 
12
- require 'rake/testtask'
13
-
14
- Rake::TestTask.new(:test) do |t|
15
- Dir.chdir('test/test_app')
16
- Kernel.exec('rake db:test:prepare')
17
- Kernel.exec('rake test')
18
- Dir.chdir('../..')
19
- end
20
-
21
- task :default => :test
13
+ RSpec::Core::RakeTask.new(:spec)
@@ -1,3 +1,4 @@
1
+ require 'active_support'
1
2
  require 'action_controller/metal/renderers'
2
3
  require 'action_controller/metal/responder'
3
4
 
@@ -1,3 +1,3 @@
1
1
  module ToSpreadsheet
2
- VERSION = '0.9'
2
+ VERSION = '0.9.2'
3
3
  end
@@ -5,12 +5,11 @@ module ToSpreadsheet
5
5
 
6
6
  def to_io(html)
7
7
  spreadsheet = Spreadsheet::Workbook.new
8
- Nokogiri::XML::Document.parse(html).xpath('/table').each_with_index do |xml_table, i|
8
+ Nokogiri::HTML::Document.parse(html).css('table').each_with_index do |xml_table, i|
9
9
  sheet = spreadsheet.create_worksheet(:name => xml_table.css('caption').inner_text.presence || "Sheet #{i + 1}")
10
10
  xml_table.css('tr').each_with_index do |row_node, row|
11
11
  row_node.css('th,td').each_with_index do |col_node, col|
12
- text = col_node.inner_text
13
- sheet[row,col] = text
12
+ sheet[row, col] = typed_node_val(col_node)
14
13
  end
15
14
  end
16
15
  end
@@ -19,5 +18,23 @@ module ToSpreadsheet
19
18
  io.rewind
20
19
  io
21
20
  end
21
+
22
+ private
23
+
24
+ def typed_node_val(node)
25
+ val = node.inner_text
26
+ case node[:class]
27
+ when /num|int/
28
+ val.to_i
29
+ when /datetime/
30
+ DateTime.parse(val)
31
+ when /date/
32
+ Date.parse(val)
33
+ when /time/
34
+ Time.parse(val)
35
+ else
36
+ val
37
+ end
38
+ end
22
39
  end
23
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_spreadsheet
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.9'
4
+ version: 0.9.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-03-21 00:00:00.000000000 +01:00
13
- default_executable:
12
+ date: 2012-01-18 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rails
17
- requirement: &21759828 !ruby/object:Gem::Requirement
16
+ requirement: &14495960 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: '0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *21759828
24
+ version_requirements: *14495960
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: nokogiri
28
- requirement: &21759552 !ruby/object:Gem::Requirement
27
+ requirement: &14495200 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: '0'
34
33
  type: :runtime
35
34
  prerelease: false
36
- version_requirements: *21759552
35
+ version_requirements: *14495200
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: spreadsheet
39
- requirement: &21759300 !ruby/object:Gem::Requirement
38
+ requirement: &14494480 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ! '>='
@@ -44,10 +43,10 @@ dependencies:
44
43
  version: '0'
45
44
  type: :runtime
46
45
  prerelease: false
47
- version_requirements: *21759300
46
+ version_requirements: *14494480
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: mocha
50
- requirement: &21759036 !ruby/object:Gem::Requirement
49
+ requirement: &14493480 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ! '>='
@@ -55,10 +54,10 @@ dependencies:
55
54
  version: '0'
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *21759036
57
+ version_requirements: *14493480
59
58
  - !ruby/object:Gem::Dependency
60
59
  name: sqlite3-ruby
61
- requirement: &21758748 !ruby/object:Gem::Requirement
60
+ requirement: &14489720 !ruby/object:Gem::Requirement
62
61
  none: false
63
62
  requirements:
64
63
  - - ! '>='
@@ -66,64 +65,22 @@ dependencies:
66
65
  version: '0'
67
66
  type: :development
68
67
  prerelease: false
69
- version_requirements: *21758748
70
- description: ! 'Rendering spreadsheets made easy: `respond_to :xls, :html`. `respond_with(@records)`. '
68
+ version_requirements: *14489720
69
+ description: Rendering spreadsheets from Rails made easy
71
70
  email: glex.spb@gmail.com
72
71
  executables: []
73
72
  extensions: []
74
73
  extra_rdoc_files:
75
- - README
74
+ - README.rdoc
76
75
  files:
77
- - README
76
+ - README.rdoc
78
77
  - LICENSE
79
78
  - Rakefile
80
79
  - lib/to_spreadsheet/action_pack_renderers.rb
80
+ - lib/to_spreadsheet/xls.rb
81
81
  - lib/to_spreadsheet/mime_types.rb
82
82
  - lib/to_spreadsheet/version.rb
83
- - lib/to_spreadsheet/xls.rb
84
83
  - lib/to_spreadsheet.rb
85
- - test/test_app/app/controllers/application_controller.rb
86
- - test/test_app/app/controllers/contacts_controller.rb
87
- - test/test_app/app/models/contact.rb
88
- - test/test_app/app/views/contacts/index.html.erb
89
- - test/test_app/app/views/contacts/index.xls.erb
90
- - test/test_app/app/views/contacts/_table.erb
91
- - test/test_app/app/views/layouts/application.html.erb
92
- - test/test_app/config/application.rb
93
- - test/test_app/config/boot.rb
94
- - test/test_app/config/database.yml
95
- - test/test_app/config/environment.rb
96
- - test/test_app/config/environments/development.rb
97
- - test/test_app/config/environments/production.rb
98
- - test/test_app/config/environments/test.rb
99
- - test/test_app/config/initializers/backtrace_silencers.rb
100
- - test/test_app/config/initializers/inflections.rb
101
- - test/test_app/config/initializers/mime_types.rb
102
- - test/test_app/config/initializers/secret_token.rb
103
- - test/test_app/config/initializers/session_store.rb
104
- - test/test_app/config/locales/en.yml
105
- - test/test_app/config/routes.rb
106
- - test/test_app/config.ru
107
- - test/test_app/db/development.sqlite3
108
- - test/test_app/db/migrate/01_create_contacts.rb
109
- - test/test_app/db/schema.rb
110
- - test/test_app/db/seeds.rb
111
- - test/test_app/db/test.sqlite3
112
- - test/test_app/Gemfile
113
- - test/test_app/Gemfile.lock
114
- - test/test_app/log/development.log
115
- - test/test_app/log/production.log
116
- - test/test_app/log/server.log
117
- - test/test_app/log/test.log
118
- - test/test_app/Rakefile
119
- - test/test_app/README
120
- - test/test_app/script/rails
121
- - test/test_app/test/fixtures/contacts.yml
122
- - test/test_app/test/integration/rails_integration_test.rb
123
- - test/test_app/test/test_helper.rb
124
- - test/test_app/test/unit/contact_test.rb
125
- - test/test_helper.rb
126
- has_rdoc: true
127
84
  homepage: https://github.com/glebm/to_spreadsheet
128
85
  licenses: []
129
86
  post_install_message:
@@ -144,10 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
101
  version: '0'
145
102
  requirements: []
146
103
  rubyforge_project:
147
- rubygems_version: 1.6.2
104
+ rubygems_version: 1.8.11
148
105
  signing_key:
149
106
  specification_version: 3
150
107
  summary: Adds various html -> spreadsheet (xls, odt, etc) renderers to Rails.
151
- test_files:
152
- - test/test_app/test/test_helper.rb
153
- - test/test_helper.rb
108
+ test_files: []
data/README DELETED
@@ -1,48 +0,0 @@
1
- to_spreadsheet is a gem that lets you render xls from your existing haml/erb views from Rails (>= 3.0).
2
-
3
- = Installation
4
-
5
- Add it to your Gemfile:
6
-
7
- gem 'to_spreadsheet'
8
-
9
-
10
- = Usage
11
-
12
- In your controller:
13
-
14
- class MyThingiesController < ApplicationController
15
- respond_to :xls, :html
16
-
17
- def index
18
- @my_thingies = MyThing.all
19
- respond_with(@my_thingies)
20
- end
21
- end
22
-
23
- In your view partial:
24
-
25
- # _my_thingies.haml
26
- %table
27
- %caption My thingies
28
- %thead
29
- %tr
30
- %td ID
31
- %td Name
32
- %tbody
33
- - @my_thingies.each do |thingie|
34
- %tr
35
- %td.number= thingie.id
36
- %td= thingie.name
37
- %tfoot
38
- %tr
39
- %td(colspan="2") #{@my_thingies.length}
40
-
41
- In your index.xls.haml:
42
-
43
- = render :partial => '_my_thingies', :collection => @my_thingies
44
-
45
- In your index.html.haml:
46
-
47
- = link_to 'Download XLS', my_thingies_url(:format => :xls)
48
- = render :partial => '_my_thingies', :collection => @my_thingies
@@ -1,10 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'rails', '> 3'
4
- gem 'sqlite3'
5
-
6
- gem 'to_spreadsheet', :path => '../..'
7
-
8
- group :test do
9
- gem 'mocha'
10
- end
@@ -1,88 +0,0 @@
1
- PATH
2
- remote: ../..
3
- specs:
4
- spreadsheet_renderer (0.9)
5
- nokogiri
6
- rails
7
- spreadsheet
8
-
9
- GEM
10
- remote: http://rubygems.org/
11
- specs:
12
- abstract (1.0.0)
13
- actionmailer (3.0.5)
14
- actionpack (= 3.0.5)
15
- mail (~> 2.2.15)
16
- actionpack (3.0.5)
17
- activemodel (= 3.0.5)
18
- activesupport (= 3.0.5)
19
- builder (~> 2.1.2)
20
- erubis (~> 2.6.6)
21
- i18n (~> 0.4)
22
- rack (~> 1.2.1)
23
- rack-mount (~> 0.6.13)
24
- rack-test (~> 0.5.7)
25
- tzinfo (~> 0.3.23)
26
- activemodel (3.0.5)
27
- activesupport (= 3.0.5)
28
- builder (~> 2.1.2)
29
- i18n (~> 0.4)
30
- activerecord (3.0.5)
31
- activemodel (= 3.0.5)
32
- activesupport (= 3.0.5)
33
- arel (~> 2.0.2)
34
- tzinfo (~> 0.3.23)
35
- activeresource (3.0.5)
36
- activemodel (= 3.0.5)
37
- activesupport (= 3.0.5)
38
- activesupport (3.0.5)
39
- arel (2.0.9)
40
- builder (2.1.2)
41
- erubis (2.6.6)
42
- abstract (>= 1.0.0)
43
- i18n (0.5.0)
44
- mail (2.2.15)
45
- activesupport (>= 2.3.6)
46
- i18n (>= 0.4.0)
47
- mime-types (~> 1.16)
48
- treetop (~> 1.4.8)
49
- mime-types (1.16)
50
- mocha (0.9.12)
51
- nokogiri (1.4.4.1-x86-mingw32)
52
- polyglot (0.3.1)
53
- rack (1.2.2)
54
- rack-mount (0.6.13)
55
- rack (>= 1.0.0)
56
- rack-test (0.5.7)
57
- rack (>= 1.0)
58
- rails (3.0.5)
59
- actionmailer (= 3.0.5)
60
- actionpack (= 3.0.5)
61
- activerecord (= 3.0.5)
62
- activeresource (= 3.0.5)
63
- activesupport (= 3.0.5)
64
- bundler (~> 1.0)
65
- railties (= 3.0.5)
66
- railties (3.0.5)
67
- actionpack (= 3.0.5)
68
- activesupport (= 3.0.5)
69
- rake (>= 0.8.7)
70
- thor (~> 0.14.4)
71
- rake (0.8.7)
72
- ruby-ole (1.2.11.1)
73
- spreadsheet (0.6.5.2)
74
- ruby-ole (>= 1.0)
75
- sqlite3 (1.3.3-x86-mingw32)
76
- thor (0.14.6)
77
- treetop (1.4.9)
78
- polyglot (>= 0.3.1)
79
- tzinfo (0.3.25)
80
-
81
- PLATFORMS
82
- x86-mingw32
83
-
84
- DEPENDENCIES
85
- mocha
86
- rails (> 3)
87
- spreadsheet_renderer!
88
- sqlite3
data/test/test_app/README DELETED
@@ -1 +0,0 @@
1
- Test app for rails_spreadsheet gem
@@ -1,7 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
- require 'rake'
6
-
7
- TestApp::Application.load_tasks