Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- "7.0"
- "7.1"
- "7.2"
- "8.0"

ruby:
- "2.6"
Expand All @@ -25,8 +26,12 @@ jobs:
- "3.1"
- "3.2"
- "3.3"
- "3.4"

exclude:
- rails: "6.1"
ruby: "3.4"

- rails: "7.0"
ruby: "2.6"

Expand All @@ -35,13 +40,20 @@ jobs:

- rails: "7.2"
ruby: "2.6"

- rails: "7.2"
ruby: "2.7"

- rails: "7.2"
ruby: "3.0"

- rails: "8.0"
ruby: "2.6"
- rails: "8.0"
ruby: "2.7"
- rails: "8.0"
ruby: "3.0"
- rails: "8.0"
ruby: "3.1"

env:
BUNDLE_GEMFILE: ${{ github.workspace }}/spec/gemfiles/Gemfile.rails-${{ matrix.rails }}

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Drop support for Ruby < 2.6 and Rails < 6.1
- Require at least caxlsx 4.0
- Add Rails 8.0 and Ruby 3.4 to the CI matrix

**June 18, 2024**: 0.6.4 release

Expand Down
17 changes: 11 additions & 6 deletions lib/axlsx_rails/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

require 'action_controller'

unless Mime[:xlsx]
Mime::Type.register 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', :xlsx
end
Mime::Type.register 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', :xlsx unless Mime[:xlsx]

ActionController::Renderers.add :xlsx do |filename, options|
#
Expand All @@ -22,14 +20,21 @@
# render 'controller/diff_action'
# end
#
options[:template] = filename.gsub(/^.*\//,'') if options[:template] == action_name
if options[:template].nil?
options[:template] ||= action_name
options[:prefixes] ||= self.class.ancestors
.take_while { |a| a.respond_to?(:controller_path) }
.map(&:controller_path)
end

options[:template] = filename.gsub(%r{^.*/}, '') if options[:template] == action_name

# force layout false
options[:layout] = false

# disposition / filename
disposition = options.delete(:disposition) || 'attachment'
file_name = options.delete(:filename) || "#{filename.gsub(/^.*\//,'')}.xlsx"
file_name = options.delete(:filename) || "#{filename.gsub(%r{^.*/}, '')}.xlsx"
file_name = "#{file_name}.xlsx" unless file_name =~ /\.xlsx$/

# alternate settings
Expand All @@ -51,7 +56,7 @@ def to_xlsx
if @default_response
@default_response.call(options)
else
controller.render({xlsx: controller.action_name}.merge(options))
controller.render({ xlsx: controller.action_name }.merge(options))
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/gemfiles/Gemfile.rails-8.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
source "http://rubygems.org"

gemspec path: '../../'

gem 'rails', '~> 8.0.0'
gem 'puma'
gem 'responders', '~> 3.0'
gem 'sqlite3'
gem 'sprockets', '~> 4.0'
gem 'capybara', '~> 3.0'

gem 'debug'
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'spec_helper'

describe Examples::RespondToController do
describe Examples::RenderTemplateController do
let(:path) { "/examples/render_template/#{variant}.xlsx" }

shared_examples_for 'responds properly' do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
config.use_transactional_fixtures = false
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.filter_run_when_matching :focus
end

# TODO: move to the support folder
Expand Down