fast_excel_rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +25 -0
- data/LICENSE.txt +21 -0
- data/README.md +79 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fast_excel_rails.gemspec +28 -0
- data/lib/fast_excel_rails.rb +5 -0
- data/lib/fast_excel_rails/railtie.rb +31 -0
- data/lib/fast_excel_rails/template_handler.rb +30 -0
- data/lib/fast_excel_rails/version.rb +3 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '04786851f3112db346d86f46931f7546425264f7e2834086915f3cac8454f5b9'
|
4
|
+
data.tar.gz: cbd27cc8c28343e8f445f597f442f1fdd365c634637171bec02f473dadaad023
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71d6c3694b6e70dacd0cdf075866f3f1c0cc536d2dec7b8d7ff14313b1506f94df74ae7bb5330328ba23151bbe467314c610afd5190877e9a7806a3eea79e86c
|
7
|
+
data.tar.gz: fa3a631a5ea3a7035231bbacfe8622b4960335a3e76ff76fed2c1f25fd6b81e59ccf33b77dc33dcd5a10fd572dd9dedd086afc70c01914315523c3fd087c780e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fast_excel_rails (0.1.0)
|
5
|
+
fast_excel (~> 0.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
fast_excel (0.4.0)
|
11
|
+
ffi (> 1.9, < 2)
|
12
|
+
ffi (1.15.3)
|
13
|
+
minitest (5.14.4)
|
14
|
+
rake (12.3.3)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
fast_excel_rails!
|
21
|
+
minitest (~> 5.0)
|
22
|
+
rake (~> 12.0)
|
23
|
+
|
24
|
+
BUNDLED WITH
|
25
|
+
2.1.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Nick Muerdter
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# FastExcelRails
|
2
|
+
|
3
|
+
A Rails template handler for the [fast_excel](https://github.com/Paxa/fast_excel) gem.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "fast_excel_rails"
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Controllers
|
22
|
+
|
23
|
+
The default template file for your controller action can be rendered using `format.xlsx`:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class ThingsController < ApplicationController
|
27
|
+
def index
|
28
|
+
@things = (1..1000).to_a
|
29
|
+
respond_to do |format|
|
30
|
+
format.xlsx
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
Other options, like filenames or custom template paths, can be set using an explicit render call:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
class ThingsController < ApplicationController
|
40
|
+
def index
|
41
|
+
respond_to do |format|
|
42
|
+
format.xlsx { render :xlsx => "my filname.xlsx", :template => "custom_template"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
### Templates
|
49
|
+
|
50
|
+
Templates use the `.xlsx.fast_excel` extension and are normal Ruby files that have access to a `workbook` variable that is a [`FastExcel::Workbook`](https://github.com/Paxa/fast_excel) instance.
|
51
|
+
|
52
|
+
For example, `app/views/things/index.xlsx.fast_excel`:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
worksheet = workbook.add_worksheet
|
56
|
+
|
57
|
+
worksheet.append_row(["Message", "Price", "Date"], workbook.bold_format)
|
58
|
+
|
59
|
+
@things.each do |i|
|
60
|
+
worksheet << ["Hello", (rand * i).round(2), Time.now])
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
See [fast_excel](https://github.com/Paxa/fast_excel) for further information on usage syntax.
|
65
|
+
|
66
|
+
## Development
|
67
|
+
|
68
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
69
|
+
|
70
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fast_excel_rails.
|
75
|
+
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fast_excel_rails"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'lib/fast_excel_rails/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "fast_excel_rails"
|
5
|
+
spec.version = FastExcelRails::VERSION
|
6
|
+
spec.authors = ["Nick Muerdter"]
|
7
|
+
spec.email = ["12112+GUI@users.noreply.github.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{A Rails template handler for the fast_excel gem.}
|
10
|
+
spec.homepage = "https://github.com/GUI/fast_excel_rails"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/GUI/fast_excel_rails/tree/v#{FastExcelRails::VERSION}"
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/GUI/fast_excel_rails/blob/v#{FastExcelRails::VERSION}/CHANGELOG.md"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_dependency "fast_excel", "~> 0.1"
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "action_controller"
|
2
|
+
require "fast_excel_rails/template_handler"
|
3
|
+
|
4
|
+
module FastExcelRails
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
initializer "fast_excel_rails.register" do |app|
|
7
|
+
ActiveSupport.on_load(:action_view) do
|
8
|
+
ActionView::Template.register_template_handler :fast_excel, FastExcelRails::TemplateHandler.new
|
9
|
+
end
|
10
|
+
|
11
|
+
ActiveSupport.on_load(:action_controller) do
|
12
|
+
unless Mime::Type.lookup_by_extension(:xlsx)
|
13
|
+
Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
|
14
|
+
end
|
15
|
+
|
16
|
+
ActionController::Renderers.add :xlsx do |filename, options|
|
17
|
+
unless filename.end_with?(".xlsx")
|
18
|
+
filename = "#{filename}.xlsx"
|
19
|
+
end
|
20
|
+
|
21
|
+
disposition = options.delete(:disposition) || "attachment"
|
22
|
+
|
23
|
+
options[:layout] = false
|
24
|
+
|
25
|
+
content = render_to_string(options)
|
26
|
+
send_data(content, :type => :xlsx, :filename => filename, :disposition => disposition)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "action_view"
|
2
|
+
|
3
|
+
module FastExcelRails
|
4
|
+
class TemplateHandler
|
5
|
+
def default_format
|
6
|
+
:xlsx
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(template, source = nil)
|
10
|
+
<<-eos
|
11
|
+
# Only build one shared workbook object so partials can take advantage
|
12
|
+
# of the same workbook by default.
|
13
|
+
root_view = false
|
14
|
+
unless @fast_excel_rails_template_workbook
|
15
|
+
@fast_excel_rails_template_workbook = FastExcel.open
|
16
|
+
root_view = true
|
17
|
+
end
|
18
|
+
|
19
|
+
# Define a local "workbook" variable for accessing things inside the
|
20
|
+
# template.
|
21
|
+
workbook = @fast_excel_rails_template_workbook
|
22
|
+
#{source || template.source}
|
23
|
+
|
24
|
+
if root_view
|
25
|
+
@fast_excel_rails_template_workbook.read_string
|
26
|
+
end
|
27
|
+
eos
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast_excel_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Muerdter
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-07-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fast_excel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- 12112+GUI@users.noreply.github.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- bin/console
|
41
|
+
- bin/setup
|
42
|
+
- fast_excel_rails.gemspec
|
43
|
+
- lib/fast_excel_rails.rb
|
44
|
+
- lib/fast_excel_rails/railtie.rb
|
45
|
+
- lib/fast_excel_rails/template_handler.rb
|
46
|
+
- lib/fast_excel_rails/version.rb
|
47
|
+
homepage: https://github.com/GUI/fast_excel_rails
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata:
|
51
|
+
homepage_uri: https://github.com/GUI/fast_excel_rails
|
52
|
+
source_code_uri: https://github.com/GUI/fast_excel_rails/tree/v0.1.0
|
53
|
+
changelog_uri: https://github.com/GUI/fast_excel_rails/blob/v0.1.0/CHANGELOG.md
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.3.0
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.1.2
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: A Rails template handler for the fast_excel gem.
|
73
|
+
test_files: []
|