Skip to content

Commit 069db4a

Browse files
committed
Made collection available to before and after filters.
1 parent 14b8d4e commit 069db4a

File tree

12 files changed

+51
-37
lines changed

12 files changed

+51
-37
lines changed

.bundle/config

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
---
2-
BUNDLE_DISABLE_SHARED_GEMS: '1'
1+
--- {}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ spec/rails
22
*.gem
33
coverage
44
*.xlsx
5+
doc
6+
*.un~
7+
.yardoc
8+
.rbenv-version

.yardops

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--no-private --protected app/**/*.rb - README.md LEGAL

Gemfile

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

55
group :development, :test do
66
gem 'sqlite3'
7-
gem 'rake', '~> 0.9.6', :require => false
7+
gem 'rake', '~> 10.0.4', :require => false
88
gem 'haml', '~> 3.1.1', :require => false
99
gem 'yard'
1010
gem 'rdiscount' # For yard

Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
activeadmin-axlsx (2.1.1)
4+
activeadmin-axlsx (2.1.2)
55
activeadmin (~> 0.6.0)
66
axlsx
77

@@ -183,7 +183,7 @@ GEM
183183
rake (>= 0.8.7)
184184
rdoc (~> 3.4)
185185
thor (>= 0.14.6, < 2.0)
186-
rake (0.9.6)
186+
rake (10.0.4)
187187
rdiscount (1.6.8)
188188
rdoc (3.12)
189189
json (~> 1.4)
@@ -236,7 +236,7 @@ GEM
236236
websocket (1.0.3)
237237
xpath (0.1.4)
238238
nokogiri (~> 1.3)
239-
yard (0.8.3)
239+
yard (0.8.6.1)
240240

241241
PLATFORMS
242242
ruby
@@ -255,7 +255,7 @@ DEPENDENCIES
255255
jslint_on_rails (~> 1.0.6)
256256
launchy
257257
rails-i18n
258-
rake (~> 0.9.6)
258+
rake (~> 10.0.4)
259259
rdiscount
260260
rspec-mocks
261261
rspec-rails (~> 2.9.0)

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ appreciation for the gem, please don't hesitate to make a donation.
2020

2121
**License**: MIT License
2222

23-
**Latest Version**: 2.0.1
23+
**Latest Version**: 2.1.2
2424

25-
**Ruby Version**: 1.9.2, 1.9.3
25+
**Ruby Version**: 1.9.2, 1.9.3, 2.0.0
2626

2727
**JRuby Version**: 1.9 mode
2828

2929
**Rubinius Version**: rubinius 2.0.0dev * lower versions may run, this gem always tests against head.
3030

31-
**Release Date**: TBA
31+
**Release Date**: 2013.06.02
3232

3333
Synopsis
3434
--------
3535

3636
This gem provides automatic OOXML (xlsx) downloads for Active Admin
3737
resources. It lets you harness the full power of Axlsx when you want to
38-
but for the most part just stays out of your way and adds a link next to
38+
but for the most part just stays out of your way and adds a link next to
3939
the csv download for xlsx (Excel/numbers/Libre Office/Google Docs)
4040

