rabl-rails 0.1.0 → 0.1.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 +9 -0
- data/Gemfile.lock +0 -2
- data/lib/rabl-rails/renderers/base.rb +6 -6
- data/lib/rabl-rails/renderers/json.rb +1 -1
- data/lib/rabl-rails/version.rb +1 -1
- data/rabl-rails.gemspec +0 -1
- data/test/deep_nesting_test.rb +2 -3
- data/test/renderers/json_renderer_test.rb +4 -5
- data/test/test_helper.rb +7 -2
- metadata +4 -19
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
@@ -3,11 +3,11 @@ module RablRails
|
|
3
3
|
class PartialError < StandardError; end
|
4
4
|
|
5
5
|
class Base
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :_options
|
7
7
|
|
8
8
|
def initialize(context) # :nodoc:
|
9
9
|
@_context = context
|
10
|
-
@
|
10
|
+
@_options = {}
|
11
11
|
setup_render_context
|
12
12
|
end
|
13
13
|
|
@@ -18,10 +18,10 @@ module RablRails
|
|
18
18
|
# method defined by the renderer.
|
19
19
|
#
|
20
20
|
def render(template)
|
21
|
-
collection_or_resource =
|
21
|
+
collection_or_resource = instance_variable_get(template.data) if template.data
|
22
22
|
output_hash = collection_or_resource.respond_to?(:each) ? render_collection(collection_or_resource, template.source) :
|
23
23
|
render_resource(collection_or_resource, template.source)
|
24
|
-
|
24
|
+
_options[:root_name] = template.root_name
|
25
25
|
format_output(output_hash)
|
26
26
|
end
|
27
27
|
|
@@ -54,7 +54,7 @@ module RablRails
|
|
54
54
|
when Hash
|
55
55
|
current_value = value.dup
|
56
56
|
data_symbol = current_value.delete(:_data)
|
57
|
-
object = data_symbol.nil? ? data : data_symbol.to_s.start_with?('@') ?
|
57
|
+
object = data_symbol.nil? ? data : data_symbol.to_s.start_with?('@') ? instance_variable_get(data_symbol) : data.send(data_symbol)
|
58
58
|
|
59
59
|
if key.to_s.start_with?('_') # glue
|
60
60
|
current_value.each_pair { |k, v|
|
@@ -108,7 +108,7 @@ module RablRails
|
|
108
108
|
#
|
109
109
|
def setup_render_context
|
110
110
|
@_context.instance_variable_get(:@_assigns).each_pair { |k, v|
|
111
|
-
instance_variable_set("@#{k}", v) unless k.start_with?('_')
|
111
|
+
instance_variable_set("@#{k}", v) unless k.start_with?('_')
|
112
112
|
}
|
113
113
|
end
|
114
114
|
end
|
@@ -2,7 +2,7 @@ module RablRails
|
|
2
2
|
module Renderers
|
3
3
|
class JSON < Base
|
4
4
|
def format_output(hash)
|
5
|
-
hash = {
|
5
|
+
hash = { _options[:root_name] => hash } if _options[:root_name] && RablRails.include_json_root
|
6
6
|
MultiJson.encode(hash)
|
7
7
|
end
|
8
8
|
end
|
data/lib/rabl-rails/version.rb
CHANGED
data/rabl-rails.gemspec
CHANGED
data/test/deep_nesting_test.rb
CHANGED
@@ -22,9 +22,8 @@ class DeepNestingTest < ActiveSupport::TestCase
|
|
22
22
|
@user.stub(:respond_to?).with(:each).and_return(false)
|
23
23
|
|
24
24
|
@context = Context.new
|
25
|
-
@context.
|
26
|
-
@context.
|
27
|
-
@context.stub(:instance_variable_get).with(:@_assigns).and_return({})
|
25
|
+
@context.assigns['user'] = @user
|
26
|
+
@context.virtual_path = 'users/show'
|
28
27
|
@context.stub(:lookup_context).and_return(mock(:find_template => mock(:source => %{ object :@comment\n attribute :content })))
|
29
28
|
end
|
30
29
|
|
@@ -7,8 +7,7 @@ class TestJsonRenderer < ActiveSupport::TestCase
|
|
7
7
|
@data.stub(:respond_to?).with(:each).and_return(false)
|
8
8
|
|
9
9
|
@context = Context.new
|
10
|
-
@context.
|
11
|
-
@context.stub(:instance_variable_get).with(:@_assigns).and_return({})
|
10
|
+
@context.assigns['data'] = @data
|
12
11
|
|
13
12
|
@template = RablRails::CompiledTemplate.new
|
14
13
|
@template.data = :@data
|
@@ -24,7 +23,7 @@ class TestJsonRenderer < ActiveSupport::TestCase
|
|
24
23
|
end
|
25
24
|
|
26
25
|
test "render collection with empty template" do
|
27
|
-
@context.
|
26
|
+
@context.assigns['data'] = [@data]
|
28
27
|
@template.source = {}
|
29
28
|
assert_equal %q([{}]), render_json_output
|
30
29
|
end
|
@@ -52,7 +51,7 @@ class TestJsonRenderer < ActiveSupport::TestCase
|
|
52
51
|
|
53
52
|
test "render collection with attributes" do
|
54
53
|
@data = [User.new(1, 'foo', 'male'), User.new(2, 'bar', 'female')]
|
55
|
-
@context.
|
54
|
+
@context.assigns['data'] = @data
|
56
55
|
@template.source = { :uid => :id, :name => :name, :gender => :sex }
|
57
56
|
assert_equal %q([{"uid":1,"name":"foo","gender":"male"},{"uid":2,"name":"bar","gender":"female"}]), render_json_output
|
58
57
|
end
|
@@ -87,8 +86,8 @@ class TestJsonRenderer < ActiveSupport::TestCase
|
|
87
86
|
|
88
87
|
test "partial should be evaluated at rendering time" do
|
89
88
|
# Set assigns
|
90
|
-
@context.stub(:instance_variable_get).with(:@_assigns).and_return({'user' => @data})
|
91
89
|
@data.stub(:respond_to?).with(:empty?).and_return(false)
|
90
|
+
@context.assigns['user'] = @data
|
92
91
|
|
93
92
|
# Stub Library#get
|
94
93
|
t = RablRails::CompiledTemplate.new
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabl-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.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: 2012-07-
|
12
|
+
date: 2012-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -43,22 +43,6 @@ dependencies:
|
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '3.0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: sqlite3
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
46
|
- !ruby/object:Gem::Dependency
|
63
47
|
name: actionpack
|
64
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,6 +67,7 @@ extensions: []
|
|
83
67
|
extra_rdoc_files: []
|
84
68
|
files:
|
85
69
|
- .gitignore
|
70
|
+
- CHANGELOG.md
|
86
71
|
- Gemfile
|
87
72
|
- Gemfile.lock
|
88
73
|
- MIT-LICENSE
|
@@ -126,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
111
|
version: '0'
|
127
112
|
requirements: []
|
128
113
|
rubyforge_project:
|
129
|
-
rubygems_version: 1.8.
|
114
|
+
rubygems_version: 1.8.22
|
130
115
|
signing_key:
|
131
116
|
specification_version: 3
|
132
117
|
summary: Fast Rails 3+ templating system with JSON and XML support
|