jbuilder 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Njk5MjUxMDExMjc4YWZkZGY3ODM0MWFhY2FhYTE0MWUyNTE2YjdjNg==
5
- data.tar.gz: !binary |-
6
- YjViMzY4ZmE2ZTVmNGVmZGNiZjM1N2JiOGZlN2NlNjgxYTA3YzIxNg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YjRjMDgyNWI1OGU2ZGFjZGZiMWRjZmYyOWZkYzI2N2NhY2MzOWY1MjYwNjM4
10
- ZGMzNzBlN2RlYjM0MWZhMjdlZGZhODJhZDIyYTA3MjQ0YjVhYjY2YTY2NjY5
11
- MTA3N2RkZDE3NTRlOGQxMzIyZTQ0Mzg1M2NlNDNmYWQwYzY0NDI=
12
- data.tar.gz: !binary |-
13
- YThmNWY1NDU5MmUwMTY0MTgzMDNlYWIyZDI2ODI4MWM2YTJkOWRjZjg1Yzky
14
- YWRlYmUxZGVlZmVkMGQxMjJkZGMzNjlkNmIxNmMzYTA0NzVjYzgwNmY2ZDE5
15
- NmY2NmIyNjI3ODJlN2EwMGVjNjhjYjM2YTMyMjIzZDhlNWZiMWU=
2
+ SHA1:
3
+ metadata.gz: 158b02263bd156e812d95710565da2a08996111a
4
+ data.tar.gz: 83c5430a9382a9a074d0fcca66999b605f18bd22
5
+ SHA512:
6
+ metadata.gz: 6d1cbb500554eb7367065d90c36034324ce4234f7bb3cb6642f5d76afde7f123ac5101adb511f89d82c072864cd96b1d2aafb3906b8b7af4c7efab6568f2c005
7
+ data.tar.gz: b60816efa65a497f3841f6d6e677461307e04873d2b23acbf2be274a9027c938a73414c73155292b1b945346cbe4b879326ed4d944eeebe4e35123bbc1f579eb
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
1
  tmp
2
2
  Gemfile.lock
3
- Gemfile.edge.lock
3
+ Gemfile.old.lock
4
4
  .ruby-version
@@ -13,21 +13,21 @@ rvm:
13
13
  - rbx-19mode
14
14
 
15
15
  gemfile:
16
+ - Gemfile.old
16
17
  - Gemfile
17
- - Gemfile.edge
18
18
 
19
19
  matrix:
20
20
  exclude:
21
21
  # Edge Rails is only compatible with 1.9.3+
22
- - gemfile: Gemfile.edge
22
+ - gemfile: Gemfile
23
23
  rvm: 1.8.7
24
- - gemfile: Gemfile.edge
24
+ - gemfile: Gemfile
25
25
  rvm: 1.9.2
26
- - gemfile: Gemfile.edge
26
+ - gemfile: Gemfile
27
27
  rvm: ree
28
- - gemfile: Gemfile.edge
28
+ - gemfile: Gemfile
29
29
  rvm: jruby-18mode
30
- - gemfile: Gemfile.edge
30
+ - gemfile: Gemfile
31
31
  rvm: rbx-18mode
32
32
  allow_failures:
33
33
  - rvm: ruby-head
data/Gemfile CHANGED
@@ -3,5 +3,6 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  gem 'rake'
6
- gem 'mocha', :require => false
7
- gem 'actionpack', '~> 3.0'
6
+ gem 'railties', '~> 4.0.0'
7
+ gem 'actionpack', '~> 4.0.0'
8
+ gem 'mocha', require: false
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+ gem 'mocha', :require => false
7
+ gem 'actionpack', '~> 3.0'
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 David Heinemeier Hansson, 37signals
1
+ Copyright (c) 2011-2013 David Heinemeier Hansson, 37signals
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jbuilder'
3
- s.version = '1.5.1'
3
+ s.version = '1.5.2'
4
4
  s.author = 'David Heinemeier Hansson'
5
5
  s.email = 'david@37signals.com'
6
6
  s.summary = 'Create JSON structures via a Builder-style DSL'
@@ -62,7 +62,7 @@ class Jbuilder < JbuilderProxy
62
62
  @attributes = ::ActiveSupport::OrderedHash.new
63
63
 
64
64
  options = args.extract_options!
65
- @key_formatter = options.fetch(:key_formatter, @@key_formatter.clone)
65
+ @key_formatter = options.fetch(:key_formatter){ @@key_formatter.clone }
66
66
  @ignore_nil = options.fetch(:ignore_nil, @@ignore_nil)
