rabl 0.9.0.pre3 → 0.9.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWZkODhjODJlYzViMTk1Y2U1MTEyZjVhZjNjZmU3OWZlNjk3YTRmOA==
4
+ ZjA4NTM5ZDI5ZjQ3YTg5MGVjNjRiODY2YTM2OTRmZmI5OGM2NmRjZQ==
5
5
  data.tar.gz: !binary |-
6
- YjIwMzgzZjM4NGQ5Njk3NWJlZWQ0ZDY0ODNlNTZjY2UyODMzOWM2Yw==
6
+ NTM5MWM4MjRkOGExNTJkNDgzZWYyYzhmMjc5MTY3ODFjNDYxYTU1NA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjJiZDhjOTI4N2EwNTIyMTRkZDE5MTFlYTU2YjhlOTczOWJmYWViZjljMjY0
10
- ZWU3ZTFkOGQwMjFjY2Y1ZjlkOWZjM2Q1ZjAyZTM0ZjM1Yzk3YmI4OThhYTFm
11
- MWU5MjY0ODgxMzllNDEwZGM3OTY0NzNhNDE0OWE4ZThhZmE1NzQ=
9
+ MmFlODc5NjdkYzEyZGJhZDhkODQ2NTczNTFkZTk0ZTk0OGRlZGQ3NmNiYmI1
10
+ OTNhNjBkOTQxMDM5ZTM0ODJiMTY5NmE5MzZmY2M0NTBmZDhmMzc5NjY3MDUy
11
+ NDY2NDRjMDFkZjA2ZGIxMDNlM2NkNWVlMjBkZmYyMGNjNGQwNTU=
12
12
  data.tar.gz: !binary |-
13
- MmNhNjEyNDg2YjYzZGE0NWJmYzIyMjUxN2NkNDQ5NTBiZDZjOTlmZTA4NzRh
14
- NDI3ZGE3NzliNzMxYmQ3M2RhYzgwMDc1ZTMzYzI4N2YxZDY1YTY1OWVhMzQ5
15
- NTNmMmE3NTk4NWUyMGQ2YzQzYzJiMDg1YzY1MzliZDExNWI4NWY=
13
+ MGZhNjI0MjU5ZjU2OTljMjkxZGIyZTA5NzFjYTE3ODcyYWI5Yzk0YzIyZGZj
14
+ MTZkZjhkNjAyNmZmMWQ0ZWIzZGY5ZWVlM2U4MmUxMTM0M2FmYTJkNTQxYWUz
15
+ NTllOGZjZjZhZWI2Y2E1OGE4ZDliYzFiYWFiOTYzZTFjZGIyODk=
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.9.0.pre4 (Sept 24 2013)
4
+
5
+ * FIX #497 Renderer should support partial caching and a digestor bug fixed (Thanks @siong1987)
6
+
3
7
  ## 0.9.0.pre3 (Sept 22 2013)
4
8
 
5
9
  * FIX #495 Digest cache when rendering from controller (Thanks @siong1987)
@@ -2,3 +2,7 @@ object @post
2
2
  cache @post
3
3
 
4
4
  attributes :title, :body
5
+
6
+ node :partial do |p|
7
+ partial('posts/renderer_partial', object: p)
8
+ end
@@ -0,0 +1,4 @@
1
+ object @post
2
+ cache @post
3
+
4
+ attributes :title, :body
@@ -149,6 +149,10 @@ context "PostsController" do
149
149
  # Attributes (regular)
150
150
  asserts("contains post title") { topic['title'] }.equals { @post1.title }
151
151
  asserts("contains post body") { topic['body'] }.equals { @post1.body }
152
+
153
+ # Attributes (partial)
154
+ asserts("contains post partial title") { topic['partial']['title'] }.equals { @post1.title }
155
+ asserts("contains post partial body") { topic['partial']['body'] }.equals { @post1.body }
152
156
  end # renderer action, json
153
157
 
