rails-excel 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create ree-1.8.6@rails-excel
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rails-excel.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
7
+ end
8
+
9
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
10
+ spec.pattern = 'spec/**/*_spec.rb'
11
+ spec.rcov = true
12
+ spec.rcov_opts = [ '--exclude gems', '--exclude spec']
13
+ end
14
+
15
+ task :default => [:spec]
16
+ task :build => [:spec]
17
+
@@ -0,0 +1,39 @@
1
+ require 'activesupport'
2
+ require "rails-excel/version"
3
+ require 'rails-excel/delegation'
4
+ require 'rails-excel/strategies'
5
+ require 'rails-excel/template_handler'
6
+
7
+ module Rails
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
+ class << self
16
+ module_eval do
17
+
18
+ attr_accessor_with_default :strategy, :spreadsheet
19
+ attr_reader :available_strategies
20
+
21
+ def add_strategy(name, instance)
22
+ @available_strategies[name.to_sym] = instance
23
+ end
24
+
25
+ def configure(&block)
26
+ @available_strategies = Hash.new
27
+ BUILTIN_STRATEGIES.each do |k,v|
28
+ add_strategy k, v.new
29
+ end
30
+ yield(self)
31
+ ::ActionView::Base.send :include, Rails::Excel::Delegation::View
32
+ ::ActionController::Base.send :include,Rails::Excel::Delegation::Controller
33
+ ActionView::Template.register_template_handler :rxls, Rails::Excel::TemplateHandler
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,25 @@
1
+ module Rails
2
+ module Excel
3
+ module Delegation
4
+
5
+ module View
6
+ def self.included(base)
7
+ base.module_eval do
8
+ delegate :excel_strategy, :to => :controller
9
+ end
10
+ end
11
+ end
12
+
13
+ module Controller
14
+ def self.included(base)
15
+ base.module_eval do
16
+ class_inheritable_accessor :excel_strategy, :instance_writer => false
17
+ self.excel_strategy = ::Rails::Excel.strategy
18
+ end
19
+
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,2 @@
1
+ require 'rails-excel/strategies/spreadsheet'
2
+ require 'rails-excel/strategies/write_excel'
@@ -0,0 +1,59 @@
1
+ require 'spreadsheet'
2
+
3
+
4
+ module Rails
5
+ module Excel
6
+ module Strategies
7
+
8
+ class Spreadsheet
9
+ def compile(io, &block)
10
+ workbook = ::Spreadsheet::Workbook.new
11
+ yield(workbook)
12
+ workbook.write(io)
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
20
+ # This extends colors for spreadsheet gem
21
+ # See http://dmcritchie.mvps.org/excel/colors.htm#dpalette
22
+
23
+ colors = %w{
24
+ black brown olive_green dark_green dark_teal dark_blue indigo dark_gray
25
+ dark_red orange dark__yellow green teal blue blue_gray gray
26
+ red light_orange lime sea_green aqua light_blue violet light_gray
27
+ pink gold yellow righ_green turquoise sky_blue plu lite_gray
28
+ rose tan light_yellow light_green light_turquoise plae_blue lavender white
29
+ periwinkle plum_plus ivory lite_turquoise dark_purple coral ocean_blue ice_blue
30
+ dark_blue pink_plus yellow_plus turquoise violet dark_red teal_plus blue_plus
31
+ }
32
+
33
+ color_indexes = %w{
34
+ 1 53 52 51 49 11 55 56
35
+ 9 46 12 10 14 5 47 16
36
+ 3 45 43 50 42 41 13 48
37
+ 7 44 6 4 8 33 54 15
38
+ 38 40 36 35 34 37 39 2
39
+ 17 18 19 20 21 22 23 24
40
+ 25 26 27 28 29 30 31 32
41
+ }
42
+
43
+ color_indexes.each_with_index do |c,i|
44
+ # Do not override already defined colors
45
+ color_num = c.to_i + 7
46
+ Spreadsheet::Excel::Internals::COLOR_CODES[color_num] = colors[i].to_sym unless Spreadsheet::Excel::Internals::COLOR_CODES.key?(color_num)
47
+ Spreadsheet::Excel::Internals::SEDOC_ROLOC[colors[i].to_sym] = color_num unless Spreadsheet::Excel::Internals::COLOR_CODES.key?(colors[i].to_sym)
48
+ end
49
+
50
+ # Add palette colors but not override existing colors
51
+ ObjectSpace.each_object(Class) do |m|
52
+ if m.ancestors.include?(Spreadsheet::Datatypes)
53
+ m::module_eval do
54
+ class << self
55
+ COLORS.replace(COLORS | Spreadsheet::Excel::Internals::SEDOC_ROLOC.keys)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,16 @@
1
+ require 'writeexcel'
2
+ module Rails
3
+ module Excel
4
+ module Strategies
5
+
6
+ class WriteExcel
7
+ def compile(io,&block)
8
+ workbook = ::WriteExcel.new(io)
9
+ yield(workbook)
10
+ workbook.close
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ require 'action_controller'
2
+ require 'action_view'
3
+ module Rails
4
+ module Excel
5
+ class TemplateHandler < ::ActionView::TemplateHandler
6
+ include ::ActionView::TemplateHandlers::Compilable
7
+
8
+ def compile(template)
9
+ %Q{
10
+ _set_controller_content_type(Mime::XLS);
11
+ io = StringIO.new
12
+ Rails::Excel.available_strategies[self.excel_strategy].compile(io) do |workbook|
13
+ #{template.source}
14
+ end
15
+ self.output_buffer = io.string
16
+ }
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+
23
+ ::Mime::Type.register "application/vnd.ms-excel", :xls
@@ -0,0 +1,5 @@
1
+ module Rails
2
+ module Excel
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rails-excel/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rails-excel"
7
+ s.version = Rails::Excel::VERSION
8
+ s.authors = ["Ramihajamalala Hery"]
9
+ s.email = ["hery@weborama.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A rails gem to write excel}
12
+ s.description = %q{Use different strategies to write excel : available are :spreadsheet and :writeexcel
13
+ This implements rxls template in your rails view
14
+ }
15
+
16
+ s.rubyforge_project = "rails-excel"
17
+
18
+ s.add_development_dependency 'rake', '= 0.8.7'
19
+ s.add_development_dependency 'rspec', '~> 2.3.0'
20
+ s.add_development_dependency 'rcov', '~> 0.9.9'
21
+ s.add_development_dependency 'actionpack', '~> 2.3.0'
22
+ s.add_dependency 'writeexcel', '>= 0.6.8'
23
+ s.add_dependency 'spreadsheet', '>= 0.6.3.1'
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-excel
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ramihajamalala Hery
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-22 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - "="
27
+ - !ruby/object:Gem::Version
28
+ hash: 49
29
+ segments:
30
+ - 0
31
+ - 8
32
+ - 7
33
+ version: 0.8.7
34
+ prerelease: false
35
+ requirement: *id001
36
+ type: :development
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 2
47
+ - 3
48
+ - 0
49
+ version: 2.3.0
50
+ prerelease: false
51
+ requirement: *id002
52
+ type: :development
53
+ - !ruby/object:Gem::Dependency
54
+ name: rcov
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 41
61
+ segments:
62
+ - 0
63
+ - 9
64
+ - 9
65
+ version: 0.9.9
66
+ prerelease: false
67
+ requirement: *id003
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: actionpack
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 2
79
+ - 3
80
+ - 0
81
+ version: 2.3.0
82
+ prerelease: false
83
+ requirement: *id004
84
+ type: :development
85
+ - !ruby/object:Gem::Dependency
86
+ name: writeexcel
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 23
93
+ segments:
94
+ - 0
95
+ - 6
96
+ - 8
97
+ version: 0.6.8
98
+ prerelease: false
99
+ requirement: *id005
100
+ type: :runtime
101
+ - !ruby/object:Gem::Dependency
102
+ name: spreadsheet
103
+ version_requirements: &id006 !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 113
109
+ segments:
110
+ - 0
111
+ - 6
112
+ - 3
113
+ - 1
114
+ version: 0.6.3.1
115
+ prerelease: false
116
+ requirement: *id006
117
+ type: :runtime
118
+ description: "Use different strategies to write excel : available are :spreadsheet and :writeexcel\n This implements rxls template in your rails view\n "
119
+ email:
120
+ - hery@weborama.com
121
+ executables: []
122
+
123
+ extensions: []
124
+
125
+ extra_rdoc_files: []
126
+
127
+ files:
128
+ - .gitignore
129
+ - .rvmrc
130
+ - Gemfile
131
+ - Rakefile
132
+ - lib/rails-excel.rb
133
+ - lib/rails-excel/delegation.rb
134
+ - lib/rails-excel/strategies.rb
135
+ - lib/rails-excel/strategies/spreadsheet.rb
136
+ - lib/rails-excel/strategies/write_excel.rb
137
+ - lib/rails-excel/template_handler.rb
138
+ - lib/rails-excel/version.rb
139
+ - rails-excel.gemspec
140
+ has_rdoc: true
141
+ homepage: ""
142
+ licenses: []
143
+
144
+ post_install_message:
145
+ rdoc_options: []
146
+
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 3
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ requirements: []
168
+
169
+ rubyforge_project: rails-excel
170
+ rubygems_version: 1.3.7
171
+ signing_key:
172
+ specification_version: 3
173
+ summary: A rails gem to write excel
174
+ test_files: []
175
+