67
67
  yield self if block
68
68
  end
@@ -92,7 +92,7 @@ class Jbuilder < JbuilderProxy
92
92
  # { "age": 32 }
93
93
  value
94
94
  end
95
- elsif value.respond_to?(:map)
95
+ elsif _mapable_arguments?(value, *args)
96
96
  # json.comments @post.comments, :content, :created_at
97
97
  # { "comments": [ { "content": "hello", "created_at": "..." }, { "content": "world", "created_at": "..." } ] }
98
98
  _scope{ array! value, *args }
@@ -125,7 +125,7 @@ class Jbuilder < JbuilderProxy
125
125
  #
126
126
  # You can pass parameters to the method using a hash pair.
127
127
  #
128
- # json.key_format! :camelize => :lower
128
+ # json.key_format! camelize: :lower
129
129
  # json.first_name "David"
130
130
  #
131
131
  # { "firstName": "David" }
@@ -221,7 +221,7 @@ class Jbuilder < JbuilderProxy
221
221
  # json.array! [1, 2, 3]
222
222
  #
223
223
  # [1,2,3]
224
- def array!(collection, *attributes, &block)
224
+ def array!(collection = [], *attributes, &block)
225
225
  @attributes = if block && block.arity == 2
226
226
  _two_arguments_map_collection(collection, &block)
227
227
  elsif block
@@ -237,17 +237,17 @@ class Jbuilder < JbuilderProxy
237
237
  #
238
238
  # Example:
239
239
  #
240
- # @person = Struct.new(:name, :age).new("David", 32)
240
+ # @person = Struct.new(:name, :age).new('David', 32)
241
241
  #
242
242
  # or you can utilize a Hash
243
243
  #
244
- # @person = {:name => "David", :age => 32}
244
+ # @person = { name: 'David', age: 32 }
245
245
  #
246
246
  # json.extract! @person, :name, :age
247
247
  #
248
248
  # { "name": David", "age": 32 }, { "name": Jamie", "age": 31 }
249
249
  #
250
- # If you are using Ruby 1.9+, you can use the call syntax instead of an explicit extract! call:
250
+ # You can also use the call syntax instead of an explicit extract! call:
251
251
  #
252
252
  # json.(@person, :name, :age)
253
253
  def extract!(object, *attributes)
@@ -349,6 +349,10 @@ class Jbuilder < JbuilderProxy
349
349
 
350
350
  _map_collection(collection){ |element| block[self, element] }
351
351
  end
352
+
353
+ def _mapable_arguments?(value, *args)
354
+ value.respond_to?(:map)
355
+ end
352
356
  end
353
357
 
354
358
  require 'jbuilder/jbuilder_template' if defined?(ActionView::Template)
@@ -22,13 +22,15 @@ class JbuilderTemplate < Jbuilder
22
22
  options = { :partial => name_or_options, :locals => locals }
23
23
  as = locals.delete(:as)
24
24
  options[:as] = as if as.present?
25
- options[:collection] = locals[:collection]
25
+ options[:collection] = locals[:collection] if locals.key?(:collection)
26
26
  end
27
27
 
28
+ options[:collection] ||= [] if options.key?(:collection)
29
+
28
30
  _handle_partial_options options
29
31
  end
30
32
 
31
- def array!(collection, *attributes, &block)
33
+ def array!(collection = [], *attributes, &block)
32
34
  options = attributes.extract_options!
33
35
 
34
36
  if options.key?(:partial)
@@ -43,7 +45,7 @@ class JbuilderTemplate < Jbuilder
43
45
  #
44
46
  # Example:
45
47
  #
46
- # json.cache! ['v1', @person], :expires_in => 10.minutes do
48
+ # json.cache! ['v1', @person], expires_in: 10.minutes do
47
49
  # json.extract! @person, :name, :age
48
50
  # end
49
51
  def cache!(key=nil, options={}, &block)
@@ -92,6 +94,14 @@ class JbuilderTemplate < Jbuilder
92
94
  ::ActiveSupport::Cache.expand_cache_key(key.is_a?(::Hash) ? url_for(key).split('://').last : key, :jbuilder)
93
95
  end
94
96
  end
97
+
98
+ private
99
+
100
+ def _mapable_arguments?(value, *args)
101
+ return true if super
102
+ options = args.last
103
+ ::Hash === options && options.key?(:as)
104
+ end
95
105
  end
96
106
 
97
107
  class JbuilderHandler
