spreadsheet_rails 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/lib/spreadsheet_rails.rb +52 -0
- data/lib/spreadsheet_rails/railtie.rb +21 -0
- data/lib/spreadsheet_rails/version.rb +3 -0
- data/spreadsheet_rails.gemspec +25 -0
- metadata +124 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jon Riddle
|
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,49 @@
|
|
1
|
+
# SpreadsheetRails
|
2
|
+
|
3
|
+
SpreadsheetRails provides a template handler for ActionView to render
|
4
|
+
Microsoft Excel workbooks like any view. This was heavily inspired by
|
5
|
+
Prawn::Rails (https://github.com/Whoops/prawn-rails).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'spreadsheet_rails', git: 'git://github.com/jdrnetworking/spreadsheet_rails.git'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Create a view template named `[action_name].xls.spreadsheet`
|
20
|
+
|
21
|
+
### Block Syntax
|
22
|
+
|
23
|
+
spreadsheet_document(options) do |workbook|
|
24
|
+
workbook.create_worksheet name: 'My Great Worksheet'
|
25
|
+
end
|
26
|
+
|
27
|
+
### Override Workbook Class
|
28
|
+
|
29
|
+
You can also override the default workbook class (Spreadsheet::Workbook):
|
30
|
+
|
31
|
+
spreadsheet_document(renderer: MyWorkbook)
|
32
|
+
|
33
|
+
and then create your workbook class:
|
34
|
+
|
35
|
+
class MyWorkbook < Spreadsheet::Workbook
|
36
|
+
def initialize(io = nil, options = { default_format: Spreadsheet::Format.new })
|
37
|
+
super
|
38
|
+
create_worksheet name: 'Another Great Worksheet'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
49
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spreadsheet_rails/version'
|
2
|
+
require 'spreadsheet_rails/railtie' if defined?(Rails)
|
3
|
+
|
4
|
+
module SpreadsheetRails
|
5
|
+
module SpreadsheetRailsHelper
|
6
|
+
##
|
7
|
+
# Render a new or existing spreadsheet workbook
|
8
|
+
#
|
9
|
+
# Pass an instance of Spreadsheet::Workbook to render it directly
|
10
|
+
#
|
11
|
+
# Valid options:
|
12
|
+
# :filename: sent to client in the Content-Disposition header
|
13
|
+
# :renderer: subclass of Spreadsheet::Workbook to use, defaults to Spreadsheet::Workbook
|
14
|
+
# :io: optional IO object pass to Spreadsheet::Workbook#initialize
|
15
|
+
#
|
16
|
+
# Yields the workbook object unless a spreadsheet instance is given
|
17
|
+
def spreadsheet_document(workbook = nil, options = {})
|
18
|
+
filename = options.delete(:filename)
|
19
|
+
|
20
|
+
unless workbook
|
21
|
+
klass = options.delete(:renderer) || Spreadsheet::Workbook
|
22
|
+
klass_args = [options.delete(:io)]
|
23
|
+
klass_args << options unless options.empty?
|
24
|
+
workbook = klass.new(*klass_args)
|
25
|
+
yield workbook if block_given?
|
26
|
+
end
|
27
|
+
|
28
|
+
disposition = "attachment;"
|
29
|
+
disposition += %Q( filename="#{filename}") if filename
|
30
|
+
headers['Content-Disposition'] = disposition
|
31
|
+
|
32
|
+
render_io workbook
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Renders to a string any object that will #write to an IO object
|
37
|
+
def render_io(writer)
|
38
|
+
StringIO.new.tap do |io|
|
39
|
+
writer.write(io)
|
40
|
+
end.string
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class TemplateHandler
|
45
|
+
class_attribute :default_format
|
46
|
+
self.default_format = :pdf
|
47
|
+
|
48
|
+
def self.call(template)
|
49
|
+
"#{template.source.strip}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spreadsheet'
|
2
|
+
|
3
|
+
module SpreadsheetRails
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer "spreadsheet_rails.register_mime_type" do
|
6
|
+
Mime::Type.register_alias('application/vnd.ms-excel', :xls) unless Mime::Type.lookup_by_extension(:xls)
|
7
|
+
end
|
8
|
+
|
9
|
+
initializer "spreadsheet_rails.register_template_handler" do
|
10
|
+
ActiveSupport.on_load(:action_view) do
|
11
|
+
ActionView::Template.register_template_handler(:spreadsheet, SpreadsheetRails::TemplateHandler)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
initializer "spreadsheet_rails.include_action_view_helper" do
|
16
|
+
ActiveSupport.on_load(:action_view) do
|
17
|
+
ActionView::Base.send(:include, SpreadsheetRails::SpreadsheetRailsHelper)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -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 'spreadsheet_rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "spreadsheet_rails"
|
8
|
+
spec.version = SpreadsheetRails::VERSION
|
9
|
+
spec.authors = ["Jon Riddle"]
|
10
|
+
spec.email = ["coder@jdrnetworking.com"]
|
11
|
+
spec.description = %q{Use spreadsheet views in Rails 3}
|
12
|
+
spec.summary = %q{Use spreadsheet views in Rails 3}
|
13
|
+
spec.homepage = "https://github.com/jdrnetworking/spreadsheet_rails"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/) - %w(.gitignore)
|
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_runtime_dependency "spreadsheet"
|
22
|
+
spec.add_runtime_dependency "rails", ">= 3.1"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spreadsheet_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jon Riddle
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: spreadsheet
|
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: rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.1'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.1'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
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: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Use spreadsheet views in Rails 3
|
79
|
+
email:
|
80
|
+
- coder@jdrnetworking.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- Gemfile
|
86
|
+
- LICENSE.txt
|
87
|
+
- README.md
|
88
|
+
- Rakefile
|
89
|
+
- lib/spreadsheet_rails.rb
|
90
|
+
- lib/spreadsheet_rails/railtie.rb
|
91
|
+
- lib/spreadsheet_rails/version.rb
|
92
|
+
- spreadsheet_rails.gemspec
|
93
|
+
homepage: https://github.com/jdrnetworking/spreadsheet_rails
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
hash: -3697989438872928748
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
hash: -3697989438872928748
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.8.25
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Use spreadsheet views in Rails 3
|
124
|
+
test_files: []
|