rabl 0.5.5.g → 0.5.5.h
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -5
- data/README.md +31 -2
- data/lib/rabl/configuration.rb +16 -0
- data/lib/rabl/engine.rb +9 -0
- data/lib/rabl/version.rb +1 -1
- data/rabl.gemspec +1 -0
- data/test/plist_engine_test.rb +332 -0
- metadata +15 -2
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 0.5.5.a-
|
3
|
+
## 0.5.5.a-h
|
4
4
|
|
5
5
|
* Change engine to only instantiate one builder when rendering a collection
|
6
6
|
* Alias to\_msgpack to to\_mpac
|
7
|
-
* Cache template sources for faster partial lookups (thanks cj)
|
8
|
-
* Adds BSON format support (thanks Antiarchitect)
|
9
|
-
* Use template lookup mechanism to find templates in Rails 3 (thanks blakewatters)
|
10
|
-
* Adds a 'object_root' option to collection (thanks blakewatters)
|
7
|
+
* Cache template sources for faster partial lookups (thanks @cj)
|
8
|
+
* Adds BSON format support (thanks @Antiarchitect)
|
9
|
+
* Use template lookup mechanism to find templates in Rails 3 (thanks @blakewatters)
|
10
|
+
* Adds a 'object_root' option to collection (thanks @blakewatters)
|
11
11
|
* Adds a 'root_name' option to collection
|
12
|
+
* Adds PList format support (thanks @alzeih)
|
12
13
|
|
13
14
|
## 0.5.4
|
14
15
|
|
data/README.md
CHANGED
@@ -102,9 +102,11 @@ Rabl.configure do |config|
|
|
102
102
|
# config.json_engine = nil # Any multi\_json engines
|
103
103
|
# config.msgpack_engine = nil # Defaults to ::MessagePack
|
104
104
|
# config.bson_engine = nil # Defaults to ::BSON
|
105
|
+
# config.plist_engine = nil # Defaults to ::Plist::Emit
|
105
106
|
# config.include_json_root = true
|
106
107
|
# config.include_msgpack_root = true
|
107
108
|
# config.include_bson_root = true
|
109
|
+
# config.include_plist_root = true
|
108
110
|
# config.include_xml_root = false
|
109
111
|
# config.enable_json_callbacks = false
|
110
112
|
# config.xml_options = { :dasherize => true, :skip_types => false }
|
@@ -191,6 +193,32 @@ end
|
|
191
193
|
*NOTE*: Attempting to render the bson format without either including the bson gem or
|
192
194
|
setting a `bson_engine` will cause an exception to be raised.
|
193
195
|
|
196
|
+
### Plist ###
|
197
|
+
|
198
|
+
Rabl also includes optional support for [Plist](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html]) serialization format using the [plist gem](http://plist.rubyforge.org/).
|
199
|
+
To enable, include the plist gem in your project's Gemfile. Then use Rabl as normal with the `plist` format (akin to other formats).
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
# Gemfile
|
203
|
+
gem 'plist'
|
204
|
+
```
|
205
|
+
|
206
|
+
There is also an option for a custom Plist implementation by setting the Rabl `plist_engine` configuration attribute.
|
207
|
+
|
208
|
+
```ruby
|
209
|
+
class CustomEncodeEngine
|
210
|
+
def self.dump string
|
211
|
+
# Custom Encoding by your own engine.
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
Rabl.configure do |config|
|
216
|
+
config.plist_engine = CustomEncodeEngine
|
217
|
+
end
|
218
|
+
```
|
219
|
+
|
220
|
+
*NOTE*: Attempting to render the plist format without either including the plist gem or setting a `plist_engine` will cause an exception to be raised.
|
221
|
+
|
194
222
|
## Usage ##
|
195
223
|
|
196
224
|
### Object Assignment ###
|
@@ -482,12 +510,13 @@ Thanks to [Miso](http://gomiso.com) for allowing me to create this for our appli
|
|
482
510
|
* [Matthew Schulkind](https://github.com/mschulkind) - Cleanup of configuration and tests
|
483
511
|
* [Luke van der Hoeven](https://github.com/plukevdh) - Support non-ORM objects in templates
|
484
512
|
* [Andrey Voronkov](https://github.com/Antiarchitect) - Added BSON format support
|
513
|
+
* [Alli Witheford](https://github.com/alzeih) - Added Plist format support
|
485
514
|
|
486
515
|
and many more contributors listed in the [CHANGELOG](https://github.com/nesquena/rabl/blob/master/CHANGELOG.md).
|
487
516
|
|
488
517
|
Want to contribute support for another format?
|
489
|
-
Check out the
|
490
|
-
[BSON support](https://github.com/nesquena/rabl/pull/163).
|
518
|
+
Check out the patches for [msgpack support](https://github.com/nesquena/rabl/pull/69), [plist support](https://github.com/nesquena/rabl/pull/153) and
|
519
|
+
[BSON support](https://github.com/nesquena/rabl/pull/163) for reference.
|
491
520
|
|
492
521
|
Please fork and contribute, any help in making this project better is appreciated!
|
493
522
|
|
data/lib/rabl/configuration.rb
CHANGED
@@ -10,6 +10,12 @@ begin
|
|
10
10
|
rescue LoadError
|
11
11
|
end
|
12
12
|
|
13
|
+
# We load the plist library if it is available.
|
14
|
+
begin
|
15
|
+
require 'plist'
|
16
|
+
rescue LoadError
|
17
|
+
end
|
18
|
+
|
13
19
|
# Load MultiJSON
|
14
20
|
require 'multi_json'
|
15
21
|
|
@@ -18,6 +24,7 @@ module Rabl
|
|
18
24
|
class Configuration
|
19
25
|
attr_accessor :include_json_root
|
20
26
|
attr_accessor :include_msgpack_root
|
27
|
+
attr_accessor :include_plist_root
|
21
28
|
attr_accessor :include_xml_root
|
22
29
|
attr_accessor :include_bson_root
|
23
30
|
attr_accessor :enable_json_callbacks
|
@@ -25,6 +32,7 @@ module Rabl
|
|
25
32
|
attr_accessor :bson_move_id
|
26
33
|
attr_writer :msgpack_engine
|
27
34
|
attr_writer :bson_engine
|
35
|
+
attr_writer :plist_engine
|
28
36
|
attr_writer :xml_options
|
29
37
|
attr_accessor :cache_sources
|
30
38
|
|
@@ -33,6 +41,7 @@ module Rabl
|
|
33
41
|
def initialize
|
34
42
|
@include_json_root = true
|
35
43
|
@include_msgpack_root = true
|
44
|
+
@include_plist_root = true
|
36
45
|
@include_xml_root = false
|
37
46
|
@include_bson_root = true
|
38
47
|
@enable_json_callbacks = false
|
@@ -41,6 +50,7 @@ module Rabl
|
|
41
50
|
@json_engine = nil
|
42
51
|
@msgpack_engine = nil
|
43
52
|
@bson_engine = nil
|
53
|
+
@plist_engine = nil
|
44
54
|
@xml_options = {}
|
45
55
|
@cache_sources = false
|
46
56
|
end
|
@@ -69,6 +79,12 @@ module Rabl
|
|
69
79
|
@bson_engine || ::BSON
|
70
80
|
end
|
71
81
|
|
82
|
+
##
|
83
|
+
# @return the Plist encoder/engine to use.
|
84
|
+
def plist_engine
|
85
|
+
@plist_engine || ::Plist::Emit
|
86
|
+
end
|
87
|
+
|
72
88
|
# Allows config options to be read like a hash
|
73
89
|
#
|
74
90
|
# @param [Symbol] option Key for a given attribute
|
data/lib/rabl/engine.rb
CHANGED
@@ -62,6 +62,15 @@ module Rabl
|
|
62
62
|
end
|
63
63
|
alias_method :to_mpac, :to_msgpack
|
64
64
|
|
65
|
+
# Returns a plist representation of the data object
|
66
|
+
# to_plist(:root => true)
|
67
|
+
def to_plist(options={})
|
68
|
+
include_root = Rabl.configuration.include_plist_root
|
69
|
+
options = options.reverse_merge(:root => include_root, :child_root => include_root)
|
70
|
+
result = defined?(@_collection_name) ? { @_collection_name => to_hash(options) } : to_hash(options)
|
71
|
+
Rabl.configuration.plist_engine.dump(result)
|
72
|
+
end
|
73
|
+
|
65
74
|
# Returns an xml representation of the data object
|
66
75
|
# to_xml(:root => true)
|
67
76
|
def to_xml(options={})
|
data/lib/rabl/version.rb
CHANGED
data/rabl.gemspec
CHANGED
@@ -0,0 +1,332 @@
|
|
1
|
+
require File.expand_path('../teststrap', __FILE__)
|
2
|
+
require File.expand_path('../../lib/rabl', __FILE__)
|
3
|
+
require File.expand_path('../../lib/rabl/template', __FILE__)
|
4
|
+
require File.expand_path('../models/user', __FILE__)
|
5
|
+
|
6
|
+
context "Rabl::Engine" do
|
7
|
+
|
8
|
+
helper(:rabl) { |t| RablTemplate.new("code", :format => 'plist') { t } }
|
9
|
+
|
10
|
+
context "with plist defaults" do
|
11
|
+
setup do
|
12
|
+
Rabl.configure do |config|
|
13
|
+
# Comment this line out because include_plist_root is default.
|
14
|
+
#config.include_plist_root = true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "#object" do
|
19
|
+
|
20
|
+
asserts "that it sets data source" do
|
21
|
+
template = rabl %q{
|
22
|
+
object @user
|
23
|
+
}
|
24
|
+
scope = Object.new
|
25
|
+
scope.instance_variable_set :@user, User.new
|
26
|
+
template.render(scope)
|
27
|
+
end.matches "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict/>\n</dict>\n</plist>\n"
|
28
|
+
|
29
|
+
asserts "that it can set root node" do
|
30
|
+
template = rabl %q{
|
31
|
+
object @user => :person
|
32
|
+
}
|
33
|
+
scope = Object.new
|
34
|
+
scope.instance_variable_set :@user, User.new
|
35
|
+
template.render(scope)
|
36
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>person</key>\n\t<dict/>\n</dict>\n</plist>\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
context "#collection" do
|
40
|
+
|
41
|
+
asserts "that it sets object to be casted as a simple array" do
|
42
|
+
template = rabl %{
|
43
|
+
collection @users
|
44
|
+
}
|
45
|
+
scope = Object.new
|
46
|
+
scope.instance_variable_set :@users, [User.new, User.new]
|
47
|
+
template.render(scope)
|
48
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<array>\n\t<dict>\n\t\t<key>user</key>\n\t\t<dict/>\n\t</dict>\n\t<dict>\n\t\t<key>user</key>\n\t\t<dict/>\n\t</dict>\n</array>\n</plist>\n"
|
49
|
+
|
50
|
+
asserts "that it sets root node for objects" do
|
51
|
+
template = rabl %{
|
52
|
+
collection @users => :person
|
53
|
+
}
|
54
|
+
scope = Object.new
|
55
|
+
scope.instance_variable_set :@users, [User.new, User.new]
|
56
|
+
template.render(scope)
|
57
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>person</key>\n\t<array>\n\t\t<dict>\n\t\t\t<key>person</key>\n\t\t\t<dict/>\n\t\t</dict>\n\t\t<dict>\n\t\t\t<key>person</key>\n\t\t\t<dict/>\n\t\t</dict>\n\t</array>\n</dict>\n</plist>\n"
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
context "#attribute" do
|
62
|
+
|
63
|
+
asserts "that it adds an attribute or method to be included in output" do
|
64
|
+
template = rabl %{
|
65
|
+
object @user
|
66
|
+
attribute :name
|
67
|
+
}
|
68
|
+
scope = Object.new
|
69
|
+
scope.instance_variable_set :@user, User.new(:name => 'irvine')
|
70
|
+
template.render(scope)
|
71
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>name</key>\n\t\t<string>irvine</string>\n\t</dict>\n</dict>\n</plist>\n"
|
72
|
+
|
73
|
+
asserts "that it can add attribute under a different key name through :as" do
|
74
|
+
template = rabl %{
|
75
|
+
object @user
|
76
|
+
attribute :name, :as => 'city'
|
77
|
+
}
|
78
|
+
scope = Object.new
|
79
|
+
scope.instance_variable_set :@user, User.new(:name => 'irvine')
|
80
|
+
template.render(scope)
|
81
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>city</key>\n\t\t<string>irvine</string>\n\t</dict>\n</dict>\n</plist>\n"
|
82
|
+
|
83
|
+
asserts "that it can add attribute under a different key name through hash" do
|
84
|
+
template = rabl %{
|
85
|
+
object @user
|
86
|
+
attribute :name => :city
|
87
|
+
}
|
88
|
+
scope = Object.new
|
89
|
+
scope.instance_variable_set :@user, User.new(:name => 'irvine')
|
90
|
+
template.render(scope)
|
91
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>city</key>\n\t\t<string>irvine</string>\n\t</dict>\n</dict>\n</plist>\n"
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
context "#code" do
|
96
|
+
|
97
|
+
asserts "that it can create an arbitraty code node" do
|
98
|
+
template = rabl %{
|
99
|
+
code(:foo) { 'bar' }
|
100
|
+
}
|
101
|
+
template.render(Object.new)
|
102
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>foo</key>\n\t<string>bar</string>\n</dict>\n</plist>\n"
|
103
|
+
|
104
|
+
asserts "that it can be passed conditionals" do
|
105
|
+
template = rabl %{
|
106
|
+
code(:foo, :if => lambda { |i| false }) { 'bar' }
|
107
|
+
}
|
108
|
+
template.render(Object.new)
|
109
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict/>\n</plist>\n"
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
context "#child" do
|
114
|
+
|
115
|
+
asserts "that it can create a child node" do
|
116
|
+
template = rabl %{
|
117
|
+
object @user
|
118
|
+
attribute :name
|
119
|
+
child(@user) { attribute :city }
|
120
|
+
}
|
121
|
+
scope = Object.new
|
122
|
+
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
|
123
|
+
template.render(scope)
|
124
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>name</key>\n\t\t<string>leo</string>\n\t\t<key>user</key>\n\t\t<dict>\n\t\t\t<key>city</key>\n\t\t\t<string>LA</string>\n\t\t</dict>\n\t</dict>\n</dict>\n</plist>\n"
|
125
|
+
|
126
|
+
asserts "that it can create a child node with different key" do
|
127
|
+
template = rabl %{
|
128
|
+
object @user
|
129
|
+
attribute :name
|
130
|
+
child(@user => :person) { attribute :city }
|
131
|
+
}
|
132
|
+
scope = Object.new
|
133
|
+
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
|
134
|
+
template.render(scope)
|
135
|
+
|
136
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>name</key>\n\t\t<string>leo</string>\n\t\t<key>person</key>\n\t\t<dict>\n\t\t\t<key>city</key>\n\t\t\t<string>LA</string>\n\t\t</dict>\n\t</dict>\n</dict>\n</plist>\n"
|
137
|
+
end
|
138
|
+
|
139
|
+
context "#glue" do
|
140
|
+
|
141
|
+
asserts "that it glues data from a child node" do
|
142
|
+
template = rabl %{
|
143
|
+
object @user
|
144
|
+
attribute :name
|
145
|
+
glue(@user) { attribute :city }
|
146
|
+
glue(@user) { attribute :age }
|
147
|
+
}
|
148
|
+
scope = Object.new
|
149
|
+
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12)
|
150
|
+
template.render(scope)
|
151
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>age</key>\n\t\t<integer>12</integer>\n\t\t<key>city</key>\n\t\t<string>LA</string>\n\t\t<key>name</key>\n\t\t<string>leo</string>\n\t</dict>\n</dict>\n</plist>\n"
|
152
|
+
end
|
153
|
+
|
154
|
+
teardown do
|
155
|
+
Rabl.reset_configuration!
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context "with plist_engine" do
|
160
|
+
setup do
|
161
|
+
class CustomPlistEncodeEngine
|
162
|
+
def self.dump string
|
163
|
+
42
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
Rabl.configure do |config|
|
168
|
+
config.plist_engine = CustomPlistEncodeEngine
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
asserts 'that it returns process by custom to_json' do
|
173
|
+
template = rabl %q{
|
174
|
+
object @user
|
175
|
+
}
|
176
|
+
scope = Object.new
|
177
|
+
scope.instance_variable_set :@user, User.new
|
178
|
+
template.render(scope)
|
179
|
+
end.equals 42
|
180
|
+
|
181
|
+
teardown do
|
182
|
+
Rabl.reset_configuration!
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context "without plist root" do
|
187
|
+
setup do
|
188
|
+
Rabl.configure do |config|
|
189
|
+
config.include_plist_root = false
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context "#object" do
|
194
|
+
|
195
|
+
asserts "that it sets data source" do
|
196
|
+
template = rabl %q{
|
197
|
+
object @user
|
198
|
+
}
|
199
|
+
scope = Object.new
|
200
|
+
scope.instance_variable_set :@user, User.new
|
201
|
+
template.render(scope)
|
202
|
+
end.matches "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict/>\n</plist>\n"
|
203
|
+
|
204
|
+
asserts "that it can set root node" do
|
205
|
+
template = rabl %q{
|
206
|
+
object @user => :person
|
207
|
+
}
|
208
|
+
scope = Object.new
|
209
|
+
scope.instance_variable_set :@user, User.new
|
210
|
+
template.render(scope)
|
211
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict/>\n</plist>\n"
|
212
|
+
end
|
213
|
+
|
214
|
+
context "#collection" do
|
215
|
+
|
216
|
+
asserts "that it sets object to be casted as a simple array" do
|
217
|
+
template = rabl %{
|
218
|
+
collection @users
|
219
|
+
}
|
220
|
+
scope = Object.new
|
221
|
+
scope.instance_variable_set :@users, [User.new, User.new]
|
222
|
+
template.render(scope)
|
223
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<array>\n\t<dict/>\n\t<dict/>\n</array>\n</plist>\n"
|
224
|
+
|
225
|
+
asserts "that it sets root node for objects" do
|
226
|
+
template = rabl %{
|
227
|
+
collection @users => :person
|
228
|
+
}
|
229
|
+
scope = Object.new
|
230
|
+
scope.instance_variable_set :@users, [User.new, User.new]
|
231
|
+
template.render(scope)
|
232
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>person</key>\n\t<array>\n\t\t<dict/>\n\t\t<dict/>\n\t</array>\n</dict>\n</plist>\n"
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
context "#attribute" do
|
237
|
+
|
238
|
+
asserts "that it adds an attribute or method to be included in output" do
|
239
|
+
template = rabl %{
|
240
|
+
object @user
|
241
|
+
attribute :name
|
242
|
+
}
|
243
|
+
scope = Object.new
|
244
|
+
scope.instance_variable_set :@user, User.new(:name => 'irvine')
|
245
|
+
template.render(scope)
|
246
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>name</key>\n\t<string>irvine</string>\n</dict>\n</plist>\n"
|
247
|
+
|
248
|
+
asserts "that it can add attribute under a different key name through :as" do
|
249
|
+
template = rabl %{
|
250
|
+
object @user
|
251
|
+
attribute :name, :as => 'city'
|
252
|
+
}
|
253
|
+
scope = Object.new
|
254
|
+
scope.instance_variable_set :@user, User.new(:name => 'irvine')
|
255
|
+
template.render(scope)
|
256
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>city</key>\n\t<string>irvine</string>\n</dict>\n</plist>\n"
|
257
|
+
|
258
|
+
asserts "that it can add attribute under a different key name through hash" do
|
259
|
+
template = rabl %{
|
260
|
+
object @user
|
261
|
+
attribute :name => :city
|
262
|
+
}
|
263
|
+
scope = Object.new
|
264
|
+
scope.instance_variable_set :@user, User.new(:name => 'irvine')
|
265
|
+
template.render(scope)
|
266
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>city</key>\n\t<string>irvine</string>\n</dict>\n</plist>\n"
|
267
|
+
|
268
|
+
end
|
269
|
+
|
270
|
+
context "#code" do
|
271
|
+
|
272
|
+
asserts "that it can create an arbitraty code node" do
|
273
|
+
template = rabl %{
|
274
|
+
code(:foo) { 'bar' }
|
275
|
+
}
|
276
|
+
template.render(Object.new)
|
277
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>foo</key>\n\t<string>bar</string>\n</dict>\n</plist>\n"
|
278
|
+
|
279
|
+
asserts "that it can be passed conditionals" do
|
280
|
+
template = rabl %{
|
281
|
+
code(:foo, :if => lambda { |i| false }) { 'bar' }
|
282
|
+
}
|
283
|
+
template.render(Object.new)
|
284
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict/>\n</plist>\n"
|
285
|
+
|
286
|
+
end
|
287
|
+
|
288
|
+
context "#child" do
|
289
|
+
|
290
|
+
asserts "that it can create a child node" do
|
291
|
+
template = rabl %{
|
292
|
+
object @user
|
293
|
+
attribute :name
|
294
|
+
child(@user) { attribute :city }
|
295
|
+
}
|
296
|
+
scope = Object.new
|
297
|
+
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
|
298
|
+
template.render(scope)
|
299
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>name</key>\n\t<string>leo</string>\n\t<key>user</key>\n\t<dict>\n\t\t<key>city</key>\n\t\t<string>LA</string>\n\t</dict>\n</dict>\n</plist>\n"
|
300
|
+
|
301
|
+
asserts "that it can create a child node with different key" do
|
302
|
+
template = rabl %{
|
303
|
+
object @user
|
304
|
+
attribute :name
|
305
|
+
child(@user => :person) { attribute :city }
|
306
|
+
}
|
307
|
+
scope = Object.new
|
308
|
+
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
|
309
|
+
template.render(scope)
|
310
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>name</key>\n\t<string>leo</string>\n\t<key>person</key>\n\t<dict>\n\t\t<key>city</key>\n\t\t<string>LA</string>\n\t</dict>\n</dict>\n</plist>\n"
|
311
|
+
end
|
312
|
+
|
313
|
+
context "#glue" do
|
314
|
+
|
315
|
+
asserts "that it glues data from a child node" do
|
316
|
+
template = rabl %{
|
317
|
+
object @user
|
318
|
+
attribute :name
|
319
|
+
glue(@user) { attribute :city }
|
320
|
+
glue(@user) { attribute :age }
|
321
|
+
}
|
322
|
+
scope = Object.new
|
323
|
+
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12)
|
324
|
+
template.render(scope)
|
325
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>age</key>\n\t<integer>12</integer>\n\t<key>city</key>\n\t<string>LA</string>\n\t<key>name</key>\n\t<string>leo</string>\n</dict>\n</plist>\n"
|
326
|
+
end
|
327
|
+
|
328
|
+
teardown do
|
329
|
+
Rabl.reset_configuration!
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rabl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 6
|
5
|
-
version: 0.5.5.
|
5
|
+
version: 0.5.5.h
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nathan Esquenazi
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-02-
|
13
|
+
date: 2012-02-16 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -111,6 +111,17 @@ dependencies:
|
|
111
111
|
version: 1.5.2
|
112
112
|
type: :development
|
113
113
|
version_requirements: *id009
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: plist
|
116
|
+
prerelease: false
|
117
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: "0"
|
123
|
+
type: :development
|
124
|
+
version_requirements: *id010
|
114
125
|
description: General ruby templating with json, bson, xml and msgpack support
|
115
126
|
email:
|
116
127
|
- nesquena@gmail.com
|
@@ -274,6 +285,7 @@ files:
|
|
274
285
|
- test/models/user.rb
|
275
286
|
- test/msgpack_engine_test.rb
|
276
287
|
- test/partials_test.rb
|
288
|
+
- test/plist_engine_test.rb
|
277
289
|
- test/silence.rb
|
278
290
|
- test/template_test.rb
|
279
291
|
- test/teststrap.rb
|
@@ -317,6 +329,7 @@ test_files:
|
|
317
329
|
- test/models/user.rb
|
318
330
|
- test/msgpack_engine_test.rb
|
319
331
|
- test/partials_test.rb
|
332
|
+
- test/plist_engine_test.rb
|
320
333
|
- test/silence.rb
|
321
334
|
- test/template_test.rb
|
322
335
|
- test/teststrap.rb
|