-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 25d8065
Showing
46 changed files
with
768 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Ignore bundler config. | ||
.bundle/ | ||
|
||
# Ignore Gemfile.lock | ||
Gemfile.lock | ||
gemfiles/*.lock | ||
|
||
# Ignore test files | ||
coverage/ | ||
|
||
# Ignore dummy app files | ||
spec/dummy/db/*.sqlite3 | ||
spec/dummy/db/*.sqlite3-journal | ||
spec/dummy/log/*.log | ||
spec/dummy/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
AllCops: | ||
TargetRubyVersion: 2.4 | ||
Exclude: | ||
- bin/* | ||
- gemfiles/* | ||
- spec/**/* | ||
|
||
Documentation: | ||
Enabled: false | ||
|
||
Layout/EmptyLinesAroundModuleBody: | ||
Enabled: false | ||
|
||
Layout/EmptyLinesAroundClassBody: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
language: ruby | ||
cache: bundler | ||
sudo: false | ||
rvm: | ||
- 2.6.1 | ||
- 2.5.3 | ||
- 2.4.5 | ||
- ruby-head | ||
before_install: | ||
- gem update --system | ||
- gem install bundler --no-document | ||
gemfile: | ||
- gemfiles/rails_5.0.7.gemfile | ||
- gemfiles/rails_5.1.6.gemfile | ||
- gemfiles/rails_5.2.2.gemfile | ||
- gemfiles/rails_6.0.0.beta2.gemfile | ||
before_script: | ||
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter | ||
- chmod +x ./cc-test-reporter | ||
- ./cc-test-reporter before-build | ||
after_script: | ||
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT | ||
matrix: | ||
exclude: | ||
- gemfile: gemfiles/rails_6.0.0.beta2.gemfile | ||
rvm: 2.4.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
RAILS_VERSIONS = %w[ | ||
5.0.7 | ||
5.1.6 | ||
5.2.2 | ||
6.0.0.beta2 | ||
].freeze | ||
|
||
RAILS_VERSIONS.each do |version| | ||
appraise "rails_#{version}" do | ||
gem 'rails', version | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
guard :rspec, cmd: 'bundle exec rspec' do | ||
require 'guard/rspec/dsl' | ||
dsl = Guard::RSpec::Dsl.new(self) | ||
|
||
# RSpec files | ||
rspec = dsl.rspec | ||
watch(rspec.spec_helper) { rspec.spec_dir } | ||
watch(rspec.spec_support) { rspec.spec_dir } | ||
watch(rspec.spec_files) | ||
|
||
# Ruby files | ||
ruby = dsl.ruby | ||
dsl.watch_spec_files_for(ruby.lib_files) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
The MIT License (MIT) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# ActsAsXLSX | ||
|
||
[![GitHub license](https://img.shields.io/github/license/jbox-web/acts_as_xlsx.svg)](https://github.com/jbox-web/acts_as_xlsx/blob/master/LICENSE) | ||
[![GitHub release](https://img.shields.io/github/release/jbox-web/acts_as_xlsx.svg)](https://github.com/jbox-web/acts_as_xlsx/releases/latest) | ||
[![Build Status](https://travis-ci.org/jbox-web/acts_as_xlsx.svg?branch=master)](https://travis-ci.org/jbox-web/acts_as_xlsx) | ||
[![Code Climate](https://codeclimate.com/github/jbox-web/acts_as_xlsx/badges/gpa.svg)](https://codeclimate.com/github/jbox-web/acts_as_xlsx) | ||
[![Test Coverage](https://codeclimate.com/github/jbox-web/acts_as_xlsx/badges/coverage.svg)](https://codeclimate.com/github/jbox-web/acts_as_xlsx/coverage) | ||
|
||
ActsAsXLSX is an ActiveRecord plugin for Axlsx. It makes generating Excel spreadsheets from any subclass of ActiveRecord::Base as simple as a couple of lines of code. | ||
|
||
## Installation | ||
|
||
Put this in your `Gemfile` : | ||
|
||
```ruby | ||
git_source(:github){ |repo_name| "https://github.com/#{repo_name}.git" } | ||
|
||
gem 'acts_as_xlsx', github: 'jbox-web/acts_as_xlsx', tag: '1.0.0' | ||
``` | ||
|
||
then run `bundle install`. | ||
|
||
## Usage | ||
|
||
See the Guides [here](http://axlsx.blog.randym.net/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
task default: :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'lib/acts_as_xlsx/version' | ||
|
||
Gem::Specification.new do |s| | ||
s.name = 'acts_as_xlsx' | ||
s.version = ActsAsXlsx::VERSION::STRING | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ['Nicolas Rodriguez'] | ||
s.email = ['nicoladmin@free.fr'] | ||
s.homepage = 'https://github.com/jbox-web/acts_as_xlsx' | ||
s.summary = 'A Rails roles solution.' | ||
s.license = 'MIT' | ||
|
||
s.required_ruby_version = '>= 2.4.4' | ||
|
||
s.files = `git ls-files`.split("\n") | ||
|
||
s.add_runtime_dependency 'axlsx' | ||
s.add_runtime_dependency 'i18n' | ||
s.add_runtime_dependency 'rails', '>= 5.0' | ||
s.add_runtime_dependency 'zeitwerk' | ||
|
||
s.add_development_dependency 'appraisal' | ||
s.add_development_dependency 'guard-rspec' | ||
s.add_development_dependency 'pry' | ||
s.add_development_dependency 'rake' | ||
s.add_development_dependency 'rspec-rails' | ||
s.add_development_dependency 'rubocop' | ||
s.add_development_dependency 'simplecov' | ||
s.add_development_dependency 'sqlite3', '~> 1.3.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# | ||
# This file was generated by Bundler. | ||
# | ||
# The application '_guard-core' is installed as part of a gem, and | ||
# this file is here to facilitate running it. | ||
# | ||
|
||
require "pathname" | ||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", | ||
Pathname.new(__FILE__).realpath) | ||
|
||
bundle_binstub = File.expand_path("../bundle", __FILE__) | ||
|
||
if File.file?(bundle_binstub) | ||
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ | ||
load(bundle_binstub) | ||
else | ||
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. | ||
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") | ||
end | ||
end | ||
|
||
require "rubygems" | ||
require "bundler/setup" | ||
|
||
load Gem.bin_path("guard", "_guard-core") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# | ||
# This file was generated by Bundler. | ||
# | ||
# The application 'guard' is installed as part of a gem, and | ||
# this file is here to facilitate running it. | ||
# | ||
|
||
require "pathname" | ||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", | ||
Pathname.new(__FILE__).realpath) | ||
|
||
bundle_binstub = File.expand_path("../bundle", __FILE__) | ||
|
||
if File.file?(bundle_binstub) | ||
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ | ||
load(bundle_binstub) | ||
else | ||
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. | ||
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") | ||
end | ||
end | ||
|
||
require "rubygems" | ||
require "bundler/setup" | ||
|
||
load Gem.bin_path("guard", "guard") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# | ||
# This file was generated by Bundler. | ||
# | ||
# The application 'rubocop' is installed as part of a gem, and | ||
# this file is here to facilitate running it. | ||
# | ||
|
||
require "pathname" | ||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", | ||
Pathname.new(__FILE__).realpath) | ||
|
||
bundle_binstub = File.expand_path("../bundle", __FILE__) | ||
|
||
if File.file?(bundle_binstub) | ||
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ | ||
load(bundle_binstub) | ||
else | ||
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. | ||
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") | ||
end | ||
end | ||
|
||
require "rubygems" | ||
require "bundler/setup" | ||
|
||
load Gem.bin_path("rubocop", "rubocop") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "rails", "5.0.7" | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "rails", "5.1.6" | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "rails", "5.2.2" | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "rails", "6.0.0.beta2" | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'axlsx' | ||
|
||
require 'zeitwerk' | ||
loader = Zeitwerk::Loader.for_gem | ||
loader.setup | ||
|
||
module ActsAsXlsx | ||
require 'acts_as_xlsx/engine' if defined?(Rails) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActsAsXlsx | ||
module ClassMethods | ||
|
||
# Maps the AR class to an Axlsx package | ||
# options are passed into AR find | ||
# @param [Array, Array] columns as an array of symbols or a symbol that defines the attributes or methods to render in the sheet. | ||
# @option options [Integer] header_style to apply to the first row of field names | ||
# @option options [Array, Symbol] types an array of Axlsx types for each cell in data rows or a single type that will be applied to all types. | ||
# @option options [Integer, Array] style The style to pass to Worksheet#add_row | ||
# @option options [String] i18n The path to i18n attributes. (usually activerecord.attributes) | ||
# @option options [Package] package An Axlsx::Package. When this is provided the output will be added to the package as a new sheet. # @option options [String] name This will be used to name the worksheet added to the package. If it is not provided the name of the table name will be humanized when i18n is not specified or the I18n.t for the table name. | ||
# @see Worksheet#add_row | ||
def to_xlsx(options = {}) | ||
self.xlsx_columns = column_names.map(&:to_sym) if xlsx_columns.nil? | ||
|
||
row_style = options.delete(:style) | ||
header_style = options.delete(:header_style) || row_style | ||
types = [options.delete(:types) || []].flatten | ||
|
||
i18n = options.delete(:i18n) || xlsx_i18n | ||
columns = options.delete(:columns) || xlsx_columns | ||
|
||
p = options.delete(:package) || Axlsx::Package.new | ||
row_style = p.workbook.styles.add_style(row_style) unless row_style.nil? | ||
header_style = p.workbook.styles.add_style(header_style) unless header_style.nil? | ||
i18n = xlsx_i18n == true ? 'activerecord.attributes' : i18n | ||
sheet_name = options.delete(:name) || (i18n ? I18n.t("#{i18n}.#{table_name.underscore}") : table_name.humanize) | ||
data = options.delete(:data) || where(options[:where]).order(options[:order]).to_a | ||
data.compact! if data.respond_to?(:compact!) | ||
data.flatten! if data.respond_to?(:flatten!) | ||
|
||
return p if data.empty? | ||
|
||
p.workbook.add_worksheet(name: sheet_name) do |sheet| | ||
col_labels = | ||
if i18n | ||
columns.map { |c| I18n.t("#{i18n}.#{name.underscore}.#{c}") } | ||
else | ||
columns.map { |c| c.to_s.humanize } | ||
end | ||
|
||
sheet.add_row(col_labels, style: header_style) | ||
|
||
data.each do |r| | ||
row_data = columns.map do |c| | ||
if c.to_s =~ /\./ | ||
v = r; c.to_s.split('.').each { |method| !v.nil? ? v = v.send(method) : v = ""; }; v | ||
else | ||
r.send(c) | ||
end | ||
end | ||
sheet.add_row(row_data, style: row_style, types: types) | ||
end | ||
end | ||
p | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActsAsXlsx | ||
class Engine < ::Rails::Engine | ||
|
||
initializer 'acts_as_xlsx.initialize' do | ||
ActiveSupport.on_load(:active_record) do | ||
extend ActsAsXlsx::Macros | ||
end | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.