axlsx_rails 0.1.0

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 (70) hide show
  1. data/CHANGELOG.md +9 -0
  2. data/Gemfile +17 -0
  3. data/Gemfile.lock +196 -0
  4. data/Guardfile +15 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +68 -0
  7. data/Rakefile +29 -0
  8. data/lib/axlsx_rails.rb +4 -0
  9. data/lib/axlsx_rails/action_controller.rb +16 -0
  10. data/lib/axlsx_rails/template_handler.rb +24 -0
  11. data/lib/axlsx_rails/version.rb +3 -0
  12. data/lib/tasks/axlsx_rails_tasks.rake +4 -0
  13. data/spec/axlsx_builder_spec.rb +34 -0
  14. data/spec/axlsx_renderer_spec.rb +13 -0
  15. data/spec/axlsx_request_spec.rb +40 -0
  16. data/spec/dummy/README.rdoc +261 -0
  17. data/spec/dummy/Rakefile +7 -0
  18. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  19. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  20. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  21. data/spec/dummy/app/controllers/home_controller.rb +20 -0
  22. data/spec/dummy/app/controllers/users_controller.rb +12 -0
  23. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  24. data/spec/dummy/app/models/user.rb +5 -0
  25. data/spec/dummy/app/views/home/index.html.erb +2 -0
  26. data/spec/dummy/app/views/home/index.xlsx.axlsx +8 -0
  27. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  28. data/spec/dummy/app/views/users/index.html.erb +29 -0
  29. data/spec/dummy/app/views/users/index.xlsx.axlsx +1 -0
  30. data/spec/dummy/config.ru +4 -0
  31. data/spec/dummy/config/application.rb +65 -0
  32. data/spec/dummy/config/boot.rb +10 -0
  33. data/spec/dummy/config/database.yml +11 -0
  34. data/spec/dummy/config/environment.rb +5 -0
  35. data/spec/dummy/config/environments/development.rb +37 -0
  36. data/spec/dummy/config/environments/production.rb +67 -0
  37. data/spec/dummy/config/environments/test.rb +37 -0
  38. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/spec/dummy/config/initializers/inflections.rb +15 -0
  40. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  41. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  42. data/spec/dummy/config/initializers/session_store.rb +8 -0
  43. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  44. data/spec/dummy/config/locales/en.yml +5 -0
  45. data/spec/dummy/config/routes.rb +6 -0
  46. data/spec/dummy/db/development.sqlite3 +0 -0
  47. data/spec/dummy/db/migrate/20120717192452_create_users.rb +12 -0
  48. data/spec/dummy/db/schema.rb +25 -0
  49. data/spec/dummy/db/test.sqlite3 +0 -0
  50. data/spec/dummy/log/development.log +125 -0
  51. data/spec/dummy/log/test.log +1396 -0
  52. data/spec/dummy/public/404.html +26 -0
  53. data/spec/dummy/public/422.html +26 -0
  54. data/spec/dummy/public/500.html +25 -0
  55. data/spec/dummy/public/favicon.ico +0 -0
  56. data/spec/dummy/script/rails +6 -0
  57. data/spec/dummy/tmp/cache/assets/C8C/B80/sprockets%2F371bf96e99717688ed7313a0c53f4212 +0 -0
  58. data/spec/dummy/tmp/cache/assets/CAC/7D0/sprockets%2F7810ea6f766208553a05d1056cd74f1e +0 -0
  59. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  60. data/spec/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
  61. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  62. data/spec/dummy/tmp/cache/assets/D34/930/sprockets%2Fd2c70e485fe1100075be3bc87cf1e282 +0 -0
  63. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  64. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  65. data/spec/dummy/tmp/cache/assets/D96/AA0/sprockets%2F022a822848bf2eef8e7cb3c08ab932ba +0 -0
  66. data/spec/dummy/tmp/cache/assets/DC1/E00/sprockets%2F20fddc9f3fca3616a6c5ea413a464a4e +0 -0
  67. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  68. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  69. data/spec/spec_helper.rb +21 -0
  70. metadata +339 -0
