fume 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,8 @@
1
1
 
2
2
 
3
- ## 0.7.0:
3
+ ## 0.7.x:
4
4
  - add action_attr_accessor method
5
5
  - depend rails_i18n
6
6
  - rename simple\_theme to simple_nav and rewirte
7
- - auto require config/application.*.rb
7
+ - auto require config/application.*.rb
8
+ - add render cache feature
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.1
@@ -15,4 +15,5 @@ module Fume
15
15
  autoload :Cancan
16
16
  autoload :SimpleNav
17
17
  autoload :AppSettingLoader
18
+ autoload :RenderCache
18
19
  end
@@ -4,6 +4,20 @@ module Fume
4
4
  if defined? ::ActionController
5
5
  ActionController::Base.send :include, ControllerExtensions
6
6
  end
7
+
8
+ if defined? ::ActiveRecord
9
+ ::ActiveRecord::Base.send :include, ActiveRecordExtensions
10
+ end
11
+ end
12
+
13
+ module ActiveRecordExtensions
14
+ extend ActiveSupport::Concern
15
+
16
+ module ClassMethods
17
+ def last_updated_at
18
+ self.reorder("").select("MAX(#{self.table_name}.updated_at) AS updated_at").first.try(:updated_at)
19
+ end
20
+ end
7
21
  end
8
22
 
9
23
  module ControllerExtensions
@@ -0,0 +1,87 @@
1
+ module Fume
2
+ module RenderCache
3
+
4
+ def self.try_enable(app)
5
+ if defined? ::ActionController
6
+ ActionController::Base.send :include, ControllerExtensions
7
+ end
8
+ end
9
+
10
+ module ControllerExtensions
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ attr_accessor :render_cache_params
15
+ around_filter RenderCacheFilter.new
16
+ end
17
+
18
+ module InstanceMethods
19
+ protected
20
+ def render_cache_by_scope(scope, options = {}, &block)
21
+ last_updated_at = scope.last_updated_at
22
+ sql = scope.to_sql
23
+ key = { :sql => sql, :last_updated_at => last_updated_at }
24
+ render_cache(key, options, &block)
25
+ end
26
+
27
+ def render_cache(key, options = {})
28
+ key = build_render_cache_key(key)
29
+ cache = Rails.cache
30
+
31
+ fragment = cache.read(key)
32
+ if fragment
33
+ response.charset = fragment[:charset]
34
+ response.content_type = fragment[:content_type]
35
+ self.response_body = fragment[:body].html_safe
36
+ else
37
+ yield if block_given?
38
+
39
+ self.render_cache_params = {
40
+ :key => key,
41
+ :options => options,
42
+ :cache => cache
43
+ }
44
+ end
45
+ end
46
+
47
+ def build_render_cache_key(key)
48
+ base = "render@#{params[:controller]}/#{params[:action]}.#{params[:format]}"
49
+ key = self.key_to_string(key)
50
+ "#{base}##{key}"
51
+ end
52
+
53
+ def key_to_string(obj)
54
+ case obj
55
+ when nil
56
+ "nil!"
57
+ when Hash
58
+ obj.keys.sort.map { |k| "#{k}=#{self.key_to_string(obj[k])}" }.join("&")
59
+ when Array
60
+ obj.map { |val| self.key_to_string(val) }.join(",")
61
+ when Time, Date
62
+ obj.to_s(:db)
63
+ else
64
+ obj.to_s
65
+ end
66
+ end
67
+
68
+ end
69
+ end
70
+
71
+ class RenderCacheFilter
72
+ def filter(controller)
73
+ yield
74
+ params = controller.render_cache_params || {}
75
+ if params[:key]
76
+ content = {
77
+ :charset => controller.response.charset,
78
+ :content_type => controller.response.content_type,
79
+ :body => controller.response_body.is_a?(Array) ? controller.response_body.join : controller.response_body
80
+ }
81
+ params[:cache].write(params[:key], content, params[:options])
82
+ end
83
+ end
84
+ end
85
+
86
+ end
87
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fume
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-30 00:00:00.000000000Z
12
+ date: 2011-09-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70181391275120 !ruby/object:Gem::Requirement
16
+ requirement: &70271197396620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.10
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70181391275120
24
+ version_requirements: *70271197396620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails-i18n
27
- requirement: &70181391270320 !ruby/object:Gem::Requirement
27
+ requirement: &70271197395640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.1.6
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70181391270320
35
+ version_requirements: *70271197395640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hashie
38
- requirement: &70181391269700 !ruby/object:Gem::Requirement
38
+ requirement: &70271197393760 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.1.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70181391269700
46
+ version_requirements: *70271197393760
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: timeliness
49
- requirement: &70181391268960 !ruby/object:Gem::Requirement
49
+ requirement: &70271197391880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.3.4
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70181391268960
57
+ version_requirements: *70271197391880
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: addressable
60
- requirement: &70181391268400 !ruby/object:Gem::Requirement
60
+ requirement: &70271197389720 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.2.6
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70181391268400
68
+ version_requirements: *70271197389720
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: authlogic
71
- requirement: &70181391267740 !ruby/object:Gem::Requirement
71
+ requirement: &70271197386760 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 3.0.3
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70181391267740
79
+ version_requirements: *70271197386760
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: formtastic
82
- requirement: &70181391265980 !ruby/object:Gem::Requirement
82
+ requirement: &70271197384760 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.2.4
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70181391265980
90
+ version_requirements: *70271197384760
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: cancan
93
- requirement: &70181391265480 !ruby/object:Gem::Requirement
93
+ requirement: &70271197383460 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.6.5
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *70181391265480
101
+ version_requirements: *70271197383460
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: symbolize
104
- requirement: &70181391264680 !ruby/object:Gem::Requirement
104
+ requirement: &70271197381880 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 3.2.0
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *70181391264680
112
+ version_requirements: *70271197381880
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: meta_search
115
- requirement: &70181391264040 !ruby/object:Gem::Requirement
115
+ requirement: &70271197379900 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 1.0.6
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *70181391264040
123
+ version_requirements: *70271197379900
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: kaminari
126
- requirement: &70181391263380 !ruby/object:Gem::Requirement
126
+ requirement: &70271197376600 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ~>
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: 0.12.4
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *70181391263380
134
+ version_requirements: *70271197376600
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: version
137
- requirement: &70181391262860 !ruby/object:Gem::Requirement
137
+ requirement: &70271197372880 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70181391262860
145
+ version_requirements: *70271197372880
146
146
  description: a simple rails scaffold.
147
147
  email:
148
148
  - Sunteya@gmail.com
@@ -163,6 +163,7 @@ files:
163
163
  - lib/fume/cancan.rb
164
164
  - lib/fume/rails_ext.rb
165
165
  - lib/fume/railtie.rb
166
+ - lib/fume/render_cache.rb
166
167
  - lib/fume/simple_nav.rb
167
168
  - lib/generators/fume/simple_scaffold/USAGE
168
169
  - lib/generators/fume/simple_scaffold/simple_scaffold_generator.rb
@@ -192,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
193
  version: '0'
193
194
  segments:
194
195
  - 0
195
- hash: -3149688421727667146
196
+ hash: -1589464902967382455
196
197
  required_rubygems_version: !ruby/object:Gem::Requirement
197
198
  none: false
198
199
  requirements:
@@ -201,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
202
  version: '0'
202
203
  segments:
203
204
  - 0
204
- hash: -3149688421727667146
205
+ hash: -1589464902967382455
205
206
  requirements: []
206
207
  rubyforge_project:
207
208
  rubygems_version: 1.8.7