spreadsheet_template 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sor.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 10to1
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,60 @@
1
+ SpreadsheetTemplate
2
+ ==================
3
+
4
+ A Rails plugin to generate xls documents by using rxls templates.
5
+
6
+ Based on Spreadsheet on Rails (by Koen Van der Auwera) plugin (http://github.com/10to1/spreadsheet_on_rails) but supports Rails 3.
7
+
8
+ Dependencies
9
+ ============
10
+
11
+ ruby-ole
12
+ spreadsheet
13
+ iconv
14
+
15
+ Example
16
+ =======
17
+
18
+ Example spreadsheet usage as found here: http://github.com/jacobat/ruby-spreadsheet
19
+
20
+ -- in the view "index.xls.rxls
21
+
22
+ sheet = workbook.create_worksheet
23
+ sheet.name = "What's in a name"
24
+
25
+ sheet.row(0).concat %w{Name Country Acknowlegement}
26
+ sheet[1,0] = 'Japan'
27
+ row = sheet.row(1)
28
+ row.push 'Creator of Ruby'
29
+ row.unshift 'Yukihiro Matsumoto'
30
+ sheet.row(2).replace [ 'Daniel J. Berger', 'U.S.A.',
31
+ 'Author of original code for Spreadsheet::Excel' ]
32
+ sheet.row(3).push 'Charles Lowe', 'Author of the ruby-ole Library'
33
+ sheet.row(3).insert 1, 'Unknown'
34
+ sheet.update_row 4, 'Hannes Wyss', 'Switzerland', 'Author'
35
+
36
+ sheet.row(0).height = 18
37
+
38
+ format = Spreadsheet::Format.new :color => :blue,
39
+ :weight => :bold,
40
+ :size => 18
41
+ sheet.row(0).default_format = format
42
+
43
+ bold = Spreadsheet::Format.new :weight => :bold
44
+ 4.times do |x| sheet.row(x + 1).set_format(0, bold) end
45
+
46
+
47
+ -- in the controller
48
+
49
+ def index
50
+ @lines = Line.find(:all)
51
+
52
+ respond_to do |format|
53
+ format.html # index.html.erb
54
+ format.xml { render :xml => @lines }
55
+ format.xls { render :action => "index", :layout => false }
56
+ end
57
+ end
58
+
59
+
60
+ Copyright (c) 2009 10to1, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,11 @@
1
+ require 'spreadsheet_template'
2
+ require 'rails'
3
+
4
+ module SpreadsheetTemplate
5
+ class SpreadsheetTemplateRailtie < Rails::Railtie
6
+ initializer "spreadsheet_template_railtie.boot_spreadsheet_template" do
7
+ Mime::Type.register "application/excel", :xls
8
+ ActionView::Template.register_template_handler 'rxls', SpreadsheetTemplate::Handler
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module SpreadsheetTemplate
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,41 @@
1
+ require 'spreadsheet_template/railtie.rb'
2
+
3
+ module SpreadsheetTemplate
4
+
5
+ class Handler < ::ActionView::TemplateHandler
6
+ include ActionView::TemplateHandlers::Compilable
7
+
8
+ def compile(template)
9
+ %Q{controller.response.content_type ||= Mime::XLS
10
+ controller.headers["Content-Disposition"] = "attachment"
11
+ SpreadsheetTemplate::Base.new { |workbook| #{template.source} }.process}
12
+ end
13
+
14
+ end
15
+
16
+ class Base
17
+ @@temp_file = nil
18
+
19
+ def temp_file_path
20
+ unless @@temp_file
21
+ temp = Tempfile.new('spreadsheet-', File.join(Rails.root.to_s, 'tmp') )
22
+ @@temp_file = temp.path
23
+ temp.close
24
+ end
25
+ @@temp_file
26
+ end
27
+
28
+ def initialize
29
+ yield workbook
30
+ end
31
+
32
+ def workbook
33
+ @workbook ||= Spreadsheet::Workbook.new
34
+ end
35
+
36
+ def process
37
+ workbook.write(temp_file_path)
38
+ File.open(temp_file_path, 'rb') { |file| file.read }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "spreadsheet_template/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "spreadsheet_template"
7
+ s.version = SpreadsheetTemplate::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Craig Knox"]
10
+ s.email = ["cknox@insiliflo.com"]
11
+ s.homepage = "http://rubygems.org/gems/spreadsheet_template"
12
+ s.summary = %q{Rails plugin to generate excel documents (xls) by using rxls templates.}
13
+ s.description = %q{Based on Spreadsheet on Rails (by Koen Van der Auwera), Spreadsheet Template is designed to work with Rails 3.0 and above.}
14
+
15
+ s.rubyforge_project = nil
16
+
17
+ s.add_dependency('rails', '>= 3.0')
18
+ s.add_dependency('ruby-ole', '>= 1.2.10.1')
19
+ s.add_dependency('spreadsheet', '>= 0.6.4.1')
20
+ s.add_dependency('iconv', '>= 0.1')
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class SpreadsheetOnRailsTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spreadsheet_template
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Craig Knox
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-17 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 7
29
+ segments:
30
+ - 3
31
+ - 0
32
+ version: "3.0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: ruby-ole
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 101
44
+ segments:
45
+ - 1
46
+ - 2
47
+ - 10
48
+ - 1
49
+ version: 1.2.10.1
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: spreadsheet
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 109
61
+ segments:
62
+ - 0
63
+ - 6
64
+ - 4
65
+ - 1
66
+ version: 0.6.4.1
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: iconv
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 9
78
+ segments:
79
+ - 0
80
+ - 1
81
+ version: "0.1"
82
+ type: :runtime
83
+ version_requirements: *id004
84
+ description: Based on Spreadsheet on Rails (by Koen Van der Auwera), Spreadsheet Template is designed to work with Rails 3.0 and above.
85
+ email:
86
+ - cknox@insiliflo.com
87
+ executables: []
88
+
89
+ extensions: []
90
+
91
+ extra_rdoc_files: []
92
+
93
+ files:
94
+ - Gemfile
95
+ - MIT-LICENSE
96
+ - README
97
+ - Rakefile
98
+ - lib/spreadsheet_template.rb
99
+ - lib/spreadsheet_template/railtie.rb
100
+ - lib/spreadsheet_template/version.rb
101
+ - spreadsheet_template.gemspec
102
+ - test/spreadsheet_on_rails_test.rb
103
+ - test/test_helper.rb
104
+ has_rdoc: true
105
+ homepage: http://rubygems.org/gems/spreadsheet_template
106
+ licenses: []
107
+
108
+ post_install_message:
109
+ rdoc_options: []
110
+
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ requirements: []
132
+
133
+ rubyforge_project:
134
+ rubygems_version: 1.3.7
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Rails plugin to generate excel documents (xls) by using rxls templates.
138
+ test_files:
139
+ - test/spreadsheet_on_rails_test.rb
140
+ - test/test_helper.rb