rails-excel 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,3 +1,7 @@
1
+ 2011-09-26 18:33 Ramihajamalala Hery <hery@weborama.com> v0.0.3
2
+
3
+ * Compatibility with Rails 3.x (by edpaget)
4
+
1
5
  2011-08-23 12:19 Ramihajamalala Hery <hery@weborama.com> v0.0.2
2
6
 
3
7
  * Add a todo list
data/README.md CHANGED
@@ -14,15 +14,17 @@ It comes with two builtin strategies based on the very good gems [writeexcel](ht
14
14
 
15
15
  In your config/environment.rb
16
16
 
17
- config.gem 'rails-excel'
18
-
17
+ ```ruby
18
+ config.gem 'rails-excel'
19
+ ```
19
20
 
20
21
  Create an initializer : config/initializers/excel.rb
21
22
 
22
- Rails::Excel.configure do |config|
23
- config.strategy = :spreadsheet # by default or :write_excel
24
- end
25
-
23
+ ```ruby
24
+ Rails::Excel.configure do |config|
25
+ config.strategy = :spreadsheet # by default or :write_excel
26
+ end
27
+ ```
26
28
 
27
29
  If you wan tot implement your own strategy, here are the requirements :
28
30
 
@@ -33,60 +35,66 @@ If you wan tot implement your own strategy, here are the requirements :
33
35
 
34
36
  Example extracted from code source:
35
37
 
36
- # lib/my_strategy.rb
38
+ ```ruby
39
+ # lib/my_strategy.rb
37
40
 
38
- class MyStrategy
39
- def compile(io, &block)
40
- workbook = ::Spreadsheet::Workbook.new
41
- yield(workbook)
42
- workbook.write(io)
43
- end
44
- end
41
+ class MyStrategy
42
+ def compile(io, &block)
43
+ workbook = ::Spreadsheet::Workbook.new
44
+ yield(workbook)
45
+ workbook.write(io)
46
+ end
47
+ end
48
+ ```
45
49
 
46
50
  Then in your config/initializers/excel.rb
47
51
 
48
-
49
- require 'my_strategy'
50
- Rails::Excel.configure do |config|
51
- config.add_strategy :my_strategy, MyStrategy.new
52
- # Redefining default strategy
53
- config.strategy = :my_strategy # by default it was :spreadsheet
54
- end
52
+ ```ruby
53
+ require 'my_strategy'
54
+ Rails::Excel.configure do |config|
55
+ config.add_strategy :my_strategy, MyStrategy.new
56
+ # Redefining default strategy
57
+ config.strategy = :my_strategy # by default it was :spreadsheet
58
+ end
59
+ ```
55
60
 
56
61
  You can use any object as long as it responds to described `compile` method
57
62
 
58
-
59
63
  The strategy defined in the initializer will be used in all of your controllers
60
64
 
61
65
  To use another strategy you can set it by controller :
62
66
 
63
- class UsersController < ApplicationController
64
- self.excel_strategy = :write_excel
65
- end
66
-
67
+ ```ruby
68
+ class UsersController < ApplicationController
69
+ self.excel_strategy = :write_excel
70
+ end
71
+ ```
67
72
 
68
73
  Or you can set strategy per action by redefining instance method excel_strategy
69
74
 
70
- class UsersController < ApplicationController
71
-
72
- self.excel_strategy = :write_excel
73
-
74
- def index
75
- # ...
76
- end
77
-
78
- def show
79
- # ...
80
- end
75
+ ```ruby
76
+ class UsersController < ApplicationController
77
+ self.excel_strategy = :write_excel
78
+ def index
79
+ # ...
80
+ end
81
+
82
+ def show
83
+ # ...
84
+ end
85
+
86
+ protected
87
+ def excel_strategy
88
+ case action_name
89
+ when 'index'
90
+ :spreadsheet
91
+ else
92
+ self.class.excel_strategy
93
+ end
94
+ end
95
+ end
96
+ ```
81
97
 
82
- protected
83
- def excel_strategy
84
- case action_name
85
- when 'index'
86
- :spreadsheet
87
- else
88
- self.class.excel_strategy
89
- end
90
- end
98
+ # Contributors
91
99
 
92
- end
100
+ * [edpaget](https://github.com/edpaget)
@@ -15,7 +15,7 @@ module Rails
15
15
  class << self
16
16
  module_eval do
17
17
 
18
- attr_accessor_with_default :strategy, :spreadsheet
18
+ attr_accessor :strategy
19
19
  attr_reader :available_strategies
20
20
 
21
21
  def add_strategy(name, instance)
@@ -2,18 +2,20 @@ require 'action_controller'
2
2
  require 'action_view'
3
3
  module Rails
4
4
  module Excel
5
- class TemplateHandler < ::ActionView::TemplateHandler
6
- include ::ActionView::TemplateHandlers::Compilable
5
+ class TemplateHandler
7
6
 
7
+ def self.call(template, *args)
8
+ new.compile(template)
9
+ end
10
+
8
11
  def compile(template)
9
12
  %Q{
10
- _set_controller_content_type(Mime::XLS);
11
13
  io = StringIO.new
12
14
  Rails::Excel.available_strategies[self.excel_strategy].compile(io) do |workbook|
13
15
  #{template.source}
14
16
  end
15
17
  self.output_buffer = io.string
16
- }
18
+ }
17
19
  end
18
20
 
19
21
  end
@@ -1,5 +1,5 @@
1
1
  module Rails
2
2
  module Excel
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-excel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ramihajamalala Hery
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-23 00:00:00 +02:00
18
+ date: 2011-09-26 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency