Skip to content

Commit

Permalink
Switch to caxlsx, Require Ruby 2.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
westonganger committed Jan 25, 2020
1 parent b33ad3a commit 3a6f02d
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 75 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
- rvm: ruby-head

gemfile:
- gemfiles/axlsx_master.gemfile
- gemfiles/axlsx_3.0.0.pre.gemfile
- gemfiles/axlsx_2.x.gemfile
- gemfiles/caxlsx.gemfile
- gemfiles/caxlsx_3.0.0.gemfile
- gemfiles/caxlsx_2.0.2.gemfile

notifications:
email: false
12 changes: 6 additions & 6 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
appraise "axlsx master" do
gem "axlsx", git: "https://github.com/randym/axlsx.git"
appraise "caxlsx" do
gem "caxlsx" # Ruby 2.3+
end

appraise "axlsx 3.0.0.pre" do
gem "axlsx", "3.0.0.pre"
appraise "caxlsx 3.0.0" do
gem "caxlsx", "3.0.0" # Ruby 1.9.3+
end

appraise "axlsx 2.x" do
gem "axlsx", "~> 2.0"
appraise "caxlsx 2.0.2" do
gem "caxlsx", "2.0.2" # Legacy Axlsx Support
end
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ CHANGELOG
---------

- **Unreleased**
- Nothing Yet
- Switch to the `caxlsx` gem (Community Axlsx) from the legacy unmaintained `axlsx` gem. Axlsx has had a long history of being poorly maintained so this community gem improves the situation.
- Require Ruby 2.3+
- **3.3.1**
- [Issue #30](https://github.com/westonganger/spreadsheet_architect/issues/30) - Fix duplicate constant warning for XLSX_COLUMN_TYPES
- **3.3.0**
Expand Down
7 changes: 1 addition & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
source 'https://rubygems.org'

### `responders` gem must remain in the Gemfile, not gemspec
### otherwise Rails integration tests fail
### Must remain in the Gemfile, not gemspec, otherwise Rails integration tests fail
gem 'responders'

### By default test against `axlsx` master
### Will be overridden by anything in Appraisal file
gem 'axlsx', git: 'https://github.com/randym/axlsx.git'

gemspec
2 changes: 1 addition & 1 deletion gemfiles/axlsx_2.x.gemfile → gemfiles/caxlsx.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source "https://rubygems.org"

gem "responders"
gem "axlsx", "~> 2.0"
gem "caxlsx"

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source "https://rubygems.org"

gem "responders"
gem "axlsx", "3.0.0.pre"
gem "caxlsx", "2.0.2"

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
source "https://rubygems.org"

gem "responders"
gem "axlsx", git: "https://github.com/randym/axlsx.git"
gem "caxlsx", "3.0.0"

gemspec path: "../"
68 changes: 20 additions & 48 deletions lib/spreadsheet_architect/monkey_patches/axlsx_column_width.rb
Original file line number Diff line number Diff line change
@@ -1,56 +1,28 @@
if RUBY_VERSION.to_f >= 2

module SpreadsheetArchitect
module AxlsxColumnWidthPatch
def initialize(*args)
@width = nil
super
end

def width=(v)
if v.nil?
@custom_width = false
@width = nil
elsif @width.nil? || @width < v+5
@custom_width = true
@best_fit = true
@width = v + 5
else
@custom_width = true
@width = v
end
end
module SpreadsheetArchitect
module AxlsxColumnWidthPatch
def initialize(*args)
@width = nil
super
end
end

module Axlsx
class Col
prepend ::SpreadsheetArchitect::AxlsxColumnWidthPatch
end
end

else

module Axlsx
class Col
original_initialize = instance_method(:initialize)
define_method :initialize do |*args|
def width=(v)
if v.nil?
@custom_width = false
@width = nil

original_initialize.bind(self).(*args)
end

def width=(v)
if v.nil?
@custom_width = false
@width = nil
elsif @width.nil? || @width < v+5
@custom_width = true
@best_fit = true
@width = v + 5
end
elsif @width.nil? || @width < v+5
@custom_width = true
@best_fit = true
@width = v + 5
else
@custom_width = true
@width = v
end
end
end
end

module Axlsx
class Col
prepend ::SpreadsheetArchitect::AxlsxColumnWidthPatch
end
end
6 changes: 3 additions & 3 deletions spreadsheet_architect.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Gem::Specification.new do |s|
s.test_files = Dir.glob("{test/**/*}")
s.require_path = 'lib'

s.required_ruby_version = '>= 1.9.3'
s.required_ruby_version = '>= 2.3.0'

s.add_runtime_dependency 'axlsx', ['>= 2', '<4']
s.add_runtime_dependency 'axlsx_styler', ['>= 0.1.7', '<2']
s.add_runtime_dependency 'caxlsx', ['>= 2.0.2', '<4']
s.add_runtime_dependency 'axlsx_styler', ['>= 1.0.0', '<2']
s.add_runtime_dependency 'rodf', ['>= 1.0.0', '<2']

s.add_development_dependency 'rake'
Expand Down
10 changes: 5 additions & 5 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class ActiveSupport::TestCase
end
end

axlsx_spec = Gem.loaded_specs['axlsx']
if !axlsx_spec.source.is_a?(Bundler::Source::Rubygems)
axlsx_version = 'axlsx-master'
caxlsx_spec = Gem.loaded_specs['caxlsx']
if caxlsx_spec.source.is_a?(Bundler::Source::Rubygems)
caxlsx_version = caxlsx_spec.version.to_s
else
axlsx_version = axlsx_spec.version.to_s
caxlsx_version = 'caxlsx-master'
end

VERSIONED_BASE_PATH = Rails.root.join("../../tmp/#{axlsx_version}")
VERSIONED_BASE_PATH = Rails.root.join("../../tmp/#{caxlsx_version}")

### Cleanup old test spreadsheets
FileUtils.remove_dir(VERSIONED_BASE_PATH, true)
Expand Down

0 comments on commit 3a6f02d

Please sign in to comment.