activeadmin-xls 1.0.5 → 2.0.3

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.
@@ -1,6 +1,6 @@
1
1
  module ActiveAdmin
2
2
  module Xls
3
- # extends activeadmin dsl to include xls
3
+ # Extends activeadmin dsl to include xls
4
4
  module DSL
5
5
  delegate(:after_filter,
6
6
  :before_filter,
@@ -9,11 +9,59 @@ module ActiveAdmin
9
9
  :header_format,
10
10
  :header_style,
11
11
  :i18n_scope,
12
+ :only_columns,
12
13
  :skip_header,
13
14
  :whitelist,
14
15
  to: :xls_builder,
15
16
  prefix: :config)
16
17
 
18
+ # Creates a default XLS Builder to respond to xls requests for this
19
+ # resource. Options are passed to the Builder initialize method.
20
+ #
21
+ # @param [Hash] options the options for the builder
22
+ # @option options [Hash] :header_format a hash of format properties to
23
+ # apply to the header row. Any properties specified will be merged with
24
+ # the default header styles.
25
+ # @option options [Array] :i18n_scope the I18n scope to use when looking
26
+ # up localized column headers.
27
+ # @param [Block] block block given will evaluated against the instance of
28
+ # Builder. That means you can call any method on the builder from within
29
+ # that block.
30
+ # @return A new instance of Builder
31
+ #
32
+ # @example Using the DSL
33
+ # xls(i18n_scope: [:active_admin, :xls, :post],
34
+ # header_format: { weight: :bold, color: :blue }) do
35
+ # # Specify that you want to white list column output.
36
+ # # whitelist
37
+ #
38
+ # # Do not serialize the header, only output data.
39
+ # # skip_header
40
+ #
41
+ # # restrict columns to a list without customization
42
+ # # only_columns :title, :author
43
+ #
44
+ # # deleting columns from the report
45
+ # delete_columns :id, :created_at, :updated_at
46
+ #
47
+ # # adding a column to the report with customization
48
+ # column(:author) do |post|
49
+ # "#{post.author.first_name} #{post.author.last_name}"
50
+ # end
51
+ #
52
+ # # inserting additional data with after_filter
53
+ # after_filter do |sheet|
54
+ # # todo
55
+ # end
56
+ #
57
+ # # inserting data with before_filter
58
+ # before_filter do |sheet|
59
+ # # todo
60
+ # end
61
+ # end
62
+ #
63
+ # @see Builder
64
+ # @see https://github.com/zdavatz/spreadsheet/blob/master/lib/spreadsheet/format.rb
17
65
  def xls(options = {}, &block)