154
158
  context "for index action rendering JSON within HTML" do
@@ -149,6 +149,10 @@ context "PostsController" do
149
149
  # Attributes (regular)
150
150
  asserts("contains post title") { topic['title'] }.equals { @post1.title }
151
151
  asserts("contains post body") { topic['body'] }.equals { @post1.body }
152
+
153
+ # Attributes (partial)
154
+ asserts("contains post partial title") { topic['partial']['title'] }.equals { @post1.title }
155
+ asserts("contains post partial body") { topic['partial']['body'] }.equals { @post1.body }
152
156
  end # renderer action, json
153
157
 
154
158
  context "for index action rendering JSON within HTML" do
@@ -199,7 +203,7 @@ context "PostsController" do
199
203
 
200
204
  asserts("contains cache hits per object (posts by title)") do
201
205
  json_output['articles'].map { |o| o['article']['title'] }
202
- end.equals { @posts.map{ |p| cache_hit([p, nil, 'hash', 'e83f65eee5ffb454c418a59105f222c4'])[:title] } }
206
+ end.equals { @posts.map { |p| cache_hit([p, nil, 'hash', 'e373525f49a3b3b044af05255e84839d'])[:title] } }
203
207
  end # index action, caching, json
204
208
 
205
209
  context "for index action with caching in xml" do
data/lib/rabl/digestor.rb CHANGED
@@ -12,7 +12,7 @@ module Rabl
12
12
  private
13
13
  def dependency_digest
14
14
  template_digests = dependencies.collect do |template_name|
15
- Digestor.digest(template_name, format, finder, partial: true)
15
+ Digestor.digest(template_name, format, finder)
16
16
  end
17
17
 
18
18
  (template_digests + injected_dependencies).join("-")
data/lib/rabl/engine.rb CHANGED
@@ -287,11 +287,11 @@ module Rabl
287
287
  end
288
288
 
289
289
  def cache_key_with_digest(cache_key)
290
- virtual_path = @_virtual_path ? @_virtual_path : @virtual_path
290
+ template = @_options[:template] || @virtual_path
291
291
  Array(cache_key) + [
292
292
  @_options[:root_name],
293
293
  @_options[:format],
294
- Digestor.digest(virtual_path, :rabl, lookup_context, dependencies: view_cache_dependencies)
294
+ Digestor.digest(template, :rabl, lookup_context)
295
295
  ]
296
296
  end
297
297
 
data/lib/rabl/partials.rb CHANGED
@@ -10,7 +10,7 @@ module Rabl
10
10
  raise ArgumentError, "Must provide an :object option to render a partial" unless options.has_key?(:object)
11
11
  object, view_path = options.delete(:object), options[:view_path] || @_view_path
12
12
  source, location = self.fetch_source(file, :view_path => view_path)
13
- engine_options = options.merge(:source => source, :source_location => location)
13
+ engine_options = options.merge(:source => source, :source_location => location, :template => file)
14
14
  self.object_to_hash(object, engine_options, &block)
15
15
  end
16
16
 
@@ -43,16 +43,11 @@ module Rabl
43
43
  fetch_manual_template(view_paths, file)
44
44
  end
45
45
 
46
- # being used by cache digestor
47
- if defined?(Rails) && Rails.version =~ /^[4]/
48
- @_virtual_path = file_path.gsub('app/views/', '').gsub('.rabl', '')
49
- end
50
-
51
46
  unless File.exist?(file_path.to_s)
52
47
  raise "Cannot find rabl template '#{file}' within registered (#{view_paths.map(&:to_s).inspect}) view paths!"
53
48
  end
54
49
 
55
- [File.read(file_path.to_s), file_path.to_s] if file_path
50
+ [File.read(file_path.to_s), file_path.to_s]
56
51
  end
57
52
  end
58
53
 
