Skip to content

Commit 429ab93

Browse files
committed
ensure that columns defined on the resource class are also present on the resource instance.
1 parent 3bf5c06 commit 429ab93

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ doc
66
*.un~
77
.yardoc
88
.rbenv-version
9+
.ruby-version

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ gemspec
44

55
group :development, :test do
66
gem 'sqlite3'
7-
gem 'rake', '~> 10.0.4', :require => false
87
gem 'haml', '~> 3.1.1', :require => false
98
gem 'yard'
109
gem 'rdiscount' # For yard

Gemfile.lock

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ GEM
5151
arbre (1.0.1)
5252
activesupport (>= 3.0.0)
5353
arel (3.0.2)
54-
axlsx (1.3.1)
54+
axlsx (2.0.1)
5555
htmlentities (~> 4.3.1)
5656
nokogiri (>= 1.4.1)
57-
rubyzip (>= 0.9.5)
57+
rubyzip (~> 1.0.0)
5858
bcrypt-ruby (3.0.1)
5959
bourbon (3.1.3)
6060
sass (>= 3.2.0)
@@ -149,8 +149,10 @@ GEM
149149
polyamorous (~> 0.5.0)
150150
method_source (0.8.1)
151151
mime-types (1.19)
152+
mini_portile (0.5.1)
152153
multi_json (1.3.7)
153-
nokogiri (1.5.5)
154+
nokogiri (1.6.0)
155+
mini_portile (~> 0.5.0)
154156
orm_adapter (0.4.0)
155157
polyamorous (0.5.0)
156158
activerecord (~> 3.0)
@@ -183,7 +185,7 @@ GEM
183185
rake (>= 0.8.7)
184186
rdoc (~> 3.4)
185187
thor (>= 0.14.6, < 2.0)
186-
rake (10.0.4)
188+
rake (10.1.0)
187189
rdiscount (1.6.8)
188190
rdoc (3.12)
189191
json (~> 1.4)
@@ -202,7 +204,7 @@ GEM
202204
activesupport (>= 3.0)
203205
railties (>= 3.0)
204206
rspec (~> 2.9.0)
205-
rubyzip (0.9.9)
207+
rubyzip (1.0.0)
206208
sass (3.2.3)
207209
sass-rails (3.2.5)
208210
railties (~> 3.2.0)
@@ -255,7 +257,6 @@ DEPENDENCIES
255257
jslint_on_rails (~> 1.0.6)
256258
launchy
257259
rails-i18n
258-
rake (~> 10.0.4)
259260
rdiscount
260261
rspec-mocks
261262
rspec-rails (~> 2.9.0)

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,24 @@ bundle exec rake setup
156156
bundle exec rake
157157
```
158158
# Changelog
159+
160+
**2013.10.12**
161+
- Upgraded to most recent version of Axlsx. This introduces some non-backwards compatible
162+
changes and pushes rubyzip up to 1.0.0
163+
- Added support for scoped collections #18
164+
159165
**2013.06.02** Release 2.1.2
160166
- builder#collection is now set on serialize and is available in before and after filters.
161167
- Code cleanup
168+
162169
**2013.04.18** Release 2.1.1
163170
- Fixed issue with repeating data in sheets across downloads
164171
- Updated to use activeadmin 0.6.0+ which supports plugins.
172+
165173
**2013.03.21** Release 2.0.1
166174
- Fixed an issue with missing objects when using the DSL.
167175
Huge thanks to [Fivell](https://github.com/Fivell)
176+
168177
**2012.11.29** Release 2.0.0
169178
- resouce content column are now pre-populated.
170179
- added before and after filters

lib/active_admin/axlsx/builder.rb

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,25 @@ def clean_up
154154
end
155155

156156
def export_collection(collection)
157-
header_row
157+
header_row(collection)
158158
collection.each do |resource|
159159
sheet.add_row resource_data(resource)
160160
end
161161
end
162162

163+
# tranform column names into array of localized strings
164+
# @return [Array]
165+
def header_row(collection)
166+
sheet.add_row header_data_for(collection), { :style => header_style_id }
167+
end
168+
169+
def header_data_for(collection)
170+
resource = collection.first
171+
columns.map do |column|
172+
column.localized_name(i18n_scope) if in_scope(resource, column)
173+
end.compact
174+
end
175+
163176
def apply_filter(filter)
164177
filter.call(sheet) if filter
165178
end
@@ -171,7 +184,14 @@ def parse_options(options)
171184
end
172185

173186
def resource_data(resource)
174-
columns.map { |column| call_method_or_proc_on resource, column.data }
187+
columns.map do |column|
188+
call_method_or_proc_on resource, column.data if in_scope(resource, column)
189+
end
190+
end
191+
192+
def in_scope(resource, column)
193+
return true unless column.name.is_a?(Symbol)
194+
resource.respond_to?(column.name)
175195
end
176196

177197
def sheet
@@ -182,12 +202,6 @@ def package
182202
@package ||= ::Axlsx::Package.new(:use_shared_strings => true)
183203
end
184204

185-
# tranform column names into array of localized strings
186-
# @return [Array]
187-
def header_row
188-
sheet.add_row columns.map { |column| column.localized_name(i18n_scope) }, :style => header_style_id
189-
end
190-
191205
def header_style_id
192206
package.workbook.styles.add_style header_style
193207
end

lib/active_admin/axlsx/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module ActiveAdmin
22
module Axlsx
3-
VERSION = '2.1.2'
3+
VERSION = '3.0.0'
44
end
55
end

0 commit comments

Comments
 (0)