18
66
  config.xls_builder = ActiveAdmin::Xls::Builder.new(
19
67
  config.resource_class,
@@ -1,6 +1,6 @@
1
1
  module ActiveAdmin
2
2
  module Xls
3
- # extends activeadmin with xls downloads
3
+ # Extends ActiveAdmin with xls downloads
4
4
  class Engine < ::Rails::Engine
5
5
  engine_name 'active_admin_xls'
6
6
 
@@ -13,7 +13,10 @@ module ActiveAdmin
13
13
 
14
14
  ActiveAdmin::ResourceDSL.send :include, ActiveAdmin::Xls::DSL
15
15
  ActiveAdmin::Resource.send :include, ActiveAdmin::Xls::ResourceExtension
16
- ActiveAdmin::ResourceController.send :include, ActiveAdmin::Xls::ResourceControllerExtension
16
+ ActiveAdmin::ResourceController.send(
17
+ :prepend,
18
+ ActiveAdmin::Xls::ResourceControllerExtension
19
+ )
17
20
  end
18
21
  end
19
22
  end
@@ -1,25 +1,19 @@
1
1
  module ActiveAdmin
2
2
  module Xls
3
+ # Extends the resource controller to respond to xls requests
3
4
  module ResourceControllerExtension
4
- def self.included(base)
5
- base.send :alias_method_chain, :per_page, :xls
6
- base.send :alias_method_chain, :index, :xls
7
- base.send :alias_method_chain, :rescue_active_admin_access_denied, :xls
8
- base.send :respond_to, :xls
5
+ def self.prepended(base)
6
+ base.send :respond_to, :xls, only: :index
9
7
  end
10
8
 
11
- def index_with_xls
12
- index_without_xls do |format|
9
+ # Patches index to respond to requests with xls mime type by
10
+ # sending a generated xls document serializing the current
11
+ # collection
12
+ def index
13
+ super do |format|
13
14
  format.xls do
14
- xls_collection = if method(:find_collection).arity.zero?
15
- collection
16
- else
17
- find_collection except: :pagination
18
- end
19
- xls = active_admin_config.xls_builder.serialize(
20
- xls_collection,
21
- view_context
22
- )
15
+ xls = active_admin_config.xls_builder.serialize(xls_collection,
16
+ view_context)
23
17
  send_data(xls,
24
18
  filename: xls_filename,
25
19
  type: Mime::Type.lookup_by_extension(:xls))
@@ -29,7 +23,12 @@ module ActiveAdmin
29
23
  end
30
24
  end
31
25
 
32
- def rescue_active_admin_access_denied_with_xls(exception)
26
+ # Patches rescue_active_admin_access_denied to respond to xls
27
+ # mime type. Provides administrators information on how to
28
+ # configure activeadmin to respond propertly to xls requests
29
+ #
30
+ # param exception [Exception] unauthorized access error
31
+ def rescue_active_admin_access_denied(exception)
33
32
  if request.format == Mime::Type.lookup_by_extension(:xls)
34
33
  respond_to do |format|
35
34
  format.xls do
@@ -38,27 +37,23 @@ module ActiveAdmin
38
37
  end
39
38
  end
40
39
  else
41
- rescue_active_admin_access_denied_without_xls(exception)
40
+ super(exception)
42
41
  end
43
42
  end
44
43
 
45
- # patch per_page to use the CSV record max for pagination
46
- # when the format is xls
47
- def per_page_with_xls
48
- if request.format == Mime::Type.lookup_by_extension(:xls)
49
- return max_per_page if respond_to?(:max_per_page, true)
50
- active_admin_config.max_per_page
51
- end
52
-
53
- per_page_without_xls
54
- end
55
-
56
44
  # Returns a filename for the xls file using the collection_name
57
45
  # and current date such as 'my-articles-2011-06-24.xls'.
46
+ #
47
+ # @return [String] with default filename
58
48
  def xls_filename
59
49
  timestamp = Time.now.strftime('%Y-%m-%d')
60
50
  "#{resource_collection_name.to_s.tr('_', '-')}-#{timestamp}.xls"
61
51
  end
52
+
53
+ # Returns the collection to use when generating an xls file.
54
+ def xls_collection
55
+ find_collection except: :pagination
56
+ end
62
57
  end
63
58
  end
64
59
  end
@@ -1,10 +1,25 @@
1
1
  module ActiveAdmin
2
+ # Provides xls functionality to ActiveAdmin resources
2
3
  module Xls
4
+ # Extends ActiveAdmin Resource
3
5
  module ResourceExtension
6
+ # Sets the XLS Builder
7
+ #
8
+ # @param builder [Builder] the new builder object
9
+ # @return [Builder] the builder for this resource
4
10
  def xls_builder=(builder)
5
11
  @xls_builder = builder
6
12
  end
7
13
 
14
+ # Returns the XLS Builder. Creates a new Builder if none exists.
15
+ #
16
+ # @return [Builder] the builder for this resource
17
+ #
18
+ # @example Localize column headers
19
+ # # app/admin/posts.rb
20
+ # ActiveAdmin.register Post do
21
+ # config.xls_builder.i18n_scope = [:active_record, :models, :posts]
22
+ # end
8
23
  def xls_builder
9
24
  @xls_builder ||= ActiveAdmin::Xls::Builder.new(resource_class)
10
25
  end
@@ -1,5 +1,6 @@
1
1
  module ActiveAdmin
2
2
  module Xls
3
- VERSION = '1.0.5'.freeze
3
+ # ActiveAdmin XLS gem version
4
+ VERSION = '2.0.3'.freeze
4
5
  end
5
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-xls
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Hambley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-29 00:00:00.000000000 Z
11
+ date: 2021-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.6
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '2'
19
+ version: 1.0.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 0.6.6
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '2'
26
+ version: 1.0.0
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: spreadsheet
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,8 +38,7 @@ dependencies:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
40
  version: '1.0'
47
- description: |2
48
- This gem provides excel/xls downloads for resources in Active Admin.
41
+ description: " This gem provides excel/xls downloads for resources in Active Admin.\n"
49
42
  email: thambley@travelleaders.com
50
43
  executables: []
51
44
  extensions: []
@@ -55,15 +48,17 @@ files:
55
48
  - ".gemignore"
56
49
  - ".gitignore"
57
50
  - ".rspec"
58
- - ".yardops"
51
+ - ".travis.yml"
52
+ - ".yardopts"
59
53
  - CHANGELOG.md
60
54
  - Gemfile
61
55
  - LICENSE
62
56
  - README.md
63
57
  - Rakefile
64
58
  - activeadmin-xls.gemspec
65
- - gemfiles/rails_32.gemfile
66
59
  - gemfiles/rails_42.gemfile
60
+ - gemfiles/rails_52.gemfile
61
+ - gemfiles/rails_60.gemfile
67
62
  - lib/active_admin/xls/builder.rb
68
63
  - lib/active_admin/xls/dsl.rb
69
64
  - lib/active_admin/xls/engine.rb
@@ -71,18 +66,6 @@ files:
71
66
  - lib/active_admin/xls/resource_extension.rb
72
67
  - lib/active_admin/xls/version.rb
73
68
  - lib/activeadmin-xls.rb
74
- - spec/spec_helper.rb
75
- - spec/support/rails_template.rb
76
- - spec/support/rails_template_with_data.rb
77
- - spec/support/templates/admin/stores.rb
78
- - spec/support/templates/cucumber.rb
79
- - spec/support/templates/cucumber_with_reloading.rb
80
- - spec/support/templates/en.yml
81
- - spec/xls/unit/build_download_format_links_spec.rb
82
- - spec/xls/unit/builder_spec.rb
83
- - spec/xls/unit/dsl_spec.rb
84
- - spec/xls/unit/resource_controller_spec.rb
85
- - spec/xls/unit/resource_spec.rb
86
69
  homepage: https://github.com/thambley/activeadmin-xls
87
70
  licenses:
88
71
  - MIT
@@ -95,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
78
  requirements:
96
79
  - - ">="
97
80
  - !ruby/object:Gem::Version
98
- version: 1.9.2
81
+ version: 2.0.0
99
82
  required_rubygems_version: !ruby/object:Gem::Requirement
100
83
  requirements:
101
84
  - - ">="
@@ -103,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
86
  version: '0'
104
87
  requirements: []
105
88
  rubyforge_project:
106
- rubygems_version: 2.4.5.2
89
+ rubygems_version: 2.6.14.4
107
90
  signing_key:
108
91
  specification_version: 4
109
92
  summary: Adds excel (xls) downloads for resources within the Active Admin framework.
data/.yardops DELETED
@@ -1 +0,0 @@
1
- --no-private --protected app/**/*.rb - README.md LEGAL
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env ruby
2
- source 'https://rubygems.org'
3
-
4
- ruby_major_version = RUBY_VERSION.split('.')[0].to_i
5
- ruby_minor_version = RUBY_VERSION.split('.')[1].to_i
6
-
7
- eval_gemfile(File.expand_path(File.join('..', 'Gemfile'), __dir__))
8
-
9
- gem 'rails', '3.2.22.5'
10
-
11
- gem 'activeadmin', '0.6.6'
12
-
13
- group :assets do
14
- gem 'coffee-rails', '~> 3.2.1'
15
- gem 'sass-rails', '~> 3.2.3'
16
-
17
- # See https://github.com/sstephenson/execjs#readme for more supported runtimes
18
- # gem 'therubyracer', :platforms => :ruby
19
-
20
- gem 'uglifier', '>= 1.0.3'
21
- end
22
-
23
- group :test do
24
- gem 'shoulda-matchers', '~> 2.8.0'
25
- if ruby_major_version > 2 || (ruby_major_version == 2 && ruby_minor_version > 1)
26
- gem 'test-unit', '~> 3.0'
27
- end
28
- end
29
-
30
- gemspec path: "../"
data/spec/spec_helper.rb DELETED
@@ -1,38 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start do
3
- add_filter '/rails/'
4
- add_filter '/spec/'
5
- end
6
-
7
- ENV['RAILS_ENV'] = 'test'
8
-
9
- # prepare ENV for rails
10
- require 'rails'
11
- ENV['RAILS_ROOT'] = File.expand_path(
12
- "../rails/rails-#{Rails::VERSION::STRING}",
13
- __FILE__
14
- )
15
-
16
- # ensure testing application is in place
17
- unless File.exist?(ENV['RAILS_ROOT'])
18
- puts 'Please run bundle exec rake setup before running the specs.'
19
- exit
20
- end
21
-
22
- # load up activeadmin and activeadmin-xls
23
- require 'active_record'
24
- require 'active_admin'
25
- require 'devise'
26
- require 'activeadmin-xls'
27
- ActiveAdmin.application.load_paths = [ENV['RAILS_ROOT'] + '/app/admin']
28
-
29
- # start up rails
30
- require ENV['RAILS_ROOT'] + '/config/environment'
31
-
32
- # and finally,here's rspec
33
- require 'rspec/rails'
34
-
35
- # Disabling authentication in specs so that we don't have to worry about
36
- # it allover the place
37
- ActiveAdmin.application.authentication_method = false
38
- ActiveAdmin.application.current_user_method = false
@@ -1,102 +0,0 @@
1
- # Rails template to build the sample app for specs
2
-
3
- # Create a cucumber database and environment
4
- copy_file File.expand_path('../templates/cucumber.rb', __FILE__),
5
- 'config/environments/cucumber.rb'
6
- copy_file File.expand_path('../templates/cucumber_with_reloading.rb', __FILE__),
7
- 'config/environments/cucumber_with_reloading.rb'
8
-
9
- gsub_file 'config/database.yml', /^test:.*\n/, "test: &test\n"
10
- gsub_file 'config/database.yml',
11
- /\z/,
12
- "\ncucumber:\n <<: *test\n database: db/cucumber.sqlite3"
13
- gsub_file 'config/database.yml',
14
- /\z/,
15
- "\ncucumber_with_reloading:\n <<: *test\n database: db/cucumber.sqlite3"
16
-
17
- # Generate some test models
18
- generate :model, 'post title:string body:text published_at:datetime author_id:integer category_id:integer'
19
- inject_into_file 'app/models/post.rb', " belongs_to :author, class_name: 'User'\n belongs_to :category\n accepts_nested_attributes_for :author\n", after: "class Post < ActiveRecord::Base\n"
20
- # Rails 3.2.3 model generator declare attr_accessible
21
- if Rails::VERSION::MAJOR == 3
22
- inject_into_file 'app/models/post.rb',
23
- " attr_accessible :author\n",
24
- before: 'end'
25
- end
26
- generate :model, 'user type:string first_name:string last_name:string username:string age:integer'
27
- inject_into_file 'app/models/user.rb', " has_many :posts, foreign_key: 'author_id'\n", after: "class User < ActiveRecord::Base\n"
28
- generate :model, 'publisher --migration=false --parent=User'
29
- generate :model, 'category name:string description:text'
30
- inject_into_file 'app/models/category.rb', " has_many :posts\n accepts_nested_attributes_for :posts\n", after: "class Category < ActiveRecord::Base\n"
31
- generate :model, 'store name:string'
32
-
33
- # Generate a model with string ids
34
- generate :model, 'tag name:string'
35
- gsub_file(Dir['db/migrate/*_create_tags.rb'][0], /\:tags\sdo\s.*/, ":tags, id: false, primary_key: :id do |t|\n\t\t\tt.string :id\n" )
36
- id_model_setup = <<-MODEL
37
- self.primary_key = :id
38
- before_create :set_id
39
-
40
- private
41
- def set_id
42
- self.id = 8.times.inject('') { |s,e| s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
43
- end
44
- MODEL
45
-
46
- inject_into_file 'app/models/tag.rb',
47
- id_model_setup,
48
- after: "class Tag < ActiveRecord::Base\n"
49
-
50
- if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 1 # Rails 3.1 Gotcha
51
- gsub_file 'app/models/tag.rb',
52
- /self\.primary_key.*$/,
53
- 'define_attr_method :primary_key, :id'
54
- end
55
-
56
- # Configure default_url_options in test environment
57
- inject_into_file 'config/environments/test.rb',
58
- " config.action_mailer.default_url_options = { host: 'example.com' }\n",
59
- after: "config.cache_classes = true\n"
60
-
61
- puts File.expand_path('../../../lib/activeadmin-xls', __FILE__)
62
- # Add our local Active Admin to the load path
63
- inject_into_file 'config/environment.rb',
64
- "\nrequire \"#{File.expand_path('../../../lib/activeadmin-xls', __FILE__)}\"\n",
65
- after: "require File.expand_path('../application', __FILE__)"
66
-
67
- # Add some translations
68
- append_file 'config/locales/en.yml',
69
- File.read(File.expand_path('../templates/en.yml', __FILE__))
70
-
71
- # Add predefined admin resources
72
- directory File.expand_path('../templates/admin', __FILE__), 'app/admin'
73
-
74
- run 'rm Gemfile'
75
- run 'rm -r test'
76
- run 'rm -r spec'
77
-
78
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
79
-
80
- if Rails::VERSION::MAJOR == 3
81
- # we need this routing path, named "logout_path", for testing
82
- route <<-ROUTE
83
- devise_scope :user do
84
- match '/admin/logout' => 'active_admin/devise/sessions#destroy', as: :logout
85
- end
86
- ROUTE
87
- end
88
-
89
- generate :'active_admin:install'
90
-
91
- if Rails::VERSION::MAJOR > 3
92
- inject_into_file 'config/initializers/active_admin.rb',
93
- " config.download_links = %i[csv xml json xls]\n",
94
- after: " # == Download Links\n"
95
- end
96
-
97
- # Setup a root path for devise
98
- route "root to: 'admin/dashboard#index'"
99
-
100
- rake 'db:migrate'
101
- rake 'db:test:prepare'
102
- run '/usr/bin/env RAILS_ENV=cucumber rake db:migrate'