rabl 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/Gemfile +2 -2
- data/README.md +10 -7
- data/lib/rabl/engine.rb +3 -2
- data/lib/rabl/version.rb +1 -1
- data/test/xml_test.rb +13 -3
- metadata +9 -3
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,10 +3,11 @@
|
|
3
3
|
[](http://travis-ci.org/nesquena/rabl)
|
4
4
|
[](https://gemnasium.com/nesquena/rabl)
|
5
5
|
|
6
|
-
RABL (Ruby API Builder Language) is a Rails and [Padrino](http://padrinorb.com) ruby templating system for generating JSON, XML, MessagePack, PList and BSON.
|
7
|
-
|
6
|
+
RABL (Ruby API Builder Language) is a Rails and [Padrino](http://padrinorb.com) ruby templating system for generating JSON, XML, MessagePack, PList and BSON.
|
7
|
+
When using the ActiveRecord 'to_json' method, I find myself wanting a more expressive and powerful solution for generating APIs.
|
8
|
+
This is especially true when the JSON representation is complex or doesn't match the exact schema defined within the database.
|
8
9
|
|
9
|
-
|
10
|
+
In particular, I want to easily:
|
10
11
|
|
11
12
|
* Create arbitrary nodes named based on combining data in an object
|
12
13
|
* Pass arguments to methods and store the result as a child node
|
@@ -16,14 +17,15 @@ I wanted a simple and flexible system for generating my APIs. In particular, I w
|
|
16
17
|
* Include nodes only if a certain condition has been met
|
17
18
|
|
18
19
|
Anyone who has tried the 'to_json' method used in ActiveRecord for generating a JSON response has felt the pain of this restrictive approach.
|
19
|
-
RABL is a general templating system created to solve these problems in an entirely new way.
|
20
|
+
RABL is a general templating system created to solve these problems by approaching API response generation in an entirely new way.
|
20
21
|
|
22
|
+
RABL at the core is all about adhering to MVC principles by deferring API data representations to the **view** layer of your application.
|
21
23
|
For a breakdown of common misconceptions about RABL, please check out our guide to
|
22
|
-
[understanding RABL](https://github.com/nesquena/rabl/wiki/Understanding-RABL) which can help clear up any confusion about this project.
|
24
|
+
[understanding RABL](https://github.com/nesquena/rabl/wiki/Understanding-RABL) which can help clear up any confusion about this project.
|
23
25
|
|
24
26
|
## Breaking Changes ##
|
25
27
|
|
26
|
-
* v0.8.0 (released Feb 14,
|
28
|
+
* v0.8.0 (released Feb 14, 2013) removes multi_json dependency and
|
27
29
|
relies on Oj (or JSON) as the json parser. Simplifies code, removes a dependency
|
28
30
|
but you might want to remove any references to MultiJson.
|
29
31
|
|
@@ -541,7 +543,8 @@ the [RABL Wiki](https://github.com/nesquena/rabl/wiki) for other usages.
|
|
541
543
|
|
542
544
|
Tutorials can always be helpful when first getting started:
|
543
545
|
|
544
|
-
* [Railscasts #322](http://railscasts.com/episodes/322-rabl)
|
546
|
+
* [Railscasts #322](http://railscasts.com/episodes/322-rabl) - Ryan Bates explains RABL
|
547
|
+
* [BackboneRails](http://www.backbonerails.com/) - Great screencasts by Brian Mann
|
545
548
|
* [Creating an API with RABL and Padrino](http://blog.crowdint.com/2012/10/22/rabl-with-padrino.html)
|
546
549
|
* http://blog.joshsoftware.com/2011/12/23/designing-rails-api-using-rabl-and-devise/
|
547
550
|
* http://engineering.gomiso.com/2011/06/27/building-a-platform-api-on-rails/
|
data/lib/rabl/engine.rb
CHANGED
@@ -89,8 +89,9 @@ module Rabl
|
|
89
89
|
include_root = Rabl.configuration.include_xml_root
|
90
90
|
include_child_root = include_root && Rabl.configuration.include_child_root
|
91
91
|
options = options.reverse_merge(:root => include_root, :child_root => include_child_root)
|
92
|
-
xml_options = Rabl.configuration.default_xml_options.merge(:root => @_data_name)
|
93
|
-
to_hash(options)
|
92
|
+
xml_options = Rabl.configuration.default_xml_options.merge(:root => collection_root_name || @_data_name)
|
93
|
+
result = to_hash(options)
|
94
|
+
result.to_xml(xml_options)
|
94
95
|
end
|
95
96
|
|
96
97
|
# Returns a bson representation of the data object
|
data/lib/rabl/version.rb
CHANGED
data/test/xml_test.rb
CHANGED
@@ -50,12 +50,12 @@ context "Rabl::Engine" do
|
|
50
50
|
|
51
51
|
asserts "that it sets root node for objects" do
|
52
52
|
template = rabl %{
|
53
|
-
collection @users => :
|
53
|
+
collection @users => :smors
|
54
54
|
}
|
55
55
|
scope = Object.new
|
56
56
|
scope.instance_variable_set :@users, [User.new, User.new]
|
57
57
|
template.render(scope)
|
58
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<
|
58
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<smors type=\"array\">\n <smor>\n </smor>\n <smor>\n </smor>\n</smors>\n"
|
59
59
|
end
|
60
60
|
|
61
61
|
context "#attribute" do
|
@@ -187,12 +187,22 @@ context "Rabl::Engine" do
|
|
187
187
|
|
188
188
|
asserts "that it sets root node for objects" do
|
189
189
|
template = rabl %{
|
190
|
-
collection @users => :
|
190
|
+
collection @users => :people
|
191
191
|
}
|
192
192
|
scope = Object.new
|
193
193
|
scope.instance_variable_set :@users, [User.new, User.new]
|
194
194
|
template.render(scope)
|
195
195
|
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<people type=\"array\">\n <person>\n <person>\n </person>\n </person>\n <person>\n <person>\n </person>\n </person>\n</people>\n"
|
196
|
+
|
197
|
+
asserts "that it sets root node for objects with :root parameter" do
|
198
|
+
template = rabl %{
|
199
|
+
collection @users, :root => :people, :object_root => :person
|
200
|
+
}
|
201
|
+
scope = Object.new
|
202
|
+
scope.instance_variable_set :@users, [User.new, User.new]
|
203
|
+
template.render(scope)
|
204
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<people type=\"array\">\n <person>\n <person>\n </person>\n </person>\n <person>\n <person>\n </person>\n </person>\n</people>\n"
|
205
|
+
|
196
206
|
end
|
197
207
|
|
198
208
|
context "#attribute" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -422,15 +422,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
422
422
|
- - ! '>='
|
423
423
|
- !ruby/object:Gem::Version
|
424
424
|
version: '0'
|
425
|
+
segments:
|
426
|
+
- 0
|
427
|
+
hash: 2506448699878914083
|
425
428
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
426
429
|
none: false
|
427
430
|
requirements:
|
428
431
|
- - ! '>='
|
429
432
|
- !ruby/object:Gem::Version
|
430
433
|
version: '0'
|
434
|
+
segments:
|
435
|
+
- 0
|
436
|
+
hash: 2506448699878914083
|
431
437
|
requirements: []
|
432
438
|
rubyforge_project: rabl
|
433
|
-
rubygems_version: 1.8.
|
439
|
+
rubygems_version: 1.8.25
|
434
440
|
signing_key:
|
435
441
|
specification_version: 3
|
436
442
|
summary: General ruby templating with json, bson, xml and msgpack support
|