write_xlsx_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.bundle/config ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ BUNDLE_PATH: vendor/bundle
3
+ BUNDLE_DISABLE_SHARED_GEMS: '1'
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .config
4
+ .yardoc
5
+ .idea
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/bundle/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Maxim Dobryakov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # write\_xlsx\_rails
2
+
3
+ Gem for generate Excel files from Rails views with [write\_xlsx](https://github.com/cxn03651/write_xlsx).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'write_xlsx_rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install write_xlsx_rails
18
+
19
+ ## Usage
20
+
21
+ write\_xlsx\_rails provides a renderer and a template handler. It adds the :xlsx format and parses .xlsx.wxlsx templates.
22
+
23
+ ###Controller
24
+
25
+ You can either use the typical format:
26
+
27
+ ```ruby
28
+ respond_to do |format|
29
+ format.xlsx
30
+ end
31
+ ```
32
+
33
+ or call render directly:
34
+
35
+ ```ruby
36
+ render xlsx: "foobar", filename: "annual-report", disposition: 'inline'
37
+ ```
38
+
39
+ If you merely want to specify a file name, you can do it one of two ways:
40
+
41
+ ```ruby
42
+ format.xlsx {
43
+ response.headers['Content-Disposition'] = 'attachment; filename="my_new_filename.xlsx"'
44
+ }
45
+ ```
46
+
47
+ or
48
+
49
+ ```ruby
50
+ format.xlsx {
51
+ render xlsx: "action_or_template", disposition: "attachment", filename: "my_new_filename.xlsx"
52
+ }
53
+ ```
54
+
55
+ > NOTE: Someday it would be nice to merely say something like:
56
+ render :filename, 'blah.xlsx"
57
+
58
+ ###Template
59
+
60
+ Use the .xlsx.wxlsx extension in the template, use `workbook` variable, which is set with WriteXLSX.new:
61
+
62
+ ```ruby
63
+ # Add a worksheet
64
+ worksheet = workbook.add_worksheet
65
+
66
+ # Add and define a format
67
+ format = workbook.add_format # Add a format
68
+ format.set_bold
69
+ format.set_color('red')
70
+ format.set_align('center')
71
+
72
+ # Write a formatted and unformatted string, row and column notation.
73
+ col = row = 0
74
+ worksheet.write(row, col, "Hi Excel!", format)
75
+ worksheet.write(1, col, "Hi Excel!")
76
+
77
+ # Write a number and a formula using A1 notation
78
+ worksheet.write('A3', 1.2345)
79
+ worksheet.write('A4', '=SIN(PI()/4)')
80
+ ```
81
+
82
+ If you use [acts\_as\_xlsx](https://github.com/randym/acts_as_xlsx), configure the active record normally, but specify the package in the template:
83
+
84
+ ```ruby
85
+ User.to_xlsx package: xlsx_package, (other options)
86
+ ```
87
+
88
+ ####Partials
89
+
90
+ Partials work as expected:
91
+
92
+ ```ruby
93
+ render partial: 'header', locals: { worksheet: worksheet }
94
+ ```
95
+
96
+ ##Dependencies
97
+
98
+ * [write\_xlsx](http://github.com/cxn03651/write_xlsx)
99
+
100
+ ##Authors
101
+
102
+ * [Maxim Dobryakov](https://github.com/maxd)
103
+
104
+ ## Contributing
105
+
106
+ 1. Fork it
107
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
108
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
109
+ 4. Push to the branch (`git push origin my-new-feature`)
110
+ 5. Create new Pull Request
111
+
112
+ ##Thanks
113
+
114
+ * Hideo Nakamura for [write\_xlsx](https://github.com/cxn03651/write_xlsx).
115
+ * Noel Peden for [axlsx](https://github.com/randym/axlsx) and [axlsx\_rails](https://github.com/straydogstudio/axlsx_rails).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ require 'action_controller'
2
+
3
+ unless defined? Mime::XLSX
4
+ Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
5
+ end
6
+
7
+ ActionController::Renderers.add :xlsx do |filename, options|
8
+ unless formats.include?(:xlsx) || Rails.version < '3.2'
9
+ formats[0] = :xlsx
10
+ end
11
+
12
+ if filename =~ /^\/([^\/]+)\/(.+)$/
13
+ options[:prefixes][0] = $1
14
+ filename = $2
15
+ end
16
+ options[:template] = filename
17
+
18
+ disposition = options.delete(:disposition) || 'attachment'
19
+ download_name = options.delete(:filename) || filename
20
+ download_name += ".xlsx" unless download_name =~ /\.xlsx$/
21
+
22
+ send_data render_to_string(options), filename: download_name, type: Mime::XLSX, disposition: disposition
23
+ end
24
+
25
+ # For respond_to default
26
+ class ActionController::Responder
27
+ def to_xlsx
28
+ controller.render xlsx: controller.action_name
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ require 'action_view'
2
+
3
+ module WriteXlsxRails
4
+ class WriteXlsxBuilder
5
+
6
+ def default_format
7
+ Mime::XLSX
8
+ end
9
+
10
+ def self.call(template)
11
+ <<-TEMPLATE
12
+ require 'stringio'
13
+
14
+ __io = StringIO.new
15
+ workbook = WriteXLSX.new(__io)
16
+
17
+ #{template.source}
18
+
19
+ workbook.close
20
+
21
+ __io.flush
22
+ __io.string
23
+ TEMPLATE
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ ActionView::Template.register_template_handler :wxlsx, WriteXlsxRails::WriteXlsxBuilder
@@ -0,0 +1,3 @@
1
+ module WriteXlsxRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'write_xlsx_rails/version'
2
+ require 'write_xlsx_rails/action_controller'
3
+ require 'write_xlsx_rails/template_handler'
4
+
5
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'write_xlsx_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'write_xlsx_rails'
8
+ spec.version = WriteXlsxRails::VERSION
9
+ spec.authors = ['Maxim Dobryakov']
10
+ spec.email = ['maxim.dobryakov@gmail.com']
11
+ spec.description = 'xlsx renderer for Rails base on write_xlsx gem'
12
+ spec.summary = 'xlsx renderer for Rails'
13
+ spec.homepage = 'https://github.com/maxd/write_xlsx_rails'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'write_xlsx'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: write_xlsx_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Maxim Dobryakov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: write_xlsx
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: xlsx renderer for Rails base on write_xlsx gem
63
+ email:
64
+ - maxim.dobryakov@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .bundle/config
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - lib/write_xlsx_rails.rb
76
+ - lib/write_xlsx_rails/action_controller.rb
77
+ - lib/write_xlsx_rails/template_handler.rb
78
+ - lib/write_xlsx_rails/version.rb
79
+ - write_xlsx_rails.gemspec
80
+ homepage: https://github.com/maxd/write_xlsx_rails
81
+ licenses:
82
+ - MIT
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.25
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: xlsx renderer for Rails
105
+ test_files: []