rabl 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -5
- data/lib/rabl/configuration.rb +9 -0
- data/lib/rabl/engine.rb +3 -2
- data/lib/rabl/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -89,6 +89,7 @@ Rabl.configure do |config|
|
|
89
89
|
# config.include_json_root = true
|
90
90
|
# config.include_xml_root = false
|
91
91
|
# config.enable_json_callbacks = false
|
92
|
+
# config.xml_options = { :dasherize => true, :skip_types => false }
|
92
93
|
end
|
93
94
|
```
|
94
95
|
|
@@ -227,23 +228,24 @@ You can use custom "code" nodes to create flexible representations of a value ut
|
|
227
228
|
|
228
229
|
### Partials ###
|
229
230
|
|
230
|
-
Often you need to access
|
231
|
+
Often you need to access other data objects in order to construct custom nodes in more complex associations. You can get access to the rabl representation of another data object by rendering a RABL partial:
|
231
232
|
|
232
233
|
```ruby
|
233
234
|
code :location do
|
234
|
-
{ :city => @city, :address => partial("
|
235
|
+
{ :city => @city, :address => partial("users/address", :object => @address) }
|
235
236
|
end
|
236
237
|
```
|
237
238
|
|
238
|
-
or an object associated
|
239
|
+
or event access an object associated with the parent model:
|
239
240
|
|
240
241
|
```ruby
|
241
242
|
code :location do |m|
|
242
|
-
{ :city => m.city, :address => partial("
|
243
|
+
{ :city => m.city, :address => partial("users/address", :object => m.address) }
|
243
244
|
end
|
244
245
|
```
|
245
246
|
|
246
|
-
You can use this method to construct arbitrarily complex nodes for your APIs.
|
247
|
+
You can use this method to construct arbitrarily complex nodes for your APIs. Note that you need to have RABL templates defined
|
248
|
+
for each of the objects you wish to construct representations for in this manner.
|
247
249
|
|
248
250
|
### Inheritance ###
|
249
251
|
|
@@ -323,6 +325,7 @@ Thanks to [Miso](http://gomiso.com) for allowing me to create this for our appli
|
|
323
325
|
* [Arthur Chiu](https://github.com/achiu) - Core Maintainer, Riot Testing Guru
|
324
326
|
* [Tim Lee](https://github.com/timothy1ee) - RABL is an awesome name and was chosen by the Miso CTO.
|
325
327
|
* [Rick Thomas](https://github.com/rickthomasjr) - Added options passing for extends and Sinatra testing
|
328
|
+
* [Marjun](https://github.com/mpagalan) - Added xml option configurations
|
326
329
|
|
327
330
|
More to come hopefully! Please fork and contribute, any help is appreciated!
|
328
331
|
|
data/lib/rabl/configuration.rb
CHANGED
@@ -4,11 +4,15 @@ module Rabl
|
|
4
4
|
attr_accessor :include_json_root
|
5
5
|
attr_accessor :include_xml_root
|
6
6
|
attr_accessor :enable_json_callbacks
|
7
|
+
attr_writer :xml_options
|
8
|
+
|
9
|
+
DEFAULT_XML_OPTIONS = { :dasherize => true, :skip_types => false }
|
7
10
|
|
8
11
|
def initialize
|
9
12
|
@include_json_root = true
|
10
13
|
@include_xml_root = false
|
11
14
|
@enable_json_callbacks = false
|
15
|
+
@xml_options = {}
|
12
16
|
end
|
13
17
|
|
14
18
|
# Allows config options to be read like a hash
|
@@ -17,5 +21,10 @@ module Rabl
|
|
17
21
|
def [](option)
|
18
22
|
send(option)
|
19
23
|
end
|
24
|
+
|
25
|
+
# Returns merged default and inputted xml options
|
26
|
+
def default_xml_options
|
27
|
+
@_default_xml_options ||= @xml_options.reverse_merge(DEFAULT_XML_OPTIONS)
|
28
|
+
end
|
20
29
|
end
|
21
30
|
end
|
data/lib/rabl/engine.rb
CHANGED
@@ -49,7 +49,8 @@ module Rabl
|
|
49
49
|
def to_xml(options={})
|
50
50
|
include_root = Rabl.configuration.include_xml_root
|
51
51
|
options = options.reverse_merge(:root => include_root, :child_root => include_root)
|
52
|
-
|
52
|
+
xml_options = Rabl.configuration.default_xml_options.merge(:root => data_name(@_data))
|
53
|
+
to_hash(options).to_xml(xml_options)
|
53
54
|
end
|
54
55
|
|
55
56
|
# Sets the object to be used as the data source for this template
|
@@ -162,4 +163,4 @@ module Rabl
|
|
162
163
|
@_scope.respond_to?(name) ? @_scope.send(name, *args, &block) : super
|
163
164
|
end
|
164
165
|
end
|
165
|
-
end
|
166
|
+
end
|
data/lib/rabl/version.rb
CHANGED