workbook_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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +207 -0
- data/MIT-LICENSE +20 -0
- data/README.md +216 -0
- data/Rakefile +29 -0
- data/lib/tasks/workbook_rails_tasks.rake +4 -0
- data/lib/workbook_rails.rb +5 -0
- data/lib/workbook_rails/action_controller.rb +51 -0
- data/lib/workbook_rails/engine.rb +25 -0
- data/lib/workbook_rails/template_handler.rb +23 -0
- data/lib/workbook_rails/version.rb +3 -0
- data/spec/ci.rb +3 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/home_controller.rb +60 -0
- data/spec/dummy/app/controllers/likes_controller.rb +18 -0
- data/spec/dummy/app/controllers/users_controller.rb +16 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/notifier.rb +14 -0
- data/spec/dummy/app/models/like.rb +3 -0
- data/spec/dummy/app/models/user.rb +8 -0
- data/spec/dummy/app/views/home/_cover_sheet.xlsx.wb +2 -0
- data/spec/dummy/app/views/home/generic.wb +5 -0
- data/spec/dummy/app/views/home/index.html.erb +4 -0
- data/spec/dummy/app/views/home/index.xls.wb +5 -0
- data/spec/dummy/app/views/home/index.xlsx.wb +5 -0
- data/spec/dummy/app/views/home/only_html.html.erb +1 -0
- data/spec/dummy/app/views/home/useheader.xlsx.wb +5 -0
- data/spec/dummy/app/views/home/withpartial.xlsx.wb +6 -0
- data/spec/dummy/app/views/layouts/application.html.erb +12 -0
- data/spec/dummy/app/views/likes/index.html.erb +17 -0
- data/spec/dummy/app/views/likes/index.xlsx.wb +5 -0
- data/spec/dummy/app/views/notifier/instructions.html.erb +14 -0
- data/spec/dummy/app/views/notifier/instructions.txt.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +23 -0
- data/spec/dummy/app/views/users/mailers/instructions.xlsx.wb +3 -0
- data/spec/dummy/app/views/users/respond_with.xlsx.wb +5 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +34 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +83 -0
- data/spec/dummy/config/environments/test.rb +44 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/secret_token.rb +2 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +17 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/migrate/20120717192452_create_users.rb +12 -0
- data/spec/dummy/db/migrate/20121206210955_create_likes.rb +10 -0
- data/spec/dummy/db/schema.rb +32 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +8575 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/template_handler_spec.rb +35 -0
- data/spec/test_3.2.sh +4 -0
- data/spec/test_4.0.sh +4 -0
- data/spec/test_4.1.sh +4 -0
- data/spec/test_4.2.sh +4 -0
- data/spec/test_all_rails.sh +4 -0
- data/spec/workbook_mailer_spec.rb +16 -0
- data/spec/workbook_renderer_spec.rb +21 -0
- data/spec/workbook_request_spec.rb +168 -0
- metadata +365 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 99b581f30cf5d61337cee27f99be081975f2e89c
|
4
|
+
data.tar.gz: 9e27f7b3ed8d1abde8754b0e3d9a715a45339617
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd27b88883fa8915abff6bc44a3172e9b47b358a6a78657deb594f7ff6f1879a4abda80b2668b0ce220e6de8f12fff32ffe9758100ba2aee946ed0faddb324e8
|
7
|
+
data.tar.gz: 4d78bb123cc96b5c482ff9d820e9086cb2ea0caf798313d7868b8b26059eb160d737b2eda73ab489e5b01e811d5c0af0dcabfdcf1647ab32bbfd2dd5b3e80e15
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
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
|
+
gem 'rails', "~> 4.2.0"
|
9
|
+
gem 'responders', '~> 2.0'
|
10
|
+
|
11
|
+
# jquery-rails is used by the dummy application
|
12
|
+
gem "jquery-rails"
|
13
|
+
|
14
|
+
# Declare any dependencies that are still in development here instead of in
|
15
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
16
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
17
|
+
# your gem to rubygems.org.
|
18
|
+
gem 'capybara', '~> 2.1'
|
19
|
+
|
20
|
+
# To use debugger
|
21
|
+
# gem 'pry-debugger'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
workbook_rails (0.1.0)
|
5
|
+
actionpack (>= 3.2)
|
6
|
+
workbook (>= 0.4.10)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (4.2.6)
|
12
|
+
actionpack (= 4.2.6)
|
13
|
+
actionview (= 4.2.6)
|
14
|
+
activejob (= 4.2.6)
|
15
|
+
mail (~> 2.5, >= 2.5.4)
|
16
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
17
|
+
actionpack (4.2.6)
|
18
|
+
actionview (= 4.2.6)
|
19
|
+
activesupport (= 4.2.6)
|
20
|
+
rack (~> 1.6)
|
21
|
+
rack-test (~> 0.6.2)
|
22
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
23
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
24
|
+
actionview (4.2.6)
|
25
|
+
activesupport (= 4.2.6)
|
26
|
+
builder (~> 3.1)
|
27
|
+
erubis (~> 2.7.0)
|
28
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
29
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
30
|
+
activejob (4.2.6)
|
31
|
+
activesupport (= 4.2.6)
|
32
|
+
globalid (>= 0.3.0)
|
33
|
+
activemodel (4.2.6)
|
34
|
+
activesupport (= 4.2.6)
|
35
|
+
builder (~> 3.1)
|
36
|
+
activerecord (4.2.6)
|
37
|
+
activemodel (= 4.2.6)
|
38
|
+
activesupport (= 4.2.6)
|
39
|
+
arel (~> 6.0)
|
40
|
+
activesupport (4.2.6)
|
41
|
+
i18n (~> 0.7)
|
42
|
+
json (~> 1.7, >= 1.7.7)
|
43
|
+
minitest (~> 5.1)
|
44
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
45
|
+
tzinfo (~> 1.1)
|
46
|
+
addressable (2.4.0)
|
47
|
+
arel (6.0.3)
|
48
|
+
axlsx (2.1.0.pre)
|
49
|
+
htmlentities (~> 4.3.1)
|
50
|
+
nokogiri (>= 1.4.1)
|
51
|
+
rubyzip (~> 1.1.7)
|
52
|
+
builder (3.2.2)
|
53
|
+
capybara (2.7.0)
|
54
|
+
addressable
|
55
|
+
mime-types (>= 1.16)
|
56
|
+
nokogiri (>= 1.3.3)
|
57
|
+
rack (>= 1.0.0)
|
58
|
+
rack-test (>= 0.5.4)
|
59
|
+
xpath (~> 2.0)
|
60
|
+
coderay (1.1.1)
|
61
|
+
concurrent-ruby (1.0.1)
|
62
|
+
coveralls (0.8.13)
|
63
|
+
json (~> 1.8)
|
64
|
+
simplecov (~> 0.11.0)
|
65
|
+
term-ansicolor (~> 1.3)
|
66
|
+
thor (~> 0.19.1)
|
67
|
+
tins (~> 1.6.0)
|
68
|
+
diff-lcs (1.2.5)
|
69
|
+
docile (1.1.5)
|
70
|
+
erubis (2.7.0)
|
71
|
+
globalid (0.3.6)
|
72
|
+
activesupport (>= 4.1.0)
|
73
|
+
growl (1.0.3)
|
74
|
+
htmlentities (4.3.4)
|
75
|
+
i18n (0.7.0)
|
76
|
+
jquery-rails (4.1.1)
|
77
|
+
rails-dom-testing (>= 1, < 3)
|
78
|
+
railties (>= 4.2.0)
|
79
|
+
thor (>= 0.14, < 2.0)
|
80
|
+
json (1.8.3)
|
81
|
+
loofah (2.0.3)
|
82
|
+
nokogiri (>= 1.5.9)
|
83
|
+
mail (2.6.4)
|
84
|
+
mime-types (>= 1.16, < 4)
|
85
|
+
method_source (0.8.2)
|
86
|
+
mime-types (3.0)
|
87
|
+
mime-types-data (~> 3.2015)
|
88
|
+
mime-types-data (3.2016.0221)
|
89
|
+
mini_portile2 (2.0.0)
|
90
|
+
minitest (5.8.4)
|
91
|
+
nokogiri (1.6.7.2)
|
92
|
+
mini_portile2 (~> 2.0.0.rc2)
|
93
|
+
pry (0.10.3)
|
94
|
+
coderay (~> 1.1.0)
|
95
|
+
method_source (~> 0.8.1)
|
96
|
+
slop (~> 3.4)
|
97
|
+
pry-nav (0.2.4)
|
98
|
+
pry (>= 0.9.10, < 0.11.0)
|
99
|
+
rack (1.6.4)
|
100
|
+
rack-test (0.6.3)
|
101
|
+
rack (>= 1.0)
|
102
|
+
rails (4.2.6)
|
103
|
+
actionmailer (= 4.2.6)
|
104
|
+
actionpack (= 4.2.6)
|
105
|
+
actionview (= 4.2.6)
|
106
|
+
activejob (= 4.2.6)
|
107
|
+
activemodel (= 4.2.6)
|
108
|
+
activerecord (= 4.2.6)
|
109
|
+
activesupport (= 4.2.6)
|
110
|
+
bundler (>= 1.3.0, < 2.0)
|
111
|
+
railties (= 4.2.6)
|
112
|
+
sprockets-rails
|
113
|
+
rails-deprecated_sanitizer (1.0.3)
|
114
|
+
activesupport (>= 4.2.0.alpha)
|
115
|
+
rails-dom-testing (1.0.7)
|
116
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
117
|
+
nokogiri (~> 1.6.0)
|
118
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
119
|
+
rails-html-sanitizer (1.0.3)
|
120
|
+
loofah (~> 2.0)
|
121
|
+
railties (4.2.6)
|
122
|
+
actionpack (= 4.2.6)
|
123
|
+
activesupport (= 4.2.6)
|
124
|
+
rake (>= 0.8.7)
|
125
|
+
thor (>= 0.18.1, < 2.0)
|
126
|
+
rake (10.5.0)
|
127
|
+
rb-fsevent (0.9.7)
|
128
|
+
rchardet (1.6.1)
|
129
|
+
responders (2.1.2)
|
130
|
+
railties (>= 4.2.0, < 5.1)
|
131
|
+
roo (2.3.2)
|
132
|
+
nokogiri (~> 1)
|
133
|
+
rubyzip (~> 1.1, < 2.0.0)
|
134
|
+
rspec-core (3.4.4)
|
135
|
+
rspec-support (~> 3.4.0)
|
136
|
+
rspec-expectations (3.4.0)
|
137
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
138
|
+
rspec-support (~> 3.4.0)
|
139
|
+
rspec-mocks (3.4.1)
|
140
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
141
|
+
rspec-support (~> 3.4.0)
|
142
|
+
rspec-rails (3.4.2)
|
143
|
+
actionpack (>= 3.0, < 4.3)
|
144
|
+
activesupport (>= 3.0, < 4.3)
|
145
|
+
railties (>= 3.0, < 4.3)
|
146
|
+
rspec-core (~> 3.4.0)
|
147
|
+
rspec-expectations (~> 3.4.0)
|
148
|
+
rspec-mocks (~> 3.4.0)
|
149
|
+
rspec-support (~> 3.4.0)
|
150
|
+
rspec-support (3.4.1)
|
151
|
+
ruby-ole (1.2.12)
|
152
|
+
rubyzip (1.1.7)
|
153
|
+
simplecov (0.11.2)
|
154
|
+
docile (~> 1.1.0)
|
155
|
+
json (~> 1.8)
|
156
|
+
simplecov-html (~> 0.10.0)
|
157
|
+
simplecov-html (0.10.0)
|
158
|
+
slop (3.6.0)
|
159
|
+
spreadsheet (1.1.2)
|
160
|
+
ruby-ole (>= 1.0)
|
161
|
+
sprockets (3.6.0)
|
162
|
+
concurrent-ruby (~> 1.0)
|
163
|
+
rack (> 1, < 3)
|
164
|
+
sprockets-rails (3.0.4)
|
165
|
+
actionpack (>= 4.0)
|
166
|
+
activesupport (>= 4.0)
|
167
|
+
sprockets (>= 3.0.0)
|
168
|
+
sqlite3 (1.3.11)
|
169
|
+
term-ansicolor (1.3.2)
|
170
|
+
tins (~> 1.0)
|
171
|
+
thor (0.19.1)
|
172
|
+
thread_safe (0.3.5)
|
173
|
+
tins (1.6.0)
|
174
|
+
tzinfo (1.2.2)
|
175
|
+
thread_safe (~> 0.1)
|
176
|
+
workbook (0.5)
|
177
|
+
axlsx (~> 2.1.0.pre)
|
178
|
+
json (~> 1.8)
|
179
|
+
nokogiri (~> 1.6)
|
180
|
+
rake (~> 10.0)
|
181
|
+
rchardet (~> 1.3)
|
182
|
+
roo (~> 2.3)
|
183
|
+
spreadsheet (~> 1.0)
|
184
|
+
xpath (2.0.0)
|
185
|
+
nokogiri (~> 1.3)
|
186
|
+
|
187
|
+
PLATFORMS
|
188
|
+
ruby
|
189
|
+
|
190
|
+
DEPENDENCIES
|
191
|
+
bundler
|
192
|
+
capybara (~> 2.1)
|
193
|
+
coveralls
|
194
|
+
growl
|
195
|
+
jquery-rails
|
196
|
+
pry
|
197
|
+
pry-nav
|
198
|
+
rails (~> 4.2.0)
|
199
|
+
rake
|
200
|
+
rb-fsevent
|
201
|
+
responders (~> 2.0)
|
202
|
+
rspec-rails
|
203
|
+
sqlite3
|
204
|
+
workbook_rails!
|
205
|
+
|
206
|
+
BUNDLED WITH
|
207
|
+
1.11.2
|
data/MIT-LICENSE
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,216 @@
|
|
1
|
+
Workbook-Rails — Workbook templates for Rails views
|
2
|
+
===================================================
|
3
|
+
|
4
|
+
[](http://badge.fury.io/rb/workbook_rails)
|
6
|
+
[](http://travis-ci.org/Programatica/workbook_rails)
|
7
|
+
[](https://gemnasium.com/Programatica/workbook_rails)
|
8
|
+
[](https://coveralls.io/r/Programatica/workbook_rails)
|
10
|
+
|
11
|
+
|
12
|
+
##Installation
|
13
|
+
|
14
|
+
In your Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'workbook_rails'
|
18
|
+
```
|
19
|
+
|
20
|
+
##Requirements
|
21
|
+
|
22
|
+
* Rails 3.2, 4.0, 4.1 or 4.2 (tested)
|
23
|
+
* **Workbook 0.4.16 requires Axlsx 2.0.1, which requires rubyzip 1.0.0**
|
24
|
+
* You must use `render_to_string` to render a mail attachment.
|
25
|
+
|
26
|
+
##FYI
|
27
|
+
|
28
|
+
* This gem depends on [Workbook](https://github.com/murb/workbook). See [README](https://github.com/murb/workbook) or [rdoc](http://www.rubydoc.info/github/murb/workbook) for usage.
|
29
|
+
|
30
|
+
##Usage
|
31
|
+
|
32
|
+
Workbook-Rails provides a renderer and a template handler. It adds the `:xlsx` and `:xls` formats and parses `.wb` templates. This lets you take all the [Workbook](https://github.com/murb/workbook) code out of your controller or model and place it inside the template, where view code belongs!
|
33
|
+
|
34
|
+
###Controller
|
35
|
+
|
36
|
+
To use Workbook-Rails set your instance variables in your controller and configure the response if needed:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
class ButtonController < ApplicationController
|
40
|
+
def action_name
|
41
|
+
@buttons = Button.all
|
42
|
+
respond_to do |format|
|
43
|
+
format.xlsx
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
###Template
|
50
|
+
|
51
|
+
Create the template with the `.xlsx.wb` extension (`action_name.xlsx.wb` for example.) [**Watch out for typos!**](#troubleshooting) In the template, use workbook variable to create your spreadsheet:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
table = workbook.sheet.table
|
55
|
+
@buttons.each do |button|
|
56
|
+
table << [button.name, button.category, button.price]
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
This is where you place all your [Workbook](https://github.com/murb/workbook) specific markup. Add worksheets, fill content, merge cells, add styles.
|
61
|
+
|
62
|
+
Remember, like in `erb` templates, view helpers are available to use the `.wb` template.
|
63
|
+
|
64
|
+
That's it. Call your action and your spreadsheet will be delivered.
|
65
|
+
|
66
|
+
###Rendering Options
|
67
|
+
|
68
|
+
You can call render in any of the following ways:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
# rendered, no disposition/filename header
|
72
|
+
render 'buttons'
|
73
|
+
# rendered from another controller, no disposition/filename header
|
74
|
+
render 'featured/latest'
|
75
|
+
# template and filename of 'buttons'
|
76
|
+
render xlsx: 'buttons'
|
77
|
+
# template from another controller, filename of 'latest_buttons'
|
78
|
+
render xlsx: 'latest_buttons', template: 'featured/latest'
|
79
|
+
```
|
80
|
+
|
81
|
+
###Multi-format Templates
|
82
|
+
|
83
|
+
You can create a template with `.wb` extension, without format, and use for generating different spreadsheets formats, such as xls and xlsx, using respond_to and format param.
|
84
|
+
|
85
|
+
Set :format param in the route (/route_path.xlsx, or /route_path.xls) and use respond_to in the controller
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
respond_to do |format|
|
89
|
+
format.xlsx
|
90
|
+
format.xls
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
###Disposition
|
95
|
+
|
96
|
+
To specify a disposition (such as `inline` so the spreadsheet is opened inside the browser), use the `disposition` option:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
render xlsx: "buttons", disposition: 'inline'
|
100
|
+
```
|
101
|
+
|
102
|
+
If `render xlsx:` is called, the disposition defaults to `attachment`.
|
103
|
+
|
104
|
+
###File name
|
105
|
+
|
106
|
+
If Rails calls Workbook through default channels (because you use `format.xlsx {}` for example) you must set the filename using the response header:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
format.xlsx {
|
110
|
+
response.headers['Content-Disposition'] = 'attachment; filename="my_new_filename.xlsx"'
|
111
|
+
}
|
112
|
+
```
|
113
|
+
|
114
|
+
If you use `render xlsx:` the gem will try to guess the file name:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
# filename of 'buttons'
|
118
|
+
render xlsx: 'buttons'
|
119
|
+
# filename of 'latest_buttons'
|
120
|
+
render xlsx: 'latest_buttons', template: 'featured/latest'
|
121
|
+
```
|
122
|
+
|
123
|
+
If that fails, pass the `:filename` parameter:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
render xlsx: "action_or_template", filename: "my_new_filename.xlsx"
|
127
|
+
```
|
128
|
+
|
129
|
+
###Partials
|
130
|
+
|
131
|
+
Partials work as expected:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
render :partial => 'cover_sheet', :locals => {:sheet => workbook.sheet}
|
135
|
+
workbook << [['Content']]
|
136
|
+
workbook.last.name = 'Content'
|
137
|
+
```
|
138
|
+
|
139
|
+
With the partial simply using the passed variables:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
sheet.name = "Cover Sheet"
|
143
|
+
sheet.table.push ['Cover', 'Sheet']
|
144
|
+
```
|
145
|
+
|
146
|
+
###Mailers
|
147
|
+
|
148
|
+
To use an xlsx template to render a mail attachment, use the following syntax:
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
class UserMailer < ActionMailer::Base
|
152
|
+
def export(users)
|
153
|
+
xlsx = render_to_string handlers: [:wb], formats: [:xlsx], template: "users/export", locals: {users: users}
|
154
|
+
attachments["Users.xlsx"] = {mime_type: Mime::XLSX, content: xlsx}
|
155
|
+
...
|
156
|
+
end
|
157
|
+
end
|
158
|
+
```
|
159
|
+
|
160
|
+
* If the route specifies or suggests the `:xlsx` format you do not need to specify `formats` or `handlers`.
|
161
|
+
* If the template (`users/export`) can refer to only one file (the xlsx.axlsx template), you do not need to specify `handlers`, provided the `formats` includes `:xlsx`.
|
162
|
+
|
163
|
+
###Scripts
|
164
|
+
|
165
|
+
To generate a template within a script, you need to instantiate an ActionView context. Here are two gists showing how to perform this:
|
166
|
+
|
167
|
+
* [Using rails runner](https://gist.github.com/straydogstudio/323139591f2cc5d48fbc)
|
168
|
+
* [Without rails runner](https://gist.github.com/straydogstudio/dceb775ead81470cea70)
|
169
|
+
|
170
|
+
##Troubleshooting
|
171
|
+
|
172
|
+
###Mispellings
|
173
|
+
|
174
|
+
**It is easy to get the spelling wrong in the extension name, the format.xlsx statement, or in a render call.** Here are some possibilities:
|
175
|
+
|
176
|
+
* If it says your template is missing, check that its extension is `.xlsx.wb`.
|
177
|
+
* If you get the error `uninitialized constant Mime::XSLX` you have used `format.xslx` instead of `format.xlsx`, or something similar.
|
178
|
+
|
179
|
+
### Rails 4.2 changes
|
180
|
+
|
181
|
+
Before Rails 4.2 you could call:
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
render xlsx: "users/index"
|
185
|
+
```
|
186
|
+
|
187
|
+
And workbook_rails could adjust the paths and make sure the template was loaded from the right directory. This is no longer possible because the paths are cached between requests for a given controller. As a result, to display a template in another directory you must use the `:template` parameter (which is normal Rails behavior anyway):
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
render xlsx: "index", template: "users/index"
|
191
|
+
```
|
192
|
+
|
193
|
+
If the request format matches you should be able to call:
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
render "users/index"
|
197
|
+
```
|
198
|
+
|
199
|
+
This is a breaking change if you have the old syntax!
|
200
|
+
|
201
|
+
###What to do
|
202
|
+
|
203
|
+
If you are having problems, try to isolate the issue. Use the console or a script to make sure your data is good. Then create the spreadsheet line by line without Workbook-Rails to see if you are having Workbook problems. If you can manually create the spreadsheet, create an issue and we will work it out.
|
204
|
+
|
205
|
+
##Dependencies
|
206
|
+
|
207
|
+
- [Rails](https://github.com/rails/rails)
|
208
|
+
- [Workbook](https://github.com/murb/workbook)
|
209
|
+
|
210
|
+
##Authors
|
211
|
+
|
212
|
+
* [Sergio Cambra](https://github.com/scambra)
|
213
|
+
|
214
|
+
##Thanks
|
215
|
+
|
216
|
+
Many thanks to [straydogstudio](https://github.com/straydogstudio) for [axlsx_rails](https://github.com/straydogstudio/axlsx_rails), which this gem is based in.
|