rabl 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.6.2
4
+
5
+ * Adds template caching support for Rails (Thanks @databyte)
6
+
3
7
  ## 0.6.1
4
8
 
5
9
  * Upgrade dependency to multi_json 1.1.0 (Thanks @geronimo)
data/README.md CHANGED
@@ -98,6 +98,7 @@ RABL is intended to require little to no configuration to get working. This is t
98
98
  # config/initializers/rabl_init.rb
99
99
  Rabl.configure do |config|
100
100
  # Commented as these are defaults
101
+ # config.cache_all_output = false
101
102
  # config.cache_sources = false
102
103
  # config.json_engine = nil # Any multi\_json engines
103
104
  # config.msgpack_engine = nil # Defaults to ::MessagePack
@@ -120,8 +121,12 @@ output if the incoming request has a 'callback' parameter.
120
121
  If `cache_sources` is set to `true`, template lookups will be cached for improved performance.
121
122
  The cache can be reset manually by running `Rabl.reset_source_cache!` within your application.
122
123
 
123
- Note that the `json_engine` option uses the [multi_json](http://intridea.com/2010/6/14/multi-json-the-swappable-json-handler) intelligent engine
124
- defaults so in most cases you **don't need to configure this** directly. If you wish to use yajl as
124
+ If `cache_all_output` is set to `true` then every template including each individual template used as part of a collection will be cached separately.
125
+ Additionally, anything within child, glue and partial will also be cached separately.
126
+ To cache just a single template, see the section titled 'Caching' below.
127
+
128
+ Note that the `json_engine` option uses [multi_json](http://intridea.com/2010/6/14/multi-json-the-swappable-json-handler) engine
129
+ defaults so that in most cases you **don't need to configure this** directly. If you wish to use yajl as
125
130
  the primary JSON encoding engine simply add that to your Gemfile:
126
131
 
127
132
  ```ruby
@@ -455,6 +460,60 @@ end
455
460
  This will display the quiz object with nested questions and answers as you would expect with a quiz node, and embedded questions and answers.
456
461
  Note that RABL can be nested arbitrarily deep within child nodes to allow for these representations to be defined.
457
462
 
463
+ ### Caching ###
464
+
465
+ Caching works by saving the entire template output to the configured cache_store in your application. Note that caching is currently **only available** for
466
+ Rails but support for other frameworks is planned in a future release.
467
+
468
+ For Rails, requires `action_controller.perform_caching` to be set to true in your environment, and for `cache` to be set to a key (object that responds to cache_key method, array or string).
469
+
470
+ ```ruby
471
+ # app/views/users/show.json.rabl
472
+ object @quiz
473
+ cache @quiz # key = rabl/quiz/[cache_key]
474
+ attribute :title
475
+ ```
476
+
477
+ The `cache` keyword accepts the same parameters as fragment caching for Rails.
478
+
479
+ ```ruby
480
+ cache @user # calls @user.cache_key
481
+ cache ['keel', @user] # calls @user.cache_key and prefixes with kewl/
482
+ cache 'lists' # explicit key of 'lists'
483
+ cache 'lists', expires_in: 1.hour
484
+ ```
485
+
486
+ The cache keyword is used from within the base template. It will ignore any cache keys specified in an extended template or within partials.
487
+
488
+ ```ruby
489
+ # app/views/users/index.json.rabl
490
+ collection @users
491
+ cache @users # key = rabl/users/[cache_key]/users/[cache_key]/...
492
+
493
+ extends "users/show"
494
+ ```
495
+
496
+ and within the inherited template:
497
+
498
+ ```ruby
499
+ # app/views/users/show.json.rabl
500
+ object @user
501
+ cache @user # will be ignored
502
+
503
+ attributes :name, :email
504
+ ```
505
+ Caching can significantly speed up the rendering of RABL templates in production and is strongly recommended when possible.
506
+
507
+ ### Content Type Assignment ###
508
+
509
+ Currently in RABL, the content-type of your response is not set automatically. This is because RABL is intended
510
+ to work for any Rack-based framework and as agostic to format as possible.
511
+ Check [this issue](https://github.com/nesquena/rabl/issues/185#issuecomment-4501232) for more
512
+ details, and if you have any ideas or patches please let me know.
513
+
514
+ In the meantime, be sure to set the proper content-types if needed. This is usually pretty simple in both
515
+ Rails and Padrino. I recommend a before_filter on that controller or directly specified in an action.
516
+
458
517
  ## Resources ##
459
518
 
460
519
  There are many resources available relating to RABL including the [RABL Wiki](https://github.com/nesquena/rabl/wiki),
@@ -535,6 +594,7 @@ Thanks to [Miso](http://gomiso.com) for allowing me to create this for our appli
535
594
  * [Luke van der Hoeven](https://github.com/plukevdh) - Support non-ORM objects in templates
536
595
  * [Andrey Voronkov](https://github.com/Antiarchitect) - Added BSON format support
537
596
  * [Alli Witheford](https://github.com/alzeih) - Added Plist format support
597
+ * [David Sommers](https://github.com/databyte) - Added template caching support for Rails
538
598
 
539
599
  and many more contributors listed in the [CHANGELOG](https://github.com/nesquena/rabl/blob/master/CHANGELOG.md).
540
600
 
@@ -1,4 +1,5 @@
1
1
  collection @posts => :articles
2
+ cache ['kittens!', @posts]
2
3
 
3
4
  extends "posts/show"
4
5
 
@@ -1,4 +1,5 @@
1
1
  object @post
2
+ cache @post
2
3
 
3
4
  attributes :title, :body
4
5
  attributes :created_at => :posted_at
@@ -1,8 +1,8 @@
1
1
  source :gemcutter
2
2
  gem "rails", "~> 2.3.14"
3
- gem "sqlite3-ruby", :require => "sqlite3"
3
+ gem "sqlite3", :require => "sqlite3"
4
4
  gem 'json'
5
5
  gem 'rabl', :path => File.expand_path(File.dirname(__FILE__) + "/../../")
6
6
 
7
7
  gem 'riot', :group => "test"
8
- gem 'rack-test', :require => "rack/test", :group => "test"
8
+ gem 'rack-test', :require => "rack/test", :group => "test"
@@ -1,5 +1,5 @@
1
1
  class PostsController < ApplicationController
2
- respond_to :json
2
+ respond_to :json, :xml
3
3
 
4
4
  def index
5
5
  @posts = Post.all(:order => "id ASC")
@@ -7,11 +7,14 @@ rescue LoadError # Rails
7
7
  require File.expand_path(File.dirname(__FILE__) + '/../test_helper.rb')
8
8
  end
9
9
 
10
+ require 'rexml/document'
11
+
10
12
  context "PostsController" do
11
13
  helper(:json_output) { JSON.parse(last_response.body) }
12
14
 
13
15
  setup do
14
16
  create_users!
17
+ Rails.cache.clear
15
18
  Post.delete_all
16
19
  @post1 = Post.create(:title => "Foo", :body => "Bar", :user_id => @user1.id)
17
20
  @post2 = Post.create(:title => "Baz", :body => "Bah", :user_id => @user2.id)
@@ -78,7 +81,7 @@ context "PostsController" do
78
81
  json_output['post']
79
82
  end
80
83
 
81
- # Attributes (regular)
84
+ # Attributes (regular)
82
85
  asserts("contains post title") { topic['title'] }.equals { @post1.title }
83
86
  asserts("contains post body") { topic['body'] }.equals { @post1.body }
84
87
 
@@ -105,4 +108,71 @@ context "PostsController" do
105
108
  asserts("contains date partial with full") { topic['full'] }.equals { @post1.created_at.iso8601 }
106
109
  end # date node
107
110
  end # show action
111
+
112
+ context "for index action with caching in json" do
113
+ helper(:cache_hit) do |key|
114
+ Rails.cache.read(ActiveSupport::Cache.expand_cache_key(key, :rabl))
115
+ end
116
+
117
+ setup do
118
+ mock(ActionController::Base).perform_caching.any_number_of_times { true }
119
+ get "/posts.json"
120
+ end
121
+
122
+ asserts("contains post titles") do
123
+ json_output['articles'].map { |o| o['article']['title'] }
124
+ end.equals { @posts.map(&:title) }
125
+
126
+ asserts(:body).equals { cache_hit ['kittens!', @posts, nil, 'json'] }
127
+ end # index action, caching, json
128
+
129
+ context "for index action with caching in xml" do
130
+ helper(:cache_hit) do |key|
131
+ Rails.cache.read(ActiveSupport::Cache.expand_cache_key(key, :rabl))
132
+ end
133
+
134
+ setup do
135
+ mock(ActionController::Base).perform_caching.any_number_of_times { true }
136
+ get "/posts.xml"
137
+ end
138
+
139
+ asserts("contains post titles") do
140
+ doc = REXML::Document.new topic.body
141
+ doc.elements.inject('articles/article/title', []) {|arr, ele| arr << ele.text}
142
+ end.equals { @posts.map(&:title) }
143
+
144
+ asserts(:body).equals { cache_hit ['kittens!', @posts, nil, 'xml'] }
145
+ end # index action, caching, xml
146
+
147
+ context "for show action with caching" do
148
+ helper(:cache_hit) do |key|
149
+ Rails.cache.read(ActiveSupport::Cache.expand_cache_key(key, :rabl))
150
+ end
151
+
152
+ setup do
153
+ mock(ActionController::Base).perform_caching.any_number_of_times { true }
154
+ get "/posts/#{@post1.id}"
155
+ end
156
+
157
+ asserts("contains post title") { json_output['post']['title'] }.equals { @post1.title }
158
+
159
+ asserts(:body).equals { cache_hit [@post1, nil, 'json'] }
160
+ end # show action, caching, json
161
+
162
+ context "cache_all_output" do
163
+ helper(:cache_hit) do |key|
164
+ Rails.cache.read(ActiveSupport::Cache.expand_cache_key([key, 'article', 'json'], :rabl))
165
+ end
166
+
167
+ setup do
168
+ mock(ActionController::Base).perform_caching.any_number_of_times { true }
169
+ Rabl.configuration.cache_all_output = true
170
+ get "/posts"
171
+ end
172
+
173
+ asserts("contains cache hits per object (posts by title)") do
174
+ json_output['articles'].map { |o| o['article']['title'] }
175
+ end.equals { @posts.map{ |p| cache_hit(p)['article'][:title] } }
176
+ end # index action, cache_all_output
177
+
108
178
  end
@@ -24,21 +24,21 @@ class SinatraTest < Sinatra::Application
24
24
 
25
25
  get "/posts" do
26
26
  @posts = Post.order("id ASC")
27
- render :rabl, :"posts/index.json", :format => "json"
27
+ render :rabl, :"posts/index", :format => "json"
28
28
  end
29
29
 
30
30
  get "/posts/:id" do
31
31
  @post = Post.find(params[:id])
32
- render :rabl, :"posts/show.json", :format => "json"
32
+ render :rabl, :"posts/show", :format => "json"
33
33
  end
34
34
 
35
35
  get "/users" do
36
36
  @users = User.order("username ASC")
37
- render :rabl, :"users/index", :format => "json"
37
+ render :rabl, :"users/index.json", :format => "json"
38
38
  end
39
39
 
40
40
  get "/users/:id" do
41
41
  @user = User.find(params[:id])
42
- render :rabl, :"users/show", :format => "json"
42
+ render :rabl, :"users/show.json", :format => "json"
43
43
  end
44
44
  end
data/lib/rabl/builder.rb CHANGED
@@ -15,7 +15,10 @@ module Rabl
15
15
  # build(@user, :format => "json", :attributes => { ... }, :root_name => "user")
16
16
  def build(object, options={})
17
17
  @_object = object
18
- compile_hash(options)
18
+
19
+ cache_results do
20
+ compile_hash(options)
21
+ end
19
22
  end
20
23
 
21
24
  protected
@@ -109,8 +112,6 @@ module Rabl
109
112
  @_result.merge!(result) if result
110
113
  end
111
114
 
112
- protected
113
-
114
115
  # resolve_condition(:if => true) => true
115
116
  # resolve_condition(:if => lambda { |m| false }) => false
116
117
  # resolve_condition(:unless => lambda { |m| true }) => true
@@ -120,5 +121,19 @@ module Rabl
120
121
  result = options[:unless] == false || (options[:unless].respond_to?(:call) && !options[:unless].call(@_object)) if options.has_key?(:unless)
121
122
  result
122
123
  end
124
+
125
+ private
126
+
127
+ # Caches the results of the block based on object cache_key
128
+ # cache_results { compile_hash(options) }
129
+ def cache_results(&block)
130
+ if template_cache_configured? && Rabl.configuration.cache_all_output && @_object.respond_to?(:cache_key)
131
+ result_cache_key = [@_object, @options[:root_name], @options[:format]]
132
+ fetch_result_from_cache(result_cache_key, &block)
133
+ else # skip cache
134
+ yield
135
+ end
136
+ end
137
+
123
138
  end
124
139
  end
@@ -35,6 +35,7 @@ module Rabl
35
35
  attr_writer :plist_engine
36
36
  attr_writer :xml_options
37
37
  attr_accessor :cache_sources
38
+ attr_accessor :cache_all_output
38
39
 
39
40
  DEFAULT_XML_OPTIONS = { :dasherize => true, :skip_types => false }
40
41
 
@@ -53,6 +54,7 @@ module Rabl
53
54
  @plist_engine = nil
54
55
  @xml_options = {}
55
56
  @cache_sources = false
57
+ @cache_all_output = false
56
58
  end
57
59
 
58
60
  # @param [Symbol, String, #encode] engine_name The name of a JSON engine,
data/lib/rabl/engine.rb CHANGED
@@ -24,7 +24,7 @@ module Rabl
24
24
  instance_eval(@_source) if @_source.present?
25
25
  end
26
26
  instance_eval(&block) if block_given?
27
- self.send("to_" + @_options[:format].to_s)
27
+ cache_results { self.send("to_" + @_options[:format].to_s) }
28
28
  end
29
29
 
30
30
  # Returns a hash representation of the data object
@@ -34,6 +34,7 @@ module Rabl
34
34
  data = data_object(@_data)
35
35
  builder = Rabl::Builder.new(options)
36
36
  options[:root_name] = determine_object_root(@_data, options[:root])
37
+
37
38
  if is_object?(data) || !data # object @user
38
39
  builder.build(data, options)
39
40
  elsif is_collection?(data) # collection @users
@@ -113,6 +114,16 @@ module Rabl
113
114
  self.object(data_object(data).to_a) if data
114
115
  end
115
116
 
117
+ # Sets the cache key to be used by ActiveSupport::Cache.expand_cache_key
118
+ # cache @user # calls @user.cache_key
119
+ # cache ['rabl', @user] # calls @user.cache_key and prefixes with rabl/
120
+ # cache 'user' # explicit key of 'user'
121
+ # cache 'user', expires_in: 1.hour
122
+ # options is passed through to the cache store
123
+ def cache(key, options = nil)
124
+ @_cache = [key, options]
125
+ end
126
+
116
127
  # Indicates an attribute or method should be included in the json output
117
128
  # attribute :foo, :as => "bar"
118
129
  # attribute :foo => :bar
@@ -221,5 +232,19 @@ module Rabl
221
232
  @_options[:extends] = []
222
233
  @_options[:root_name] = nil
223
234
  end
235
+
236
+ # Caches the results of the block based on object cache_key
237
+ # cache_results { compile_hash(options) }
238
+ def cache_results(&block)
239
+ _cache = @_cache if defined?(@_cache)
240
+ cache_key, cache_options = *_cache || nil
241
+ if template_cache_configured? && cache_key
242
+ result_cache_key = Array(cache_key) + [@_options[:root_name], @_options[:format]]
243
+ fetch_result_from_cache(result_cache_key, cache_options, &block)
244
+ else # skip caching
245
+ yield
246
+ end
247
+ end
248
+
224
249
  end
225
250
  end
data/lib/rabl/helpers.rb CHANGED
@@ -78,5 +78,17 @@ module Rabl
78
78
  defined?(@_collection_name) ? @_collection_name : nil
79
79
  end
80
80
 
81
+ # Fetches a key from the cache and stores rabl template result otherwise
82
+ # fetch_from_cache('some_key') { ...rabl template result... }
83
+ def fetch_result_from_cache(cache_key, cache_options=nil, &block)
84
+ expanded_cache_key = ActiveSupport::Cache.expand_cache_key(cache_key, :rabl)
85
+ Rails.cache.fetch(expanded_cache_key, cache_options, &block) if defined?(Rails)
86
+ end
87
+
88
+ # Returns true if the cache has been enabled for the application
89
+ def template_cache_configured?
90
+ defined?(Rails) && defined?(ActionController) && ActionController::Base.perform_caching
91
+ end
92
+
81
93
  end
82
94
  end
data/lib/rabl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rabl
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
data/test/builder_test.rb CHANGED
@@ -23,34 +23,26 @@ context "Rabl::Builder" do
23
23
  end
24
24
 
25
25
  context "#to_hash" do
26
-
27
26
  context "when given a simple object" do
28
-
29
27
  setup { builder({ :attributes => { :name => :name } }) }
30
28
  asserts "that the object is set properly" do
31
29
  topic.build(User.new, :root_name => "user")
32
30
  end.equivalent_to({ "user" => { :name => "rabl" } })
33
-
34
31
  end
35
32
 
36
33
  context "when given an object alias" do
37
-
38
34
  setup { builder({ :attributes => { :name => :name } }) }
39
35
  asserts "that the object is set properly" do
40
36
  topic.build(User.new, :root_name => "person")
41
37
  end.equivalent_to({ "person" => { :name => "rabl" } })
42
-
43
38
  end
44
39
 
45
40
  context "when specified with no root" do
46
-
47
41
  setup { builder({ :attributes => { :name => :name } }) }
48
42
  asserts "that the object is set properly" do
49
43
  topic.build(User.new, :root => false)
50
44
  end.equivalent_to({ :name => "rabl" })
51
-
52
45
  end
53
-
54
46
  end
55
47
 
56
48
  context "#attribute" do
@@ -63,7 +55,6 @@ context "Rabl::Builder" do
63
55
  end.equals({})
64
56
  end
65
57
 
66
-
67
58
  context "#node" do
68
59
  asserts "that it has node :foo" do
69
60
  build_hash @user, :node => [{ :name => :foo, :options => {}, :block => lambda { |u| "bar" } }]
@@ -78,7 +69,6 @@ context "Rabl::Builder" do
78
69
  end
79
70
 
80
71
  context "#child" do
81
-
82
72
  asserts "that it generates if no data present" do
83
73
  builder(:child => []).build(@user)
84
74
  end.equals({})
@@ -115,9 +105,7 @@ context "Rabl::Builder" do
115
105
  end.equivalent_to({ :users => 'xyz'})
116
106
  end
117
107
 
118
-
119
108
  context "#glue" do
120
-
121
109
  asserts "that it generates if no data present" do
122
110
  builder(:glue => []).build(@user)
123
111
  end.equals({})
@@ -141,7 +129,6 @@ context "Rabl::Builder" do
141
129
  end
142
130
 
143
131
  context "#extend" do
144
-
145
132
  asserts "that it does not genereate if no data is present" do
146
133
  b = builder :extends => [{ :file => 'users/show', :options => {}, :block => lambda { |u| attribute :name }}]
147
134
  mock(b).partial('users/show',{ :object => @user}).returns({}).subject
data/test/engine_test.rb CHANGED
@@ -17,6 +17,41 @@ context "Rabl::Engine" do
17
17
  asserts_topic.assigns :_options
18
18
  end
19
19
 
20
+ context "#cache" do
21
+ context "with cache" do
22
+ setup do
23
+ template = rabl %q{
24
+ cache 'foo'
25
+ }
26
+ template.render(Object.new)
27
+ template.instance_eval('@engine')
28
+ end
29
+
30
+ asserts_topic.assigns(:_cache) { ['foo', nil] }
31
+ end
32
+
33
+ context "with cache and options" do
34
+ setup do
35
+ template = rabl %q{
36
+ cache 'foo', expires_in: 'bar'
37
+ }
38
+ template.render(Object.new)
39
+ template.instance_eval('@engine')
40
+ end
41
+
42
+ asserts_topic.assigns(:_cache) { ['foo', { expires_in: 'bar' }] }
43
+ end
44
+
45
+ context "without cache" do
46
+ setup do
47
+ template = RablTemplate.new {}
48
+ template.render(Object.new)
49
+ template.instance_eval('@engine')
50
+ end
51
+
52
+ denies(:instance_variable_defined?, :@_cache)
53
+ end
54
+ end
20
55
 
21
56
  context "with defaults" do
22
57
  setup do
@@ -27,8 +62,19 @@ context "Rabl::Engine" do
27
62
  end
28
63
  end
29
64
 
30
- context "#object" do
65
+ context "#cache" do
66
+ asserts "does not modify output" do
67
+ template = rabl %q{
68
+ object @user
69
+ cache @user
70
+ }
71
+ scope = Object.new
72
+ scope.instance_variable_set :@user, User.new
73
+ template.render(scope)
74
+ end.matches "{\"user\":{}}"
75
+ end
31
76
 
77
+ context "#object" do
32
78
  asserts "that it sets data source" do
33
79
  template = rabl %q{
34
80
  object @user
@@ -47,7 +93,6 @@ context "Rabl::Engine" do
47
93
  template.render(scope)
48
94
  end.equals "{\"person\":{}}"
49
95
 
50
-
51
96
  asserts "that it can use non-ORM objects" do
52
97
  template = rabl %q{
53
98
  object @other
@@ -63,11 +108,9 @@ context "Rabl::Engine" do
63
108
  scope.instance_variable_set :@user, User.new
64
109
  template.render(scope)
65
110
  end.matches "{}"
66
-
67
111
  end
68
112
 
69
113
  context "#collection" do
70
-
71
114
  asserts "that it sets object to be casted as a simple array" do
72
115
  template = rabl %{
73
116
  collection @users
@@ -115,7 +158,6 @@ context "Rabl::Engine" do
115
158
  end
116
159
 
117
160
  context "#attribute" do
118
-
119
161
  asserts "that it adds an attribute or method to be included in output" do
120
162
  template = rabl %{
121
163
  object @user
@@ -145,11 +187,9 @@ context "Rabl::Engine" do
145
187
  scope.instance_variable_set :@user, User.new(:name => 'irvine')
146
188
  template.render(scope).split('').sort
147
189
  end.equals "{\"user\":{\"city\":\"irvine\"}}".split('').sort
148
-
149
190
  end
150
191
 
151
192
  context "#code" do
152
-
153
193
  asserts "that it can create an arbitraty code node" do
154
194
  template = rabl %{
155
195
  code(:foo) { 'bar' }
@@ -190,11 +230,9 @@ context "Rabl::Engine" do
190
230
  scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
191
231
  template.render(scope).split('').sort
192
232
  end.equals "{\"user\":{\"name\":\"leo\",\"user\":{\"city\":\"LA\"}}}".split('').sort
193
-
194
233
  end
195
234
 
196
235
  context "#child" do
197
-
198
236
  asserts "that it can create a child node" do
199
237
  template = rabl %{
200
238
  object @user
@@ -220,7 +258,6 @@ context "Rabl::Engine" do
220
258
  end
221
259
 
222
260
  context "#glue" do
223
-
224
261
  asserts "that it glues data from a child node" do
225
262
  template = rabl %{
226
263
  object @user
@@ -249,7 +286,6 @@ context "Rabl::Engine" do
249
286
  end
250
287
 
251
288
  context "#object" do
252
-
253
289
  asserts "that it sets data source" do
254
290
  template = rabl %q{
255
291
  object @user
@@ -270,7 +306,6 @@ context "Rabl::Engine" do
270
306
  end
271
307
 
272
308
  context "#collection" do
273
-
274
309
  asserts "that it sets object to be casted as a simple array" do
275
310
  template = rabl %{
276
311
  collection @users
@@ -289,7 +324,7 @@ context "Rabl::Engine" do
289
324
  template.render(scope)
290
325
  end.equals "{\"people\":[{},{}]}"
291
326
 
292
- asserts "that it sets root node for objects using root option" do
327
+ asserts "that it sets root node for objects using root option" do
293
328
  template = rabl %{
294
329
  collection @users, :root => :people
295
330
  }
@@ -309,7 +344,6 @@ context "Rabl::Engine" do
309
344
  end
310
345
 
311
346
  context "#attribute" do
312
-
313
347
  asserts "that it adds an attribute or method to be included in output" do
314
348
  template = rabl %{
315
349
  object @user
@@ -339,11 +373,9 @@ context "Rabl::Engine" do
339
373
  scope.instance_variable_set :@user, User.new(:name => 'irvine')
340
374
  template.render(scope)
341
375
  end.equals "{\"city\":\"irvine\"}"
342
-
343
376
  end
344
377
 
345
378
  context "#code" do
346
-
347
379
  asserts "that it can create an arbitraty code node" do
348
380
  template = rabl %{
349
381
  code(:foo) { 'bar' }
@@ -357,11 +389,9 @@ context "Rabl::Engine" do
357
389
  }
358
390
  template.render(Object.new)
359
391
  end.equals "{}"
360
-
361
392
  end
362
393
 
363
394
  context "#child" do
364
-
365
395
  asserts "that it can create a child node" do
366
396
  template = rabl %{
367
397
  object @user
@@ -385,7 +415,6 @@ context "Rabl::Engine" do
385
415
 
386
416
  end.equals "{\"name\":\"leo\",\"person\":{\"city\":\"LA\"}}".split('').sort
387
417
 
388
-
389
418
  asserts "that it can be passed conditionals" do
390
419
  template = rabl %{
391
420
  object @user
@@ -397,11 +426,9 @@ context "Rabl::Engine" do
397
426
  template.render(scope).split('').sort
398
427
 
399
428
  end.equals "{\"name\":\"leo\"}".split('').sort
400
-
401
429
  end
402
430
 
403
431
  context "#glue" do
404
-
405
432
  asserts "that it glues data from a child node" do
406
433
  template = rabl %{
407
434
  object @user
@@ -1,5 +1,6 @@
1
1
  require 'rack/test'
2
2
  require 'riot'
3
+ require 'riot/rr'
3
4
 
4
5
  Riot.pretty_dots
5
6
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rabl
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.1
5
+ version: 0.6.2
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-03-09 00:00:00 Z
13
+ date: 2012-03-21 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
@@ -152,12 +152,12 @@ files:
152
152
  - fixtures/ashared/models/post.rb
153
153
  - fixtures/ashared/models/user.rb
154
154
  - fixtures/ashared/views/layouts/application.html.erb
155
- - fixtures/ashared/views/posts/date.json.rabl
156
- - fixtures/ashared/views/posts/index.json.rabl
157
- - fixtures/ashared/views/posts/show.json.rabl
158
- - fixtures/ashared/views/users/index.rabl
159
- - fixtures/ashared/views/users/phone_number.rabl
160
- - fixtures/ashared/views/users/show.rabl
155
+ - fixtures/ashared/views/posts/date.rabl
156
+ - fixtures/ashared/views/posts/index.rabl
157
+ - fixtures/ashared/views/posts/show.rabl
158
+ - fixtures/ashared/views/users/index.json.rabl
159
+ - fixtures/ashared/views/users/phone_number.json.rabl
160
+ - fixtures/ashared/views/users/show.json.rabl
161
161
  - fixtures/padrino_test/.components
162
162
  - fixtures/padrino_test/.gitignore
163
163
  - fixtures/padrino_test/Gemfile
@@ -312,7 +312,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
312
312
  requirements: []
313
313
 
314
314
  rubyforge_project: rabl
315
- rubygems_version: 1.8.15
315
+ rubygems_version: 1.8.19
316
316
  signing_key:
317
317
  specification_version: 3
318
318
  summary: General ruby templating with json, bson, xml and msgpack support