rabl 0.9.0.pre2 → 0.9.0.pre3
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.
- checksums.yaml +8 -8
- data/CHANGELOG.md +4 -0
- data/fixtures/ashared/views_rails_3/posts/renderer.rabl +4 -0
- data/fixtures/rails3_2/app/controllers/posts_controller.rb +5 -0
- data/fixtures/rails3_2/config/routes.rb +5 -1
- data/fixtures/rails3_2/test/functional/posts_controller_test.rb +12 -0
- data/fixtures/rails4/Gemfile +2 -2
- data/fixtures/rails4/app/controllers/posts_controller.rb +5 -0
- data/fixtures/rails4/config/routes.rb +5 -1
- data/fixtures/rails4/test/functional/posts_controller_test.rb +12 -0
- data/lib/rabl/engine.rb +2 -3
- data/lib/rabl/partials.rb +5 -0
- data/lib/rabl/version.rb +1 -1
- data/rabl.gemspec +1 -0
- data/test/builder_test.rb +7 -0
- data/test/engine_test.rb +1 -1
- data/test/integration/rails3_2/posts_controller_test.rb +12 -0
- data/test/integration/rails4/posts_controller_test.rb +12 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWZkODhjODJlYzViMTk1Y2U1MTEyZjVhZjNjZmU3OWZlNjk3YTRmOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjIwMzgzZjM4NGQ5Njk3NWJlZWQ0ZDY0ODNlNTZjY2UyODMzOWM2Yw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjJiZDhjOTI4N2EwNTIyMTRkZDE5MTFlYTU2YjhlOTczOWJmYWViZjljMjY0
|
10
|
+
ZWU3ZTFkOGQwMjFjY2Y1ZjlkOWZjM2Q1ZjAyZTM0ZjM1Yzk3YmI4OThhYTFm
|
11
|
+
MWU5MjY0ODgxMzllNDEwZGM3OTY0NzNhNDE0OWE4ZThhZmE1NzQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmNhNjEyNDg2YjYzZGE0NWJmYzIyMjUxN2NkNDQ5NTBiZDZjOTlmZTA4NzRh
|
14
|
+
NDI3ZGE3NzliNzMxYmQ3M2RhYzgwMDc1ZTMzYzI4N2YxZDY1YTY1OWVhMzQ5
|
15
|
+
NTNmMmE3NTk4NWUyMGQ2YzQzYzJiMDg1YzY1MzliZDExNWI4NWY=
|
data/CHANGELOG.md
CHANGED
@@ -8,4 +8,9 @@ class PostsController < ApplicationController
|
|
8
8
|
def show
|
9
9
|
@post = Post.find(params[:id])
|
10
10
|
end
|
11
|
+
|
12
|
+
def renderer
|
13
|
+
post = Post.find(params[:id])
|
14
|
+
render json: Rabl.render(post, 'posts/renderer', view_path: 'app/views', format: :json, scope: view_context)
|
15
|
+
end
|
11
16
|
end
|
@@ -139,6 +139,18 @@ context "PostsController" do
|
|
139
139
|
asserts("contains post attributes via node") { topic["post"] }.equals { [@post1.title, @post1.body] }
|
140
140
|
end # show action, json
|
141
141
|
|
142
|
+
context "renderer" do
|
143
|
+
setup do
|
144
|
+
mock(ActionController::Base).perform_caching.any_number_of_times { true }
|
145
|
+
get "/posts/#{@post1.id}/renderer"
|
146
|
+
json_output['post']
|
147
|
+
end
|
148
|
+
|
149
|
+
# Attributes (regular)
|
150
|
+
asserts("contains post title") { topic['title'] }.equals { @post1.title }
|
151
|
+
asserts("contains post body") { topic['body'] }.equals { @post1.body }
|
152
|
+
end # renderer action, json
|
153
|
+
|
142
154
|
context "for index action rendering JSON within HTML" do
|
143
155
|
setup do
|
144
156
|
get "/posts", format: :html
|
data/fixtures/rails4/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
4
|
-
gem 'rails', '4.0.0
|
4
|
+
gem 'rails', '4.0.0'
|
5
5
|
|
6
6
|
# Use sqlite3 as the database for Active Record
|
7
7
|
gem 'sqlite3'
|
@@ -9,7 +9,7 @@ gem 'rabl', :path => File.expand_path(File.dirname(__FILE__) + "/../../")
|
|
9
9
|
gem 'riot', :group => "test"
|
10
10
|
|
11
11
|
# Use SCSS for stylesheets
|
12
|
-
gem 'sass-rails', '~> 4.0.0
|
12
|
+
gem 'sass-rails', '~> 4.0.0'
|
13
13
|
|
14
14
|
# Use Uglifier as compressor for JavaScript assets
|
15
15
|
gem 'uglifier', '>= 1.3.0'
|
@@ -8,4 +8,9 @@ class PostsController < ApplicationController
|
|
8
8
|
def show
|
9
9
|
@post = Post.find(params[:id])
|
10
10
|
end
|
11
|
+
|
12
|
+
def renderer
|
13
|
+
post = Post.find(params[:id])
|
14
|
+
render json: Rabl.render(post, 'posts/renderer', view_path: 'app/views', format: :json, scope: view_context)
|
15
|
+
end
|
11
16
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
Rails4::Application.routes.draw do
|
2
2
|
resources :users
|
3
|
-
resources :posts
|
3
|
+
resources :posts do
|
4
|
+
member do
|
5
|
+
get 'renderer'
|
6
|
+
end
|
7
|
+
end
|
4
8
|
# The priority is based upon order of creation: first created -> highest priority.
|
5
9
|
# See how all your routes lay out with "rake routes".
|
6
10
|
|
@@ -139,6 +139,18 @@ context "PostsController" do
|
|
139
139
|
asserts("contains post attributes via node") { topic["post"] }.equals { [@post1.title, @post1.body] }
|
140
140
|
end # show action, json
|
141
141
|
|
142
|
+
context "renderer" do
|
143
|
+
setup do
|
144
|
+
mock(ActionController::Base).perform_caching.any_number_of_times { true }
|
145
|
+
get "/posts/#{@post1.id}/renderer"
|
146
|
+
json_output['post']
|
147
|
+
end
|
148
|
+
|
149
|
+
# Attributes (regular)
|
150
|
+
asserts("contains post title") { topic['title'] }.equals { @post1.title }
|
151
|
+
asserts("contains post body") { topic['body'] }.equals { @post1.body }
|
152
|
+
end # renderer action, json
|
153
|
+
|
142
154
|
context "for index action rendering JSON within HTML" do
|
143
155
|
setup do
|
144
156
|
get "/posts", format: :html
|
data/lib/rabl/engine.rb
CHANGED
@@ -287,17 +287,16 @@ module Rabl
|
|
287
287
|
end
|
288
288
|
|
289
289
|
def cache_key_with_digest(cache_key)
|
290
|
+
virtual_path = @_virtual_path ? @_virtual_path : @virtual_path
|
290
291
|
Array(cache_key) + [
|
291
292
|
@_options[:root_name],
|
292
293
|
@_options[:format],
|
293
|
-
Digestor.digest(
|
294
|
+
Digestor.digest(virtual_path, :rabl, lookup_context, dependencies: view_cache_dependencies)
|
294
295
|
]
|
295
296
|
end
|
296
297
|
|
297
298
|
def cache_key_simple(key)
|
298
299
|
Array(key) + [@_options[:root_name], @_options[:format]]
|
299
300
|
end
|
300
|
-
|
301
|
-
|
302
301
|
end
|
303
302
|
end
|
data/lib/rabl/partials.rb
CHANGED
@@ -43,6 +43,11 @@ module Rabl
|
|
43
43
|
fetch_manual_template(view_paths, file)
|
44
44
|
end
|
45
45
|
|
46
|
+
# being used by cache digestor
|
47
|
+
if defined?(Rails) && Rails.version =~ /^[4]/
|
48
|
+
@_virtual_path = file_path.gsub('app/views/', '').gsub('.rabl', '')
|
49
|
+
end
|
50
|
+
|
46
51
|
unless File.exist?(file_path.to_s)
|
47
52
|
raise "Cannot find rabl template '#{file}' within registered (#{view_paths.map(&:to_s).inspect}) view paths!"
|
48
53
|
end
|
data/lib/rabl/version.rb
CHANGED
data/rabl.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = "https://github.com/nesquena/rabl"
|
12
12
|
s.summary = %q{General ruby templating with json, bson, xml and msgpack support}
|
13
13
|
s.description = %q{General ruby templating with json, bson, xml and msgpack support}
|
14
|
+
s.license = 'MIT'
|
14
15
|
|
15
16
|
s.rubyforge_project = "rabl"
|
16
17
|
|
data/test/builder_test.rb
CHANGED
@@ -129,6 +129,13 @@ context "Rabl::Builder" do
|
|
129
129
|
mock(b).object_to_hash(@users, { :root => false, :child_root => false }).returns('xyz').subject
|
130
130
|
b.build(@user)
|
131
131
|
end.equivalent_to({ :users => 'xyz'})
|
132
|
+
|
133
|
+
asserts "that it generates with an collection and a specified object_root_name and root" do
|
134
|
+
ops = { :object_root => "person", :root => :people }
|
135
|
+
b = builder :child => [{ :data => @users, :options => ops, :block => lambda { |u| attribute :name } }], :child_root => true
|
136
|
+
mock(b).object_to_hash(@users, { :root => "person", :object_root_name => "person", :child_root => true }).returns('xyz').subject
|
137
|
+
b.build(@user)
|
138
|
+
end.equivalent_to({ :people => 'xyz'})
|
132
139
|
end
|
133
140
|
|
134
141
|
context "#glue" do
|
data/test/engine_test.rb
CHANGED
@@ -329,7 +329,7 @@ context "Rabl::Engine" do
|
|
329
329
|
template.render(scope)
|
330
330
|
end.equals "{\"user\":{\"name\":\"leo\",\"users\":[{\"person\":{\"city\":\"UNO\"}},{\"person\":{\"city\":\"DOS\"}}]}}"
|
331
331
|
|
332
|
-
asserts "it allows modification of both
|
332
|
+
asserts "it allows modification of both labels for a child collection" do
|
333
333
|
template = rabl %{
|
334
334
|
object @user
|
335
335
|
attribute :name
|
@@ -139,6 +139,18 @@ context "PostsController" do
|
|
139
139
|
asserts("contains post attributes via node") { topic["post"] }.equals { [@post1.title, @post1.body] }
|
140
140
|
end # show action, json
|
141
141
|
|
142
|
+
context "renderer" do
|
143
|
+
setup do
|
144
|
+
mock(ActionController::Base).perform_caching.any_number_of_times { true }
|
145
|
+
get "/posts/#{@post1.id}/renderer"
|
146
|
+
json_output['post']
|
147
|
+
end
|
148
|
+
|
149
|
+
# Attributes (regular)
|
150
|
+
asserts("contains post title") { topic['title'] }.equals { @post1.title }
|
151
|
+
asserts("contains post body") { topic['body'] }.equals { @post1.body }
|
152
|
+
end # renderer action, json
|
153
|
+
|
142
154
|
context "for index action rendering JSON within HTML" do
|
143
155
|
setup do
|
144
156
|
get "/posts", format: :html
|
@@ -139,6 +139,18 @@ context "PostsController" do
|
|
139
139
|
asserts("contains post attributes via node") { topic["post"] }.equals { [@post1.title, @post1.body] }
|
140
140
|
end # show action, json
|
141
141
|
|
142
|
+
context "renderer" do
|
143
|
+
setup do
|
144
|
+
mock(ActionController::Base).perform_caching.any_number_of_times { true }
|
145
|
+
get "/posts/#{@post1.id}/renderer"
|
146
|
+
json_output['post']
|
147
|
+
end
|
148
|
+
|
149
|
+
# Attributes (regular)
|
150
|
+
asserts("contains post title") { topic['title'] }.equals { @post1.title }
|
151
|
+
asserts("contains post body") { topic['body'] }.equals { @post1.body }
|
152
|
+
end # renderer action, json
|
153
|
+
|
142
154
|
context "for index action rendering JSON within HTML" do
|
143
155
|
setup do
|
144
156
|
get "/posts", format: :html
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.0.
|
4
|
+
version: 0.9.0.pre3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Esquenazi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- fixtures/ashared/views_rails_3/posts/date.rabl
|
178
178
|
- fixtures/ashared/views_rails_3/posts/index.html.erb
|
179
179
|
- fixtures/ashared/views_rails_3/posts/index.rabl
|
180
|
+
- fixtures/ashared/views_rails_3/posts/renderer.rabl
|
180
181
|
- fixtures/ashared/views_rails_3/posts/show.html.erb
|
181
182
|
- fixtures/ashared/views_rails_3/posts/show.rabl
|
182
183
|
- fixtures/ashared/views_rails_3/posts/show.rabl_test_v1.rabl
|
@@ -445,7 +446,8 @@ files:
|
|
445
446
|
- test/teststrap.rb
|
446
447
|
- test/xml_test.rb
|
447
448
|
homepage: https://github.com/nesquena/rabl
|
448
|
-
licenses:
|
449
|
+
licenses:
|
450
|
+
- MIT
|
449
451
|
metadata: {}
|
450
452
|
post_install_message:
|
451
453
|
rdoc_options: []
|