excel-esv 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a2ad78c50712dd3abd619474ff2637db64b514d3
4
+ data.tar.gz: 773c73f51f0516299ff6a9e3a314329b3750203c
5
+ SHA512:
6
+ metadata.gz: 6bf4dfbe7f5cc555c1c1d03fbfec88bdccc08cba67bba4ba189e6c714ff946cba5cf6382eb67d489886946d76d654262de62e2db09a2b06c31b2f7df1ac4d265
7
+ data.tar.gz: c8a0f32f0869fa1d10a1b21045f6d219d2436c74743ef8e32523e3c083a2551d4924148071c70781a7572d4060143185b2a1225502693a3d119acefc31f1fb1e
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in esv.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Auctionet.com
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.
@@ -0,0 +1,83 @@
1
+ # ESV
2
+
3
+ Ruby library/gem for Excel generation with the ease of CSV generation.
4
+
5
+ Exporting CSVs because Excel generation is too complex? No more!
6
+
7
+ CSVs can be difficult to open correctly, e.g. in Excel on Mac.
8
+
9
+
10
+ ## Usage
11
+
12
+ ```
13
+ data = ESV.generate do |esv|
14
+ esv << [ "Name", "Dogs", "Cats" ]
15
+ esv << [ "Victor", 1, 4 ]
16
+ end
17
+
18
+ File.write("/tmp/test.xls", data)
19
+ ```
20
+
21
+ ### Ruby on Rails
22
+
23
+ In `config/initializers/mime_types.rb`:
24
+
25
+ ```
26
+ Mime::Type.register ESV::MIME_TYPE, "xls"
27
+ ```
28
+
29
+ As a model or whatever you prefer:
30
+
31
+ ```
32
+ class MyExcelDocument
33
+ def generate(name)
34
+ ESV.generate { |esv| esv << [ "Hello #{name}" ] }
35
+ end
36
+ end
37
+ ```
38
+
39
+ Controller:
40
+
41
+ ```
42
+ class MyController < ApplicationController
43
+ include ESV::RailsController # for send_excel
44
+
45
+ def show
46
+ data = MyExcelDocument.new("Rails").generate
47
+ send_excel(data)
48
+ end
49
+
50
+ def another_example
51
+ respond_to do |format|
52
+ format.html { … }
53
+ format.xls { send_excel(…) }
54
+ end
55
+ end
56
+ end
57
+ ```
58
+
59
+
60
+ ## Installation
61
+
62
+ Add this line to your application's Gemfile:
63
+
64
+ ```ruby
65
+ gem 'excel-esv'
66
+ ```
67
+
68
+ And then execute:
69
+
70
+ $ bundle
71
+
72
+ Or install it yourself as:
73
+
74
+ $ gem install excel-esv
75
+
76
+
77
+ ## Credits and license
78
+
79
+ By Henrik Nyh for Auctionet.com under the MIT license.
80
+
81
+ Using [a lot of code](https://github.com/livingsocial/excelinator/blob/master/lib/excelinator/xls.rb) from LivingSocial's [Excelinator](https://github.com/livingsocial/excelinator), also under the MIT license.
82
+
83
+ This library is a thin wrapper around [Spreadsheet](https://github.com/zdavatz/spreadsheet) which does the heavy lifting.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'esv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "excel-esv"
8
+ spec.version = ESV::VERSION
9
+ spec.authors = ["Henrik Nyh"]
10
+ spec.email = ["henrik@nyh.se"]
11
+ spec.summary = %q{Excel generation with the ease of CSV generation.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "spreadsheet"
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,34 @@
1
+ require "esv/version"
2
+ require "esv/rails_controller"
3
+ require "spreadsheet"
4
+
5
+ class ESV
6
+ def self.generate
7
+ instance = new
8
+ yield(instance)
9
+ instance.render
10
+ end
11
+
12
+ def initialize
13
+ @data_rows = []
14
+ end
15
+
16
+ def <<(row)
17
+ @data_rows << row
18
+ end
19
+
20
+ def render
21
+ book = Spreadsheet::Workbook.new
22
+ sheet = book.create_worksheet
23
+
24
+ @data_rows.each_with_index do |data_row, index|
25
+ row = sheet.row(index)
26
+ row.push(*data_row)
27
+ end
28
+
29
+ content = ""
30
+ fake_file = StringIO.new(content)
31
+ book.write(fake_file)
32
+ content
33
+ end
34
+ end
@@ -0,0 +1,16 @@
1
+ class ESV
2
+ MIME_TYPE = "application/vnd.ms-excel"
3
+ CONTENT_TYPE = "#{MIME_TYPE}; charset=utf-8"
4
+
5
+ module RailsController
6
+ private
7
+
8
+ def send_excel(data)
9
+ send_data(
10
+ data,
11
+ type: ESV::CONTENT_TYPE,
12
+ disposition: "attachment",
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ class ESV
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ # Rails will automatically require a file with the gem's name.
2
+
3
+ require "esv"
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: excel-esv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Henrik Nyh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: spreadsheet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - henrik@nyh.se
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - excel-esv.gemspec
68
+ - lib/esv.rb
69
+ - lib/esv/rails_controller.rb
70
+ - lib/esv/version.rb
71
+ - lib/excel-esv.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Excel generation with the ease of CSV generation.
96
+ test_files: []