@@ -105,4 +115,4 @@ class JbuilderHandler
105
115
  end
106
116
  end
107
117
 
108
- ActionView::Template.register_template_handler :jbuilder, JbuilderHandler
118
+ ActionView::Template.register_template_handler :jbuilder, JbuilderHandler
@@ -110,6 +110,14 @@ class JbuilderTemplateTest < ActionView::TestCase
110
110
  assert_collection_rendered json
111
111
  end
112
112
 
113
+ test 'partial! renders as empty array for nil-collection' do
114
+ json = render_jbuilder <<-JBUILDER
115
+ json.partial! 'blog_post', :collection => nil, :as => :blog_post
116
+ JBUILDER
117
+
118
+ assert_equal '[]', json
119
+ end
120
+
113
121
  test 'partial! renders collection (alt. syntax)' do
114
122
  json = render_jbuilder <<-JBUILDER
115
123
  json.partial! :partial => 'blog_post', :collection => BLOG_POST_COLLECTION, :as => :blog_post
@@ -118,6 +126,14 @@ class JbuilderTemplateTest < ActionView::TestCase
118
126
  assert_collection_rendered json
119
127
  end
120
128
 
129
+ test 'partial! renders as empty array for nil-collection (alt. syntax)' do
130
+ json = render_jbuilder <<-JBUILDER
131
+ json.partial! :partial => 'blog_post', :collection => nil, :as => :blog_post
132
+ JBUILDER
133
+
134
+ assert_equal '[]', json
135
+ end
136
+
121
137
  test 'render array of partials' do
122
138
  json = render_jbuilder <<-JBUILDER
123
139
  json.array! BLOG_POST_COLLECTION, :partial => 'blog_post', :as => :blog_post
@@ -126,6 +142,14 @@ class JbuilderTemplateTest < ActionView::TestCase
126
142
  assert_collection_rendered json
127
143
  end
128
144
 
145
+ test 'render array of partials as empty array with nil-collection' do
146
+ json = render_jbuilder <<-JBUILDER
147
+ json.array! nil, :partial => 'blog_post', :as => :blog_post
148
+ JBUILDER
149
+
150
+ assert_equal '[]', json
151
+ end
152
+
129
153
  test 'render array if partials as a value' do
130
154
  json = render_jbuilder <<-JBUILDER
131
155
  json.posts BLOG_POST_COLLECTION, :partial => 'blog_post', :as => :blog_post
@@ -134,6 +158,14 @@ class JbuilderTemplateTest < ActionView::TestCase
134
158
  assert_collection_rendered json, 'posts'
135
159
  end
136
160
 
161
+ test 'render as empty array if partials as a nil value' do
162
+ json = render_jbuilder <<-JBUILDER
163
+ json.posts nil, :partial => 'blog_post', :as => :blog_post
164
+ JBUILDER
165
+
166
+ assert_equal '{"posts":[]}', json
167
+ end
168
+
137
169
  test 'fragment caching a JSON object' do
138
170
  undef_context_methods :fragment_name_with_digest, :cache_fragment_name
139
171
 
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-24 00:00:00.000000000 Z
11
+ date: 2013-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: activesupport
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - ! '>='
17
+ - - '>='
17
18
  - !ruby/object:Gem::Version
18
19
  version: 3.0.0
19
20
  type: :runtime
20
21
  prerelease: false
21
- name: activesupport
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.0.0
27
27
  - !ruby/object:Gem::Dependency
28
+ name: multi_json
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: 1.2.0
33
34
  type: :runtime
34
35
  prerelease: false
35
- name: multi_json
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.2.0
41
41
  description:
@@ -47,7 +47,7 @@ files:
47
47
  - .gitignore
48
48
  - .travis.yml
49
49
  - Gemfile
50
- - Gemfile.edge
50
+ - Gemfile.old
51
51
  - MIT-LICENSE
52
52
  - README.md
53
53
  - Rakefile
@@ -74,17 +74,17 @@ require_paths:
74
74
  - lib
75
75
  required_ruby_version: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - ! '>='
77
+ - - '>='
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ! '>='
82
+ - - '>='
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubyforge_project:
87
- rubygems_version: 2.0.6
87
+ rubygems_version: 2.1.5
88
88
  signing_key:
89
89
  specification_version: 4
90
90
  summary: Create JSON structures via a Builder-style DSL
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'rake'
6
- gem 'railties', '~> 4.0.0'
7
- gem 'actionpack', '~> 4.0.0'
8
- gem 'mocha', require: false