jbuilder 2.2.8 → 2.2.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6fff76c0587398f3f158d2263ddb193fd0781fe
4
- data.tar.gz: 3c1f56012c79d825f11fda61fcfd9bdaa61abdd4
3
+ metadata.gz: 65e2e51bfcf3cf17786986d6dc8826b0b0436955
4
+ data.tar.gz: 23739f1c015a50a27239b0f96bb2f8d811f3ff59
5
5
  SHA512:
6
- metadata.gz: 8965ab307c6d4f8a0e1f5ad3774273bc0954e82603db9951fcb48ccddffef5ccf0cc90955f2827cd778d951d2f8d76c4fe0ab2e0c9a36c86d3ae6aa2fa42d81d
7
- data.tar.gz: bea36a97b8097ca854c8b9d07a463d1d4dd03d89799d995dcc4909c9f458cd57bb85406820d69f7311b8902e24aa530e16d2abd63a1bc265ba16d7f65257ceab
6
+ metadata.gz: d37cb2048c0c0c5ff27f4fe5a0e9d868766bd8b96317686a98da3aea45ab7365bc98390d185072ee359da7b44281b3ab42f206f4d9ff3ee2ffabef8b4ebd5e02
7
+ data.tar.gz: 14e3be5081174e64616bbbd189bd42fef0ddaacdfcdba260672b763224a52ece1adf3190a6feaf1b95074ddc4f1072009c186162ef2c4f00d21f6581954351ec
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ 2.2.9
4
+ -----
5
+
6
+ * Support `partial!` call with `locals` option in `JbuilderTemplate` [#251](https://github.com/rails/jbuilder/pull/251)
7
+
3
8
  2.2.8
4
9
  -----
5
10
  * [Raise ArrayError when trying to add key to an array](https://github.com/rails/jbuilder/commit/869e4be1ad165ce986d8fca78311bdd3ed166087)
data/README.md CHANGED
@@ -181,6 +181,17 @@ json.partial! partial: 'posts/post', collection: @posts, as: :post
181
181
  json.comments @post.comments, partial: 'comment/comment', as: :comment
182
182
  ```
183
183
 
184
+ You can pass any objects into partial templates with or without `:locals` option.
185
+
186
+ ```ruby
187
+ json.partial! 'sub_template', locals: { user: user }
188
+
189
+ # or
190
+
191
+ json.partial! 'sub_template', user: user
192
+ ```
193
+
194
+
184
195
  You can explicitly make Jbuilder object return null if you want:
185
196
 
186
197
  ``` ruby
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jbuilder'
3
- s.version = '2.2.8'
3
+ s.version = '2.2.9'
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'
@@ -17,11 +17,16 @@ class JbuilderTemplate < Jbuilder
17
17
  def partial!(name_or_options, locals = {})
18
18
  case name_or_options
19
19
  when ::Hash
20
- # partial! partial: 'name', locals: { foo: 'bar' }
20
+ # partial! partial: 'name', foo: 'bar'
21
21
  options = name_or_options
22
22
  else
23
+ # partial! 'name', locals: {foo: 'bar'}
24
+ if locals.one? && (locals.keys.first == :locals)
25
+ options = locals.merge(partial: name_or_options)
26
+ else
27
+ options = { partial: name_or_options, locals: locals }
28
+ end
23
29
  # partial! 'name', foo: 'bar'
24
- options = { partial: name_or_options, locals: locals }
25
30
  as = locals.delete(:as)
26
31
  options[:as] = as if as.present?
27
32
  options[:collection] = locals[:collection] if locals.key?(:collection)
@@ -40,7 +40,7 @@ class JbuilderTemplateTest < ActionView::TestCase
40
40
 
41
41
  def partials
42
42
  {
43
- '_partial.json.jbuilder' => 'json.content "hello"',
43
+ '_partial.json.jbuilder' => 'foo ||= "hello"; json.content foo',
44
44
  '_blog_post.json.jbuilder' => BLOG_POST_PARTIAL,
45
45
  '_collection.json.jbuilder' => COLLECTION_PARTIAL
46
46
  }
@@ -110,6 +110,22 @@ class JbuilderTemplateTest < ActionView::TestCase
110
110
  assert_equal 'hello', MultiJson.load(json)['content']
111
111
  end
112
112
 
113
+ test 'partial! + locals via :locals option' do
114
+ json = render_jbuilder <<-JBUILDER
115
+ json.partial! 'partial', locals: { foo: 'howdy' }
116
+ JBUILDER
117
+
118
+ assert_equal 'howdy', MultiJson.load(json)['content']
119
+ end
120
+
121
+ test 'partial! + locals without :locals key' do
122
+ json = render_jbuilder <<-JBUILDER
123
+ json.partial! 'partial', foo: 'goodbye'
124
+ JBUILDER
125
+
126
+ assert_equal 'goodbye', MultiJson.load(json)['content']
127
+ end
128
+
113
129
  test 'partial! renders collections' do
114
130
  json = render_jbuilder <<-JBUILDER
115
131
  json.partial! 'blog_post', :collection => BLOG_POST_COLLECTION, :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.2.8
4
+ version: 2.2.9
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: 2015-02-22 00:00:00.000000000 Z
12
+ date: 2015-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport