jbuilder 2.1.2 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -0
- data/jbuilder.gemspec +1 -1
- data/lib/jbuilder/jbuilder_template.rb +9 -7
- data/test/jbuilder_template_test.rb +15 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d5b664cede402d0f7c028a234e22a7bf1114274
|
4
|
+
data.tar.gz: d4e163e75dea9c02ecb14ce79f7dafda0b5f32f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88378366476f8fbaf94eecdc4e31be5bf000d605c9797c4c0a9b53ae3be63dc0f5c119e5cd349f42d1fa9459b69de9730d5dad2a2d7fd89e38cefe3808884cf7
|
7
|
+
data.tar.gz: 13134bb6ea6ff1df39592cfef8a3575f94e185864ebf629af38b8cd19911bdb9f6804eeaf87d5d2a256c1d482cec49cf93aa7b77094f2124a798f7fa959af048
|
data/Rakefile
CHANGED
data/jbuilder.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jbuilder'
|
3
|
-
s.version = '2.1.
|
3
|
+
s.version = '2.1.3'
|
4
4
|
s.authors = ['David Heinemeier Hansson', 'Pavel Pravosud']
|
5
5
|
s.email = ['david@37signals.com', 'pavel@pravosud.com']
|
6
6
|
s.summary = 'Create JSON structures via a Builder-style DSL'
|
@@ -27,7 +27,7 @@ class JbuilderTemplate < Jbuilder
|
|
27
27
|
options[:collection] = locals[:collection] if locals.key?(:collection)
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
_render_partial_with_options options
|
31
31
|
end
|
32
32
|
|
33
33
|
def array!(collection = [], *attributes, &block)
|
@@ -75,17 +75,19 @@ class JbuilderTemplate < Jbuilder
|
|
75
75
|
|
76
76
|
protected
|
77
77
|
|
78
|
-
def
|
78
|
+
def _render_partial_with_options(options)
|
79
79
|
options.reverse_merge! locals: {}
|
80
80
|
options.reverse_merge! ::JbuilderTemplate.template_lookup_options
|
81
81
|
as = options[:as]
|
82
82
|
|
83
83
|
if as && options.key?(:collection)
|
84
|
-
collection = options.delete(:collection)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
collection = options.delete(:collection)
|
85
|
+
locals = options.delete(:locals)
|
86
|
+
array! collection do |member|
|
87
|
+
member_locals = locals.clone
|
88
|
+
member_locals.merge! collection: collection
|
89
|
+
member_locals.merge! as => member
|
90
|
+
_render_partial options.merge(locals: member_locals)
|
89
91
|
end
|
90
92
|
else
|
91
93
|
_render_partial options
|
@@ -15,9 +15,15 @@ BLOG_POST_PARTIAL = <<-JBUILDER
|
|
15
15
|
end
|
16
16
|
JBUILDER
|
17
17
|
|
18
|
+
COLLECTION_PARTIAL = <<-JBUILDER
|
19
|
+
json.extract! collection, :id, :name
|
20
|
+
JBUILDER
|
21
|
+
|
18
22
|
BlogPost = Struct.new(:id, :body, :author_name)
|
23
|
+
Collection = Struct.new(:id, :name)
|
19
24
|
blog_authors = [ 'David Heinemeier Hansson', 'Pavel Pravosud' ].cycle
|
20
25
|
BLOG_POST_COLLECTION = 10.times.map{ |i| BlogPost.new(i+1, "post body #{i+1}", blog_authors.next) }
|
26
|
+
COLLECTION_COLLECTION = 5.times.map{ |i| Collection.new(i+1, "collection #{i+1}") }
|
21
27
|
|
22
28
|
module Rails
|
23
29
|
def self.cache
|
@@ -34,7 +40,8 @@ class JbuilderTemplateTest < ActionView::TestCase
|
|
34
40
|
def partials
|
35
41
|
{
|
36
42
|
'_partial.json.jbuilder' => 'json.content "hello"',
|
37
|
-
'_blog_post.json.jbuilder' => BLOG_POST_PARTIAL
|
43
|
+
'_blog_post.json.jbuilder' => BLOG_POST_PARTIAL,
|
44
|
+
'_collection.json.jbuilder' => COLLECTION_PARTIAL
|
38
45
|
}
|
39
46
|
end
|
40
47
|
|
@@ -47,7 +54,7 @@ class JbuilderTemplateTest < ActionView::TestCase
|
|
47
54
|
def undef_context_methods(*names)
|
48
55
|
self.class_eval do
|
49
56
|
names.each do |name|
|
50
|
-
undef_method name.to_sym if
|
57
|
+
undef_method name.to_sym if method_defined?(name.to_sym)
|
51
58
|
end
|
52
59
|
end
|
53
60
|
end
|
@@ -110,6 +117,12 @@ class JbuilderTemplateTest < ActionView::TestCase
|
|
110
117
|
assert_collection_rendered json
|
111
118
|
end
|
112
119
|
|
120
|
+
test 'partial! renders collections as collections' do
|
121
|
+
json = render_jbuilder <<-JBUILDER
|
122
|
+
json.partial! 'collection', collection: COLLECTION_COLLECTION, as: :collection
|
123
|
+
JBUILDER
|
124
|
+
end
|
125
|
+
|
113
126
|
test 'partial! renders as empty array for nil-collection' do
|
114
127
|
json = render_jbuilder <<-JBUILDER
|
115
128
|
json.partial! 'blog_post', :collection => nil, :as => :blog_post
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|