rails-excel 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -5
- data/lib/rails-excel.rb +35 -21
- data/lib/rails-excel/delegation.rb +19 -21
- data/lib/rails-excel/strategies/spreadsheet.rb +10 -11
- data/lib/rails-excel/strategies/write_excel.rb +8 -10
- data/lib/rails-excel/template_handler.rb +5 -7
- data/lib/rails-excel/version.rb +2 -4
- data/rails-excel.gemspec +1 -1
- metadata +31 -22
data/README.md
CHANGED
@@ -6,8 +6,8 @@ It comes with two builtin strategies based on the very good gems [writeexcel](ht
|
|
6
6
|
|
7
7
|
# Requirements
|
8
8
|
|
9
|
-
* rails
|
10
|
-
* ruby
|
9
|
+
* rails >= 2.3.0
|
10
|
+
* ruby >= '1.8.6'
|
11
11
|
|
12
12
|
|
13
13
|
# Usage
|
@@ -21,7 +21,7 @@ config.gem 'rails-excel'
|
|
21
21
|
Create an initializer : config/initializers/excel.rb
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
|
24
|
+
RailsExcel.configure do |config|
|
25
25
|
config.strategy = :spreadsheet # by default or :write_excel
|
26
26
|
end
|
27
27
|
```
|
@@ -51,7 +51,7 @@ Then in your config/initializers/excel.rb
|
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
require 'my_strategy'
|
54
|
-
|
54
|
+
RailsExcel.configure do |config|
|
55
55
|
config.add_strategy :my_strategy, MyStrategy.new
|
56
56
|
# Redefining default strategy
|
57
57
|
config.strategy = :my_strategy # by default it was :spreadsheet
|
@@ -97,4 +97,4 @@ end
|
|
97
97
|
|
98
98
|
# Contributors
|
99
99
|
|
100
|
-
* [edpaget](https://github.com/edpaget)
|
100
|
+
* [edpaget](https://github.com/edpaget)
|
data/lib/rails-excel.rb
CHANGED
@@ -6,34 +6,48 @@ require 'rails-excel/template_handler'
|
|
6
6
|
|
7
7
|
module Rails
|
8
8
|
module Excel
|
9
|
-
|
10
|
-
BUILTIN_STRATEGIES = {
|
11
|
-
:spreadsheet => Rails::Excel::Strategies::Spreadsheet,
|
12
|
-
:write_excel => Rails::Excel::Strategies::WriteExcel
|
13
|
-
} unless const_defined?(:BUILTIN_STRATEGIES)
|
14
|
-
|
15
9
|
class << self
|
16
10
|
module_eval do
|
11
|
+
%w{add_strategy configure}.each do |m|
|
12
|
+
define_method m do |*args|
|
13
|
+
ActiveSupport::Deprecation.warn("Rails::Excel is deprecated in favor of RailsExcel",caller)
|
14
|
+
RailsExcel.send(m, *args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
+
end
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
module RailsExcel
|
24
|
+
BUILTIN_STRATEGIES = {
|
25
|
+
:spreadsheet => RailsExcel::Strategies::Spreadsheet,
|
26
|
+
:write_excel => RailsExcel::Strategies::WriteExcel
|
27
|
+
} unless const_defined?(:BUILTIN_STRATEGIES)
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
29
|
+
class << self
|
30
|
+
module_eval do
|
31
|
+
|
32
|
+
attr_accessor :strategy
|
33
|
+
attr_reader :available_strategies
|
34
|
+
|
35
|
+
def add_strategy(name, instance)
|
36
|
+
@available_strategies[name.to_sym] = instance
|
37
|
+
end
|
35
38
|
|
39
|
+
def configure(&block)
|
40
|
+
@available_strategies = Hash.new
|
41
|
+
BUILTIN_STRATEGIES.each do |k,v|
|
42
|
+
add_strategy k, v.new
|
43
|
+
end
|
44
|
+
yield(self)
|
45
|
+
::ActionView::Base.send :include, RailsExcel::Delegation::View
|
46
|
+
::ActionController::Base.send :include,RailsExcel::Delegation::Controller
|
47
|
+
ActionView::Template.register_template_handler :rxls, RailsExcel::TemplateHandler
|
36
48
|
end
|
49
|
+
|
37
50
|
end
|
38
51
|
end
|
52
|
+
|
39
53
|
end
|
@@ -1,33 +1,31 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
module Delegation
|
1
|
+
module RailsExcel
|
2
|
+
module Delegation
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
4
|
+
module View
|
5
|
+
def self.included(base)
|
6
|
+
base.module_eval do
|
7
|
+
delegate :excel_strategy, :to => :controller
|
10
8
|
end
|
11
9
|
end
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def excel_strategy=(strategy)
|
22
|
-
@excel_strategy = strategy
|
23
|
-
end
|
12
|
+
module Controller
|
13
|
+
def self.included(base)
|
14
|
+
base.module_eval do
|
15
|
+
class_inheritable_accessor :excel_strategy, :instance_writer => false
|
16
|
+
def excel_strategy
|
17
|
+
@excel_strategy ||= self.class.excel_strategy
|
18
|
+
end
|
24
19
|
|
25
|
-
|
20
|
+
def excel_strategy=(strategy)
|
21
|
+
@excel_strategy = strategy
|
26
22
|
end
|
27
23
|
|
24
|
+
self.excel_strategy = ::RailsExcel.strategy
|
28
25
|
end
|
29
|
-
end
|
30
26
|
|
27
|
+
end
|
31
28
|
end
|
29
|
+
|
32
30
|
end
|
33
31
|
end
|
@@ -1,22 +1,21 @@
|
|
1
1
|
require 'spreadsheet'
|
2
2
|
|
3
3
|
|
4
|
-
module
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
workbook.write(io)
|
13
|
-
end
|
4
|
+
module RailsExcel
|
5
|
+
module Strategies
|
6
|
+
|
7
|
+
class Spreadsheet
|
8
|
+
def compile(io, &block)
|
9
|
+
workbook = ::Spreadsheet::Workbook.new
|
10
|
+
yield(workbook)
|
11
|
+
workbook.write(io)
|
14
12
|
end
|
15
|
-
|
16
13
|
end
|
17
14
|
|
18
15
|
end
|
16
|
+
|
19
17
|
end
|
18
|
+
|
20
19
|
# This extends colors for spreadsheet gem
|
21
20
|
# See http://dmcritchie.mvps.org/excel/colors.htm#dpalette
|
22
21
|
|
@@ -1,16 +1,14 @@
|
|
1
1
|
require 'writeexcel'
|
2
|
-
module
|
3
|
-
module
|
4
|
-
module Strategies
|
2
|
+
module RailsExcel
|
3
|
+
module Strategies
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
5
|
+
class WriteExcel
|
6
|
+
def compile(io,&block)
|
7
|
+
workbook = ::WriteExcel.new(io)
|
8
|
+
yield(workbook)
|
9
|
+
workbook.close
|
12
10
|
end
|
13
|
-
|
14
11
|
end
|
12
|
+
|
15
13
|
end
|
16
14
|
end
|
@@ -1,17 +1,16 @@
|
|
1
1
|
require 'action_controller'
|
2
2
|
require 'action_view'
|
3
|
-
module
|
4
|
-
|
5
|
-
class TemplateHandler
|
3
|
+
module RailsExcel
|
4
|
+
class TemplateHandler
|
6
5
|
|
7
6
|
def self.call(template, *args)
|
8
|
-
new.compile(template)
|
7
|
+
new.compile(template)
|
9
8
|
end
|
10
|
-
|
9
|
+
|
11
10
|
def compile(template)
|
12
11
|
%Q{
|
13
12
|
io = StringIO.new
|
14
|
-
|
13
|
+
RailsExcel.available_strategies[self.excel_strategy].compile(io) do |workbook|
|
15
14
|
#{template.source}
|
16
15
|
end
|
17
16
|
self.output_buffer = io.string
|
@@ -20,6 +19,5 @@ module Rails
|
|
20
19
|
|
21
20
|
end
|
22
21
|
end
|
23
|
-
end
|
24
22
|
|
25
23
|
::Mime::Type.register "application/vnd.ms-excel", :xls
|
data/lib/rails-excel/version.rb
CHANGED
data/rails-excel.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-excel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
|
9
|
+
- 4
|
10
|
+
segments_generated: true
|
11
|
+
version: 0.0.4
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Ramihajamalala Hery
|
@@ -15,13 +16,12 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date:
|
19
|
+
date: 2012-01-02 00:00:00 +01:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: rake
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - "="
|
@@ -31,13 +31,14 @@ dependencies:
|
|
31
31
|
- 0
|
32
32
|
- 8
|
33
33
|
- 7
|
34
|
+
segments_generated: true
|
34
35
|
version: 0.8.7
|
36
|
+
prerelease: false
|
37
|
+
requirement: *id001
|
35
38
|
type: :development
|
36
|
-
version_requirements: *id001
|
37
39
|
- !ruby/object:Gem::Dependency
|
38
40
|
name: rspec
|
39
|
-
|
40
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
42
|
none: false
|
42
43
|
requirements:
|
43
44
|
- - ~>
|
@@ -47,13 +48,14 @@ dependencies:
|
|
47
48
|
- 2
|
48
49
|
- 3
|
49
50
|
- 0
|
51
|
+
segments_generated: true
|
50
52
|
version: 2.3.0
|
53
|
+
prerelease: false
|
54
|
+
requirement: *id002
|
51
55
|
type: :development
|
52
|
-
version_requirements: *id002
|
53
56
|
- !ruby/object:Gem::Dependency
|
54
57
|
name: rcov
|
55
|
-
|
56
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
57
59
|
none: false
|
58
60
|
requirements:
|
59
61
|
- - ~>
|
@@ -63,13 +65,14 @@ dependencies:
|
|
63
65
|
- 0
|
64
66
|
- 9
|
65
67
|
- 9
|
68
|
+
segments_generated: true
|
66
69
|
version: 0.9.9
|
70
|
+
prerelease: false
|
71
|
+
requirement: *id003
|
67
72
|
type: :development
|
68
|
-
version_requirements: *id003
|
69
73
|
- !ruby/object:Gem::Dependency
|
70
74
|
name: actionpack
|
71
|
-
|
72
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
75
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
73
76
|
none: false
|
74
77
|
requirements:
|
75
78
|
- - ~>
|
@@ -79,13 +82,14 @@ dependencies:
|
|
79
82
|
- 2
|
80
83
|
- 3
|
81
84
|
- 0
|
85
|
+
segments_generated: true
|
82
86
|
version: 2.3.0
|
87
|
+
prerelease: false
|
88
|
+
requirement: *id004
|
83
89
|
type: :development
|
84
|
-
version_requirements: *id004
|
85
90
|
- !ruby/object:Gem::Dependency
|
86
91
|
name: writeexcel
|
87
|
-
|
88
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
92
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
89
93
|
none: false
|
90
94
|
requirements:
|
91
95
|
- - ">="
|
@@ -95,13 +99,14 @@ dependencies:
|
|
95
99
|
- 0
|
96
100
|
- 6
|
97
101
|
- 8
|
102
|
+
segments_generated: true
|
98
103
|
version: 0.6.8
|
104
|
+
prerelease: false
|
105
|
+
requirement: *id005
|
99
106
|
type: :runtime
|
100
|
-
version_requirements: *id005
|
101
107
|
- !ruby/object:Gem::Dependency
|
102
108
|
name: spreadsheet
|
103
|
-
|
104
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
109
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
105
110
|
none: false
|
106
111
|
requirements:
|
107
112
|
- - ">="
|
@@ -112,9 +117,11 @@ dependencies:
|
|
112
117
|
- 6
|
113
118
|
- 3
|
114
119
|
- 1
|
120
|
+
segments_generated: true
|
115
121
|
version: 0.6.3.1
|
122
|
+
prerelease: false
|
123
|
+
requirement: *id006
|
116
124
|
type: :runtime
|
117
|
-
version_requirements: *id006
|
118
125
|
description: "Use different strategies to write excel : available are :spreadsheet and :writeexcel\n This implements rxls template in your rails view\n "
|
119
126
|
email:
|
120
127
|
- hery@weborama.com
|
@@ -157,6 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
164
|
hash: 3
|
158
165
|
segments:
|
159
166
|
- 0
|
167
|
+
segments_generated: true
|
160
168
|
version: "0"
|
161
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
170
|
none: false
|
@@ -166,6 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
174
|
hash: 3
|
167
175
|
segments:
|
168
176
|
- 0
|
177
|
+
segments_generated: true
|
169
178
|
version: "0"
|
170
179
|
requirements: []
|
171
180
|
|