4141
![Screen 1](https://github.com/randym/activeadmin-axlsx/raw/master/screen_capture.png)
@@ -53,7 +53,7 @@ Cool Toys
5353
---------
5454

5555
Here are a few quick examples of things you can easily tweak.
56-
Axlsx supports A LOT of the specification so if you are looking to do
56+
Axlsx supports A LOT of the specification so if you are looking to do
5757
something adventurous please ping me on irc. (freenode#axlsx)
5858

5959
##localize column headers
@@ -71,7 +71,7 @@ end
7171
#app/admin/posts.rb
7272
ActiveAdmin.register Post do
7373
config.xlsx_builder.column('author_name') do |resource|
74-
resource.author.name
74+
resource.author.name
7575
end
7676
end
7777
```
@@ -98,22 +98,22 @@ end
9898
#Using the DSL
9999

100100
Everything that you do with the config'd default builder can be done via
101-
the resource DSL.
101+
the resource DSL.
102102

103103
Below is an example of the DSL
104104

105105
```ruby
106106
ActiveAdmin.register Post do
107107
# i18n_scope and header style are set via options
108-
xlsx(:i18n_scope => [:active_admin, :axlsx, :post],
108+
xlsx(:i18n_scope => [:active_admin, :axlsx, :post],
109109
:header_style => {:bg_color => 'FF0000', :fg_color => 'FF' }) do
110110

111111
# deleting columns from the report
112112
delete_columns :id, :created_at, :updated_at
113113

114114
# adding a column to the report
115115
column(:author) { |resource| "#{resource.author.first_name} #{resource.author.last_name}" }
116-
116+
117117
# creating a chart and inserting additional data with after_filter
118118
after_filter { |sheet|
119119
sheet.add_row []
@@ -145,7 +145,7 @@ end
145145
#Specs
146146
------
147147
Running specs for this gem requires that you construct a rails application.
148-
To execute the specs, navigate to the gem directory,
148+
To execute the specs, navigate to the gem directory,
149149
run bundle install and run these to rake tasks:
150150

151151
```
@@ -156,8 +156,14 @@ bundle exec rake setup
156156
bundle exec rake
157157
```
158158
# Changelog
159+
**2013.06.02** Release 2.1.2
160+
- builder#collection is now set on serialize and is available in before and after filters.
161+
- Code cleanup
162+
**2013.04.18** Release 2.1.1
163+
- Fixed issue with repeating data in sheets across downloads
164+
- Updated to use activeadmin 0.6.0+ which supports plugins.
159165
**2013.03.21** Release 2.0.1
160-
- Fixed an issue with missing objects when using the DSL.
166+
- Fixed an issue with missing objects when using the DSL.
161167
Huge thanks to [Fivell](https://github.com/Fivell)
162168
**2012.11.29** Release 2.0.0
163169
- resouce content column are now pre-populated.

activeadmin-axlsx.gemspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ Gem::Specification.new do |s|
88
s.homepage = 'https://github.com/randym/activeadmin-axlsx'
99
s.platform = Gem::Platform::RUBY
1010
s.date = Time.now.strftime('%Y-%m-%d')
11+
s.license = 'MIT'
1112
s.summary = "Adds excel downloads for resources within the Active Admin framework via Axlsx."
1213
s.description = <<-eof
1314
This gem uses axlsx to provide excel/xlsx downloads for resources in Active Admin. Often, users are happier with excel, so why not give it to them instead of CSV?
1415
eof
1516
s.files = `git ls-files`.split("\n").sort
16-
s.test_files = `git ls-files -- {spec}/*`.split("\n")
17+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
1718
s.test_files = Dir.glob("{spec/**/*}")
19+
1820
s.add_runtime_dependency 'activeadmin', "~> 0.6.0"
1921
s.add_runtime_dependency 'axlsx'
2022

lib/active_admin/axlsx.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require 'active_admin'
2-
require 'active_admin/axlsx/build_download_format_links'
32
require 'active_admin/axlsx/version'
43
require 'active_admin/axlsx/builder'
54
require 'active_admin/axlsx/dsl'
65
require 'active_admin/axlsx/resource_extension'
76
require 'active_admin/axlsx/resource_controller_extension'
7+
88
class Railtie < ::Rails::Railtie
99
config.before_initialize do
1010
begin

lib/active_admin/axlsx/build_download_format_links.rb

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/active_admin/axlsx/builder.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ def before_filter(&block)
8989
# The columns this builder will be serializing
9090
attr_reader :columns
9191

92-
# removes all columns from the builder. This is useful when you want to
92+
# The collection we are serializing.
93+
# @note This is only available after serialize has been called,
94+
# and is reset on each subsequent call.
95+
attr_reader :collection
96+
97+
# removes all columns from the builder. This is useful when you want to
9398
# only render specific columns. To remove specific columns use ignore_column.
9499
def clear_columns
95100
@columns = []
@@ -112,6 +117,7 @@ def delete_columns(*column_names)
112117
# Serializes the collection provided
113118
# @return [Axlsx::Package]
114119
def serialize(collection)
120+
@collection = collection
115121
apply_filter @before_filter
116122
export_collection(collection)
117123
apply_filter @after_filter

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.1'
3+
VERSION = '2.1.2'
44
end
55
end

spec/axlsx/unit/builder_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ module Axlsx
7676
end
7777
}
7878
before_filter do |sheet|
79+
collection.first.author.first_name = 'Set In Proc'
7980
sheet.add_row ['Created', Time.zone.now]
8081
sheet.add_row []
8182
end
@@ -89,6 +90,11 @@ module Axlsx
8990
builder.stub(:clean_up) { false }
9091
builder.serialize(Post.all)
9192
@package = builder.send(:package)
93+
@collection = builder.collection
94+
end
95+
96+
it 'provides the collection object' do
97+
@collection.count.should == Post.all.count
9298
end
9399

94100
it 'merges our customizations with the default header style' do
@@ -109,6 +115,11 @@ module Axlsx
109115
it 'processes the before filter' do
110116
@package.workbook.worksheets.first["A1"].value.should == 'Created'
111117
end
118+
119+
it 'lets us work against the collection in the before filter' do
120+
@package.workbook.worksheets.first.rows.last.cells.first.value.should == 'Set In Proc nancy'
121+
end
122+
112123
it 'processes the after filter' do
113124
@package.workbook.charts.size.should == 1
114125
end

0 commit comments

Comments
 (0)