data/lib/rabl/renderer.rb CHANGED
@@ -26,7 +26,8 @@ module Rabl
26
26
  options = {
27
27
  :format => :json,
28
28
  :scope => self,
29
- :view_path => []
29
+ :view_path => [],
30
+ :template => source
30
31
  }.update(options)
31
32
 
32
33
  @options = options
data/lib/rabl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rabl
2
- VERSION = "0.9.0.pre3"
2
+ VERSION = "0.9.0.pre4"
3
3
  end
data/test/engine_test.rb CHANGED
@@ -379,7 +379,7 @@ context "Rabl::Engine" do
379
379
  scope.instance_variable_set :@user, @user
380
380
  any_instance_of(Rabl::Engine) do |b|
381
381
  mock(b).fetch_source("foo/bar", :view_path => nil).once
382
- mock(b).object_to_hash(@user, :locals => { :foo => "bar" }, :source => nil, :source_location => nil).returns({ :name => 'leo', :city => 'LA', :age => 12 })
382
+ mock(b).object_to_hash(@user, :locals => { :foo => "bar" }, :source => nil, :source_location => nil, :template => 'foo/bar').returns({ :name => 'leo', :city => 'LA', :age => 12 })
383
383
  end
384
384
  JSON.parse(template.render(scope))
385
385
  end.equals JSON.parse("{ \"foo\" : {\"name\":\"leo\",\"city\":\"LA\",\"age\":12} }")
@@ -149,6 +149,10 @@ context "PostsController" do
149
149
  # Attributes (regular)
150
150
  asserts("contains post title") { topic['title'] }.equals { @post1.title }
151
151
  asserts("contains post body") { topic['body'] }.equals { @post1.body }
152
+
153
+ # Attributes (partial)
154
+ asserts("contains post partial title") { topic['partial']['title'] }.equals { @post1.title }
155
+ asserts("contains post partial body") { topic['partial']['body'] }.equals { @post1.body }
152
156
  end # renderer action, json
153
157
 
154
158
  context "for index action rendering JSON within HTML" do
@@ -149,6 +149,10 @@ context "PostsController" do
149
149
  # Attributes (regular)
150
150
  asserts("contains post title") { topic['title'] }.equals { @post1.title }
151
151
  asserts("contains post body") { topic['body'] }.equals { @post1.body }
152
+
153
+ # Attributes (partial)
154
+ asserts("contains post partial title") { topic['partial']['title'] }.equals { @post1.title }
155
+ asserts("contains post partial body") { topic['partial']['body'] }.equals { @post1.body }
152
156
  end # renderer action, json
153
157
 
154
158
  context "for index action rendering JSON within HTML" do
@@ -199,7 +203,7 @@ context "PostsController" do
199
203
 
200
204
  asserts("contains cache hits per object (posts by title)") do
201
205
  json_output['articles'].map { |o| o['article']['title'] }
202
- end.equals { @posts.map{ |p| cache_hit([p, nil, 'hash', 'e83f65eee5ffb454c418a59105f222c4'])[:title] } }
206
+ end.equals { @posts.map { |p| cache_hit([p, nil, 'hash', 'e373525f49a3b3b044af05255e84839d'])[:title] } }
203
207
  end # index action, caching, json
204
208
 
205
209
  context "for index action with caching in xml" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rabl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.pre3
4
+ version: 0.9.0.pre4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Esquenazi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-23 00:00:00.000000000 Z
11
+ date: 2013-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -178,6 +178,7 @@ files:
178
178
  - fixtures/ashared/views_rails_3/posts/index.html.erb
179
179
  - fixtures/ashared/views_rails_3/posts/index.rabl
180
180
  - fixtures/ashared/views_rails_3/posts/renderer.rabl
181
+ - fixtures/ashared/views_rails_3/posts/renderer_partial.rabl
181
182
  - fixtures/ashared/views_rails_3/posts/show.html.erb
182
183
  - fixtures/ashared/views_rails_3/posts/show.rabl
183
184
  - fixtures/ashared/views_rails_3/posts/show.rabl_test_v1.rabl