diff --git a/Gemfile b/Gemfile index e2ae9b2..7119e82 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,11 @@ source 'https://rubygems.org' gem 'axlsx' +gem 'activeadmin', github: 'gregbell/active_admin' gemspec group :development, :test do gem 'sqlite3' - gem 'haml', '~> 3.1.1', :require => false + gem 'haml', :require => false gem 'yard' gem 'rdiscount' # For yard gem "sprockets" @@ -15,9 +16,9 @@ group :test do gem 'inherited_resources' gem 'sass-rails' gem 'rspec-mocks' - gem 'rspec-rails', '~> 2.9.0' - gem 'cucumber-rails', '1.2.1', :require => false - gem 'capybara', '1.1.2' + gem 'rspec-rails' + gem 'cucumber-rails', :require => false + gem 'capybara' gem 'database_cleaner' gem 'shoulda-matchers', '1.0.0' gem 'launchy' diff --git a/Gemfile.lock b/Gemfile.lock index db0e980..d54ac6b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,247 +2,227 @@ PATH remote: . specs: activeadmin-axlsx (3.0.0) - activeadmin (~> 0.6.0) axlsx GEM remote: https://rubygems.org/ specs: - actionmailer (3.2.9) - actionpack (= 3.2.9) - mail (~> 2.4.4) - actionpack (3.2.9) - activemodel (= 3.2.9) - activesupport (= 3.2.9) - builder (~> 3.0.0) + actionmailer (4.1.4) + actionpack (= 4.1.4) + actionview (= 4.1.4) + mail (~> 2.5.4) + actionpack (4.1.4) + actionview (= 4.1.4) + activesupport (= 4.1.4) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + actionview (4.1.4) + activesupport (= 4.1.4) + builder (~> 3.1) erubis (~> 2.7.0) - journey (~> 1.0.4) - rack (~> 1.4.0) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.2.1) - activeadmin (0.6.0) - arbre (>= 1.0.1) - bourbon (>= 1.0.0) - devise (>= 1.1.2) - fastercsv - formtastic (>= 2.0.0) - inherited_resources (>= 1.3.1) - jquery-rails (>= 1.0.0) - kaminari (>= 0.13.0) - meta_search (>= 0.9.2) - rails (>= 3.0.0) - sass (>= 3.1.0) - activemodel (3.2.9) - activesupport (= 3.2.9) - builder (~> 3.0.0) - activerecord (3.2.9) - activemodel (= 3.2.9) - activesupport (= 3.2.9) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.9) - activemodel (= 3.2.9) - activesupport (= 3.2.9) - activesupport (3.2.9) - i18n (~> 0.6) - multi_json (~> 1.0) - addressable (2.3.2) - arbre (1.0.1) - activesupport (>= 3.0.0) - arel (3.0.2) - atomic (1.1.14) + activemodel (4.1.4) + activesupport (= 4.1.4) + builder (~> 3.1) + activerecord (4.1.4) + activemodel (= 4.1.4) + activesupport (= 4.1.4) + arel (~> 5.0.0) + activesupport (4.1.4) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.1) + tzinfo (~> 1.1) + addressable (2.3.6) + arel (5.0.1.20140414130214) axlsx (2.0.1) htmlentities (~> 4.3.1) nokogiri (>= 1.4.1) rubyzip (~> 1.0.0) - bcrypt-ruby (3.1.2) - bourbon (3.1.3) - sass (>= 3.2.0) - thor - builder (3.0.4) - capybara (1.1.2) + builder (3.2.2) + capybara (2.4.1) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) - selenium-webdriver (~> 2.0) - xpath (~> 0.1.4) - childprocess (0.3.6) - ffi (~> 1.0, >= 1.0.6) - coderay (1.0.8) - coffee-script (2.2.0) + xpath (~> 2.0) + celluloid (0.15.2) + timers (~> 1.1.0) + coderay (1.1.0) + coffee-script (2.3.0) coffee-script-source execjs - coffee-script-source (1.4.0) - cucumber (1.2.1) + coffee-script-source (1.7.1) + cucumber (1.3.15) builder (>= 2.1.2) diff-lcs (>= 1.1.3) - gherkin (~> 2.11.0) - json (>= 1.4.6) - cucumber-rails (1.2.1) - capybara (>= 1.1.2) - cucumber (>= 1.1.3) - nokogiri (>= 1.5.0) - database_cleaner (0.9.1) - devise (3.1.0) - bcrypt-ruby (~> 3.0) - orm_adapter (~> 0.1) - railties (>= 3.2.6, < 5) - thread_safe (~> 0.1) - warden (~> 1.2.3) - diff-lcs (1.1.3) + gherkin (~> 2.12) + multi_json (>= 1.7.5, < 2.0) + multi_test (>= 0.1.1) + cucumber-rails (1.4.1) + capybara (>= 1.1.2, < 3) + cucumber (>= 1.3.8, < 2) + mime-types (~> 1.16) + nokogiri (~> 1.5) + rails (>= 3, < 5) + database_cleaner (1.3.0) + diff-lcs (1.2.5) + docile (1.1.5) erubis (2.7.0) - execjs (1.4.0) - multi_json (~> 1.0) - fastercsv (1.5.5) - ffi (1.2.0) - formtastic (2.2.1) - actionpack (>= 3.0) - gherkin (2.11.5) - json (>= 1.4.6) - guard (1.5.4) - listen (>= 0.4.2) - lumberjack (>= 1.0.2) - pry (>= 0.9.10) - thor (>= 0.14.6) - guard-coffeescript (1.2.1) + execjs (2.2.1) + ffi (1.9.3) + formatador (0.2.5) + gherkin (2.12.2) + multi_json (~> 1.3) + guard (2.6.1) + formatador (>= 0.2.4) + listen (~> 2.7) + lumberjack (~> 1.0) + pry (>= 0.9.12) + thor (>= 0.18.1) + guard-coffeescript (1.4.0) coffee-script (>= 2.2.0) guard (>= 1.1.0) - guard-rspec (1.2.1) - guard (>= 1.1) - haml (3.1.7) - has_scope (0.5.1) - hike (1.2.1) - htmlentities (4.3.1) - i18n (0.6.1) - inherited_resources (1.3.1) - has_scope (~> 0.5.0) - responders (~> 0.6) - jasmine (1.2.1) - jasmine-core (>= 1.2.0) - rack (~> 1.0) - rspec (>= 1.3.1) - selenium-webdriver (>= 0.1.3) - jasmine-core (1.2.0) - journey (1.0.4) - jquery-rails (3.0.4) - railties (>= 3.0, < 5.0) - thor (>= 0.14, < 2.0) + guard-rspec (4.3.1) + guard (~> 2.1) + rspec (>= 2.14, < 4.0) + haml (4.0.5) + tilt + has_scope (0.6.0.rc) + actionpack (>= 3.2, < 5) + activesupport (>= 3.2, < 5) + hike (1.2.3) + htmlentities (4.3.2) + i18n (0.6.11) + inherited_resources (1.4.1) + has_scope (~> 0.6.0.rc) + responders (~> 1.0.0.rc) + jasmine (2.0.2) + jasmine-core (~> 2.0.0) + phantomjs + rack (>= 1.2.1) + rake + jasmine-core (2.0.1) jslint_on_rails (1.0.7) - json (1.7.5) - kaminari (0.14.1) - actionpack (>= 3.0.0) - activesupport (>= 3.0.0) - launchy (2.1.2) + json (1.8.1) + launchy (2.4.2) addressable (~> 2.3) - libwebsocket (0.1.6.1) - websocket - listen (0.5.3) - lumberjack (1.0.2) - mail (2.4.4) - i18n (>= 0.4.0) + listen (2.7.9) + celluloid (>= 0.15.2) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9) + lumberjack (1.0.9) + mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) - meta_search (1.1.3) - actionpack (~> 3.1) - activerecord (~> 3.1) - activesupport (~> 3.1) - polyamorous (~> 0.5.0) - method_source (0.8.1) - mime-types (1.19) - mini_portile (0.5.1) - multi_json (1.3.7) - nokogiri (1.6.0) - mini_portile (~> 0.5.0) - orm_adapter (0.4.0) - polyamorous (0.5.0) - activerecord (~> 3.0) - polyglot (0.3.3) - pry (0.9.10) - coderay (~> 1.0.5) - method_source (~> 0.8) - slop (~> 3.3.1) - rack (1.4.1) - rack-cache (1.2) - rack (>= 0.4) - rack-ssl (1.3.2) - rack + method_source (0.8.2) + mime-types (1.25.1) + mini_portile (0.6.0) + minitest (5.4.0) + multi_json (1.10.1) + multi_test (0.1.1) + nokogiri (1.6.3.1) + mini_portile (= 0.6.0) + phantomjs (1.9.7.1) + polyglot (0.3.5) + pry (0.10.0) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) - rails (3.2.9) - actionmailer (= 3.2.9) - actionpack (= 3.2.9) - activerecord (= 3.2.9) - activeresource (= 3.2.9) - activesupport (= 3.2.9) - bundler (~> 1.0) - railties (= 3.2.9) - rails-i18n (0.7.0) - i18n (~> 0.5) - railties (3.2.9) - actionpack (= 3.2.9) - activesupport (= 3.2.9) - rack-ssl (~> 1.3.2) + rails (4.1.4) + actionmailer (= 4.1.4) + actionpack (= 4.1.4) + actionview (= 4.1.4) + activemodel (= 4.1.4) + activerecord (= 4.1.4) + activesupport (= 4.1.4) + bundler (>= 1.3.0, < 2.0) + railties (= 4.1.4) + sprockets-rails (~> 2.0) + rails-i18n (4.0.2) + i18n (~> 0.6) + rails (>= 4.0) + rails (>= 4.0) + rails (>= 4.0) + rails (>= 4.0) + rails (>= 4.0) + rails (>= 4.0) + rails (>= 4.0) + rails (>= 4.0) + rails (>= 4.0) + rails (>= 4.0) + rails (>= 4.0) + railties (4.1.4) + actionpack (= 4.1.4) + activesupport (= 4.1.4) rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.14.6, < 2.0) - rake (10.1.0) - rdiscount (1.6.8) - rdoc (3.12) - json (~> 1.4) - responders (0.9.3) - railties (~> 3.1) - rspec (2.9.0) - rspec-core (~> 2.9.0) - rspec-expectations (~> 2.9.0) - rspec-mocks (~> 2.9.0) - rspec-core (2.9.0) - rspec-expectations (2.9.1) - diff-lcs (~> 1.1.3) - rspec-mocks (2.9.0) - rspec-rails (2.9.0) + thor (>= 0.18.1, < 2.0) + rake (10.3.2) + rb-fsevent (0.9.4) + rb-inotify (0.9.5) + ffi (>= 0.5.0) + rdiscount (2.1.7.1) + responders (1.0.0) + railties (>= 3.2, < 5) + rspec (3.0.0) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-core (3.0.3) + rspec-support (~> 3.0.0) + rspec-expectations (3.0.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.0.0) + rspec-mocks (3.0.3) + rspec-support (~> 3.0.0) + rspec-rails (3.0.2) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec (~> 2.9.0) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-support (~> 3.0.0) + rspec-support (3.0.3) rubyzip (1.0.0) - sass (3.2.3) - sass-rails (3.2.5) - railties (~> 3.2.0) - sass (>= 3.1.10) - tilt (~> 1.3) - selenium-webdriver (2.26.0) - childprocess (>= 0.2.5) - libwebsocket (~> 0.1.3) - multi_json (~> 1.0) - rubyzip + sass (3.2.19) + sass-rails (4.0.3) + railties (>= 4.0.0, < 5.0) + sass (~> 3.2.0) + sprockets (~> 2.8, <= 2.11.0) + sprockets-rails (~> 2.0) shoulda-matchers (1.0.0) - simplecov (0.7.1) - multi_json (~> 1.0) - simplecov-html (~> 0.7.1) - simplecov-html (0.7.1) - slop (3.3.3) - sprockets (2.2.1) + simplecov (0.9.0) + docile (~> 1.1.0) + multi_json + simplecov-html (~> 0.8.0) + simplecov-html (0.8.0) + slop (3.6.0) + sprockets (2.11.0) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sqlite3 (1.3.6) - thor (0.16.0) - thread_safe (0.1.3) - atomic - tilt (1.3.3) + sprockets-rails (2.1.3) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) + sqlite3 (1.3.9) + thor (0.19.1) + thread_safe (0.3.4) + tilt (1.4.1) + timers (1.1.0) treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.38) - warden (1.2.3) - rack (>= 1.0) - websocket (1.0.3) - xpath (0.1.4) + tzinfo (1.2.1) + thread_safe (~> 0.1) + xpath (2.0.0) nokogiri (~> 1.3) - yard (0.8.6.1) + yard (0.8.7.4) PLATFORMS ruby @@ -250,12 +230,12 @@ PLATFORMS DEPENDENCIES activeadmin-axlsx! axlsx - capybara (= 1.1.2) - cucumber-rails (= 1.2.1) + capybara + cucumber-rails database_cleaner guard-coffeescript guard-rspec - haml (~> 3.1.1) + haml inherited_resources jasmine jslint_on_rails (~> 1.0.6) @@ -263,7 +243,7 @@ DEPENDENCIES rails-i18n rdiscount rspec-mocks - rspec-rails (~> 2.9.0) + rspec-rails sass-rails shoulda-matchers (= 1.0.0) simplecov diff --git a/activeadmin-axlsx.gemspec b/activeadmin-axlsx.gemspec index 94ea552..db707bd 100644 --- a/activeadmin-axlsx.gemspec +++ b/activeadmin-axlsx.gemspec @@ -13,11 +13,11 @@ Gem::Specification.new do |s| s.description = <<-eof 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? eof - s.files = `git ls-files`.split("\n").sort + s.files = `git ls-files`.split("\n").sort s.test_files = `git ls-files -- {spec}/*`.split("\n") s.test_files = Dir.glob("{spec/**/*}") - s.add_runtime_dependency 'activeadmin', "~> 0.6.0" + s.add_runtime_dependency 'activeadmin' s.add_runtime_dependency 'axlsx' s.required_ruby_version = '>= 1.9.2' diff --git a/lib/active_admin/axlsx.rb b/lib/active_admin/axlsx.rb index 545c426..29b1078 100644 --- a/lib/active_admin/axlsx.rb +++ b/lib/active_admin/axlsx.rb @@ -18,12 +18,12 @@ class Railtie < ::Rails::Railtie end - config.after_initialize do + initializer "active_admin_axlsx_railtie.configure_rails_initialization" do |variable| ActiveAdmin::ResourceDSL.send :include, ActiveAdmin::Axlsx::DSL ActiveAdmin::Resource.send :include, ActiveAdmin::Axlsx::ResourceExtension ActiveAdmin::Views::PaginatedCollection.add_format :xlsx ActiveAdmin::ResourceController.send :include, ActiveAdmin::Axlsx::ResourceControllerExtension end -end +end diff --git a/lib/active_admin/axlsx/builder.rb b/lib/active_admin/axlsx/builder.rb index 6fb28ad..993ab31 100644 --- a/lib/active_admin/axlsx/builder.rb +++ b/lib/active_admin/axlsx/builder.rb @@ -74,7 +74,7 @@ def i18n_scope # This is the I18n scope that will be used when looking up your # colum names in the current I18n locale. - # If you set it to [:active_admin, :resources, :posts] the + # If you set it to [:active_admin, :resources, :posts] the # serializer will render the value at active_admin.resources.posts.title in the # current translations # @note If you do not set this, the column name will be titleized. @@ -128,8 +128,9 @@ def delete_columns(*column_names) # Serializes the collection provided # @return [Axlsx::Package] - def serialize(collection) + def serialize(collection, view_context) @collection = collection + @view_context = view_context apply_filter @before_filter export_collection(collection) apply_filter @after_filter @@ -141,7 +142,7 @@ def serialize(collection) class Column def initialize(name, block = nil) - @name = name.to_sym + @name = name @data = block || @name end @@ -223,6 +224,14 @@ def resource_columns(resource) Column.new(column.name.to_sym) end end + + def method_missing(method_name, *arguments) + if @view_context.respond_to? method_name + @view_context.send method_name, *arguments + else + super + end + end end end end diff --git a/lib/active_admin/axlsx/resource_controller_extension.rb b/lib/active_admin/axlsx/resource_controller_extension.rb index 5e002e4..85c4f11 100644 --- a/lib/active_admin/axlsx/resource_controller_extension.rb +++ b/lib/active_admin/axlsx/resource_controller_extension.rb @@ -3,24 +3,18 @@ module Axlsx module ResourceControllerExtension def self.included(base) base.send :alias_method_chain, :per_page, :xlsx - base.send :alias_method_chain, :index, :xlsx base.send :respond_to, :xlsx end - # patching the index method to allow the xlsx format. - def index_with_xlsx(options={}, &block) - index_without_xlsx(options) do |format| - format.xlsx do - xlsx = active_admin_config.xlsx_builder.serialize(collection) - send_data xlsx, :filename => "#{xlsx_filename}", :type => Mime::Type.lookup_by_extension(:xlsx) - end - end + ActionController::Renderers.add :xlsx do |obj, options| + xlsx = active_admin_config.xlsx_builder.serialize(collection, view_context) + send_data xlsx, :filename => "#{xlsx_filename}", :type => Mime::Type.lookup_by_extension(:xlsx) end # patching per_page to use the CSV record max for pagination when the format is xlsx def per_page_with_xlsx if request.format == Mime::Type.lookup_by_extension(:xlsx) - return max_csv_records + return max_per_page end per_page_without_xlsx end diff --git a/lib/active_admin/axlsx/resource_extension.rb b/lib/active_admin/axlsx/resource_extension.rb index 34951ab..71e8a7a 100644 --- a/lib/active_admin/axlsx/resource_extension.rb +++ b/lib/active_admin/axlsx/resource_extension.rb @@ -8,6 +8,7 @@ def xlsx_builder=(builder) def xlsx_builder @xlsx_builder ||= ActiveAdmin::Axlsx::Builder.new(resource_class) end + end end end