bldr 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .rspec
2
2
  Gemfile.lock
3
+ pkg
data/HISTORY.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.1.2 (2011-09-08)
2
+
3
+ * Return an empty collection when a nil value is passed to `collection` method
data/README.md CHANGED
@@ -49,7 +49,7 @@ render templates.
49
49
  get "/posts" do
50
50
  # ...
51
51
  posts = Post.all
52
- bldr :'template.json', {}, {:posts => posts}
52
+ bldr :'template.json', :locals => {:posts => posts}
53
53
  end
54
54
 
55
55
  # views/template.json.bldr
data/lib/bldr/node.rb CHANGED
@@ -90,7 +90,12 @@ module Bldr
90
90
  key = items.keys.first
91
91
  values = items.values.to_a.first
92
92
 
93
- merge_result! key, values.map{|item| Node.new(item, :parent => self, &block).render!}
93
+ vals = if values
94
+ values.map{|item| Node.new(item, :parent => self, &block).render!}
95
+ else
96
+ []
97
+ end
98
+ merge_result! key, vals
94
99
 
95
100
  self.to_json
96
101
  end
data/lib/bldr/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Bldr
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
@@ -192,6 +192,7 @@ describe "Node#collection" do
192
192
  }
193
193
  end
194
194
 
195
+ # @todo fix this
195
196
  it "renders properly when a collection is the root node" do
196
197
  nodes = node_wrap do
197
198
  collection :people => [Person.new('bert'), Person.new('ernie')] do
@@ -202,6 +203,26 @@ describe "Node#collection" do
202
203
  nodes.render!.should == {:people => [{:name => 'bert'}, {:name => 'ernie'}]}
203
204
  end
204
205
 
206
+ it "gracefully handles empty collections" do
207
+ nodes = node_wrap do
208
+ collection :people => [] do
209
+ attributes :name
210
+ end
211
+ end
212
+
213
+ nodes.render!.should == {:people => []}
214
+ end
215
+
216
+ it "gracefully handles nil collections" do
217
+ nodes = node_wrap do
218
+ collection :people => nil do
219
+ attributes :name
220
+ end
221
+ end
222
+
223
+ nodes.render!.should == {:people => []}
224
+ end
225
+
205
226
  it "renders nested collections properly" do
206
227
  post = Post.new("my post")
207
228
  post.comments << Comment.new('my comment')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bldr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-09-07 00:00:00.000000000Z
12
+ date: 2011-09-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
16
- requirement: &2153792500 !ruby/object:Gem::Requirement
16
+ requirement: &2156406360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153792500
24
+ version_requirements: *2156406360
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json_pure
27
- requirement: &2153792080 !ruby/object:Gem::Requirement
27
+ requirement: &2152301980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2153792080
35
+ version_requirements: *2152301980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sinatra
38
- requirement: &2153791540 !ruby/object:Gem::Requirement
38
+ requirement: &2152301440 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.2.6
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2153791540
46
+ version_requirements: *2152301440
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: tilt
49
- requirement: &2153791040 !ruby/object:Gem::Requirement
49
+ requirement: &2152300940 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.3.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2153791040
57
+ version_requirements: *2152300940
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yajl-ruby
60
- requirement: &2153790660 !ruby/object:Gem::Requirement
60
+ requirement: &2152300560 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2153790660
68
+ version_requirements: *2152300560
69
69
  description: Provides a simple and intuitive templating DSL for serializing objects
70
70
  to JSON.
71
71
  email:
@@ -78,6 +78,7 @@ files:
78
78
  - .rvmrc
79
79
  - .travis.yml
80
80
  - Gemfile
81
+ - HISTORY.md
81
82
  - MIT-LICENSE
82
83
  - README.md
83
84
  - Rakefile