@@ -0,0 +1,9 @@
1
+ # Change log
2
+ ---------
3
+ - **July 17, 2012**: 0.1.0 release
4
+ * Tests completed
5
+ * Acts_as_xlsx tested, example in docs
6
+
7
+ - **July 12, 2012**: 0.0.1 release
8
+ * Initial posting.
9
+ * It works, but there are no tests! Bad programmer!
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in axlsx_rails.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # jquery-rails is used by the dummy application
9
+ gem "jquery-rails"
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use debugger
17
+ # gem 'debugger'
@@ -0,0 +1,196 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ axlsx_rails (0.1.0)
5
+ axlsx
6
+ rails (~> 3.1)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionmailer (3.2.6)
12
+ actionpack (= 3.2.6)
13
+ mail (~> 2.4.4)
14
+ actionpack (3.2.6)
15
+ activemodel (= 3.2.6)
16
+ activesupport (= 3.2.6)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ journey (~> 1.0.1)
20
+ rack (~> 1.4.0)
21
+ rack-cache (~> 1.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.1.3)
24
+ activemodel (3.2.6)
25
+ activesupport (= 3.2.6)
26
+ builder (~> 3.0.0)
27
+ activerecord (3.2.6)
28
+ activemodel (= 3.2.6)
29
+ activesupport (= 3.2.6)
30
+ arel (~> 3.0.2)
31
+ tzinfo (~> 0.3.29)
32
+ activeresource (3.2.6)
33
+ activemodel (= 3.2.6)
34
+ activesupport (= 3.2.6)
35
+ activesupport (3.2.6)
36
+ i18n (~> 0.6)
37
+ multi_json (~> 1.0)
38
+ acts_as_xlsx (1.0.5)
39
+ activerecord (>= 2.3.9)
40
+ axlsx (>= 1.0.13)
41
+ i18n (>= 0.4.1)
42
+ addressable (2.2.8)
43
+ arel (3.0.2)
44
+ axlsx (1.1.7)
45
+ nokogiri (>= 1.4.1)
46
+ rake (>= 0.8.7)
47
+ rubyzip (>= 0.9.5)
48
+ builder (3.0.0)
49
+ capybara (1.1.2)
50
+ mime-types (>= 1.16)
51
+ nokogiri (>= 1.3.3)
52
+ rack (>= 1.0.0)
53
+ rack-test (>= 0.5.4)
54
+ selenium-webdriver (~> 2.0)
55
+ xpath (~> 0.1.4)
56
+ childprocess (0.3.3)
57
+ ffi (~> 1.0.6)
58
+ choice (0.1.6)
59
+ diff-lcs (1.1.3)
60
+ erubis (2.7.0)
61
+ faraday (0.8.1)
62
+ multipart-post (~> 1.1)
63
+ ffi (1.0.11)
64
+ google-spreadsheet-ruby (0.3.0)
65
+ google_drive (>= 0.3.0)
66
+ google_drive (0.3.1)
67
+ nokogiri (>= 1.4.4, != 1.5.2, != 1.5.1)
68
+ oauth (>= 0.3.6)
69
+ oauth2 (>= 0.5.0)
70
+ guard (1.2.3)
71
+ listen (>= 0.4.2)
72
+ thor (>= 0.14.6)
73
+ guard-rspec (1.2.0)
74
+ guard (>= 1.1)
75
+ hike (1.2.1)
76
+ httpauth (0.1)
77
+ i18n (0.6.0)
78
+ journey (1.0.4)
79
+ jquery-rails (2.0.2)
80
+ railties (>= 3.2.0, < 5.0)
81
+ thor (~> 0.14)
82
+ json (1.7.3)
83
+ jwt (0.1.4)
84
+ json (>= 1.2.4)
85
+ libwebsocket (0.1.3)
86
+ addressable
87
+ listen (0.4.7)
88
+ rb-fchange (~> 0.0.5)
89
+ rb-fsevent (~> 0.9.1)
90
+ rb-inotify (~> 0.8.8)
91
+ log4r (1.1.10)
92
+ mail (2.4.4)
93
+ i18n (>= 0.4.0)
94
+ mime-types (~> 1.16)
95
+ treetop (~> 1.4.8)
96
+ mime-types (1.19)
97
+ multi_json (1.3.6)
98
+ multipart-post (1.1.5)
99
+ nokogiri (1.5.5)
100
+ oauth (0.4.6)
101
+ oauth2 (0.8.0)
102
+ faraday (~> 0.8)
103
+ httpauth (~> 0.1)
104
+ jwt (~> 0.1.4)
105
+ multi_json (~> 1.0)
106
+ rack (~> 1.2)
107
+ polyglot (0.3.3)
108
+ rack (1.4.1)
109
+ rack-cache (1.2)
110
+ rack (>= 0.4)
111
+ rack-ssl (1.3.2)
112
+ rack
113
+ rack-test (0.6.1)
114
+ rack (>= 1.0)
115
+ rails (3.2.6)
116
+ actionmailer (= 3.2.6)
117
+ actionpack (= 3.2.6)
118
+ activerecord (= 3.2.6)
119
+ activeresource (= 3.2.6)
120
+ activesupport (= 3.2.6)
121
+ bundler (~> 1.0)
122
+ railties (= 3.2.6)
123
+ railties (3.2.6)
124
+ actionpack (= 3.2.6)
125
+ activesupport (= 3.2.6)
126
+ rack-ssl (~> 1.3.2)
127
+ rake (>= 0.8.7)
128
+ rdoc (~> 3.4)
129
+ thor (>= 0.14.6, < 2.0)
130
+ rake (0.9.2.2)
131
+ rb-fchange (0.0.5)
132
+ ffi
133
+ rb-fsevent (0.9.1)
134
+ rb-inotify (0.8.8)
135
+ ffi (>= 0.5.0)
136
+ rdoc (3.12)
137
+ json (~> 1.4)
138
+ roo (1.10.1)
139
+ choice (>= 0.1.4)
140
+ google-spreadsheet-ruby (>= 0.1.5)
141
+ nokogiri (>= 1.5.0)
142
+ rubyzip (>= 0.9.4)
143
+ spreadsheet (> 0.6.4)
144
+ todonotes (>= 0.1.0)
145
+ rspec (2.11.0)
146
+ rspec-core (~> 2.11.0)
147
+ rspec-expectations (~> 2.11.0)
148
+ rspec-mocks (~> 2.11.0)
149
+ rspec-core (2.11.0)
150
+ rspec-expectations (2.11.1)
151
+ diff-lcs (~> 1.1.3)
152
+ rspec-mocks (2.11.1)
153
+ rspec-rails (2.11.0)
154
+ actionpack (>= 3.0)
155
+ activesupport (>= 3.0)
156
+ railties (>= 3.0)
157
+ rspec (~> 2.11.0)
158
+ ruby-ole (1.2.11.4)
159
+ rubyzip (0.9.9)
160
+ selenium-webdriver (2.24.0)
161
+ childprocess (>= 0.2.5)
162
+ libwebsocket (~> 0.1.3)
163
+ multi_json (~> 1.0)
164
+ rubyzip
165
+ spreadsheet (0.7.3)
166
+ ruby-ole (>= 1.0)
167
+ sprockets (2.1.3)
168
+ hike (~> 1.2)
169
+ rack (~> 1.0)
170
+ tilt (~> 1.1, != 1.3.0)
171
+ sqlite3 (1.3.6)
172
+ thor (0.15.4)
173
+ tilt (1.3.3)
174
+ todonotes (0.1.0)
175
+ log4r
176
+ treetop (1.4.10)
177
+ polyglot
178
+ polyglot (>= 0.3.1)
179
+ tzinfo (0.3.33)
180
+ xpath (0.1.4)
181
+ nokogiri (~> 1.3)
182
+
183
+ PLATFORMS
184
+ ruby
185
+
186
+ DEPENDENCIES
187
+ acts_as_xlsx
188
+ axlsx_rails!
189
+ bundler
190
+ capybara
191
+ guard-rspec
192
+ jquery-rails
193
+ rake
194
+ roo
195
+ rspec-rails
196
+ sqlite3
@@ -0,0 +1,15 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{spec/.+_spec\.rb$})
6
+ watch('spec/spec_helper.rb') { "spec" }
7
+ watch(%r{spec/support/.+\.rb$}) { "spec" }
8
+
9
+ watch(%r{spec/dummy/app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
10
+ watch(%r{spec/dummy/app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
11
+ watch(%r{spec/dummy/app/controllers/.+\.rb$}) { ["spec/axlsx_renderer_spec.rb", "spec/axlsx_builder_spec.rb", "axlsx_request_spec.rb"] }
12
+ watch('lib/axlsx_rails/action_controller.rb') { ["spec/axlsx_renderer_spec.rb", "spec/axlsx_request_spec.rb"] }
13
+ watch('lib/axlsx_rails/template_handler.rb') { "spec/axlsx_builder_spec.rb" }
14
+ watch(%r{spec/dummy/app/views/.+\.erb}) { "spec/axlsx_request_spec.rb" }
15
+ end
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ Axlsx-Rails &mdash; Axlsx templates for Rails views
2
+ ===================================================
3
+
4
+ ##Installation
5
+ --------------
6
+ Until published:
7
+ gem 'axlsx_rails', :git => "https://github.com/straydogstudio/axlsx_rails.git"
8
+
9
+ ##Requirements
10
+ --------------
11
+ * Rails 3.1, but it has only been tested on 3.2.6
12
+
13
+ ##Usage
14
+ -------
15
+
16
+ Axlsx-Rails provides a renderer and a template handler. It adds the :xlsx format and parses .xlsx.axslx templates.
17
+
18
+ ###Controller
19
+
20
+ You can either use the typical format:
21
+
22
+ respond_to do |format|
23
+ format.xlsx
24
+ end
25
+
26
+ or call render directly:
27
+
28
+ render "foobar", filename: "the_latest_foobar", disposition: 'inline'
29
+
30
+ ###Template
31
+
32
+ Use the .xlsx.axlsx extension (sorry if your lysdexic!) In the template, use xlsx_package variable, which is set with Axlsx::Package.new:
33
+
34
+ wb = xlsx_package.workbook
35
+ style_shout = wb.styles.add_style sz: 16, b: true, alignment: { horizontal: :center }
36
+ wb.add_worksheet(name: "Foobar") do |sheet|
37
+ sheet.add_row ['Bad', 'spellers', 'of', 'the', 'world', '...']
38
+ sheet.add_row ['Untie!']
39
+ sheet.merge_cells("B1:B6")
40
+ sheet["B1"].style = style_shout
41
+ end
42
+
43
+ If you use [acts_as_xlsx](https://github.com/randym/acts_as_xlsx), configure the active record normally, but specify the package in the template:
44
+
45
+ User.to_xlsx package: xlsx_package, (other options)
46
+
47
+ To set the author attribute upon Axlsx::Package.new, insert the following in application.rb:
48
+
49
+ config.axlsx_author = "Elmer Fudd"
50
+
51
+ > NOTE: We really ought to allow the author to be set in each call
52
+
53
+ ####Partials
54
+ Partials are currently untested.
55
+
56
+ ##Dependencies
57
+ --------------
58
+ - [Axlsx](https://github.com/randym/axlsx)
59
+
60
+ ##Authors
61
+ ---------
62
+ * [Noel Peden](https://github.com/straydogstudio)
63
+
64
+ ##Change log
65
+ ------------
66
+ - **July 12, 2012**: 0.0.1 release
67
+ * Initial posting.
68
+ * It works, but there are no tests! Bad programmer!
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'AxlsxRails'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ require "rspec/core/rake_task"
24
+ RSpec::Core::RakeTask.new('spec')
25
+
26
+ task :default => :spec
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
@@ -0,0 +1,4 @@
1
+ require 'axlsx'
2
+ require 'axlsx_rails/action_controller'
3
+ require 'axlsx_rails/template_handler'
4
+
@@ -0,0 +1,16 @@
1
+ require 'action_controller'
2
+ Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
3
+
4
+ ActionController::Renderers.add :xlsx do |filename, options|
5
+ disposition = options.delete(:disposition) || 'attachment'
6
+ download_name = options.delete(:filename) || "#{filename}.xlsx"
7
+ download_name += ".xlsx" unless download_name =~ /\.xlsx$/
8
+ send_data render_to_string(filename, options), :filename => download_name, :type => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :disposition => disposition
9
+ end
10
+
11
+ # For respond_to default
12
+ class ActionController::Responder
13
+ def to_xlsx
14
+ controller.render :xlsx => controller.action_name
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ require 'action_view'
2
+ module ActionView
3
+ module Template::Handlers
4
+ class AxlsxBuilder
5
+ def default_format
6
+ Mime::XLSX
7
+ end
8
+
9
+ def self.call(template)
10
+ "xlsx_package = Axlsx::Package.new(:author => #{axlsx_author.inspect});\n" +
11
+ template.source +
12
+ ";\nxlsx_package.to_stream.string;"
13
+ end
14
+
15
+ private
16
+
17
+ def self.axlsx_author
18
+ Rails.application.config.respond_to?(:axlsx_author) ? Rails.application.config.axlsx_author : nil
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ ActionView::Template.register_template_handler :axlsx, ActionView::Template::Handlers::AxlsxBuilder
@@ -0,0 +1,3 @@
1
+ module AxlsxRails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :axlsx_rails do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,34 @@
1
+ require'spec_helper'
2
+ describe 'Axlsx template handler' do
3
+
4
+ AB = ActionView::Template::Handlers::AxlsxBuilder
5
+ VT = Struct.new(:source)
6
+
7
+ let( :handler ) { AB.new }
8
+
9
+ let( :template ) do
10
+ VT.new("wb = xlsx_package.workbook;\nwb.add_worksheet(name: 'Test') do |sheet|\n\tsheet.add_row ['one', 'two', 'three']\n\tsheet.add_row ['a', 'b', 'c']\nend\n")
11
+ end
12
+
13
+ context "Rails #{Rails.version}" do
14
+ # for testing if the author is set
15
+ # before do
16
+ # Rails.stub_chain(:application, :config, :axlsx_author).and_return( 'Elmer Fudd' )
17
+ # end
18
+
19
+ it "has xlsx format" do
20
+ handler.default_format.should == Mime::XLSX
21
+ end
22
+
23
+ it "compiles to an excel spreadsheet" do
24
+ xlsx_package, wb = nil
25
+ eval( AB.call template )
26
+ xlsx_package.serialize('/tmp/axlsx_temp.xlsx')
27
+ expect{ wb = Excelx.new('/tmp/axlsx_temp.xlsx') }.to_not raise_error
28
+ wb.cell(2,3).should == 'c'
29
+ end
30
+
31
+ #TODO:
32
+ # Test if author field is set - does roo parse that?
33
+ end
34
+ end