rabl 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -6
- data/CHANGELOG.md +4 -0
- data/lib/rabl/builder.rb +6 -6
- data/lib/rabl/digestor.rb +27 -1
- data/lib/rabl/engine.rb +5 -7
- data/lib/rabl/helpers.rb +6 -10
- data/lib/rabl/template.rb +1 -1
- data/lib/rabl/version.rb +1 -1
- data/rabl.gemspec +1 -3
- data/test/builder_test.rb +1 -1
- data/test/helpers_test.rb +7 -1
- data/test/plist_engine_test.rb +24 -24
- data/test/renderer_test.rb +1 -1
- metadata +25 -50
- data/Gemfile.ci +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9181c1a232aab327e58bd686eb3cf14403e6aac9
|
4
|
+
data.tar.gz: 3e2f0d536f6752cb575e5843709be0b40f8bd09a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ea05c8211d750c882c4b0fa6e29a20b56e4ebfcff23e12a2af18e0f50302b191be374a76eace11ed46a787ae702cb7ff5eb7ef659a6d7096db2823451c5b6d1
|
7
|
+
data.tar.gz: c8634ea3cfbbc11e131b484e598326888c81f15f2a304caf06ec786f8a3ab5d72cfb77f88fc47b4fd34d1dc595c3468ef5c460d44effc949c352dd6ca23d7398
|
data/.travis.yml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
#
|
1
|
+
# https://docs.travis-ci.com/user/customizing-the-build/
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
2
4
|
rvm:
|
3
|
-
- 1.8.7
|
4
5
|
- 1.9.3
|
5
6
|
- 2.0.0
|
6
7
|
- 2.1
|
7
8
|
- 2.2
|
8
|
-
|
9
|
+
- 2.3.1
|
9
10
|
notifications:
|
10
11
|
recipients:
|
11
12
|
- nesquena@gmail.com
|
12
13
|
- databyte@gmail.com
|
13
|
-
|
14
|
-
|
15
|
-
- rvm: 1.8.7
|
14
|
+
before_install:
|
15
|
+
- gem install bundler
|
data/CHANGELOG.md
CHANGED
data/lib/rabl/builder.rb
CHANGED
@@ -15,7 +15,7 @@ module Rabl
|
|
15
15
|
# options = { :format => "json", :root => true, :child_root => true,
|
16
16
|
# :attributes, :node, :child, :glue, :extends }
|
17
17
|
#
|
18
|
-
def initialize(object, settings = {}, options = {}
|
18
|
+
def initialize(object, settings = {}, options = {})
|
19
19
|
@_object = object
|
20
20
|
|
21
21
|
@settings = settings
|
@@ -41,7 +41,7 @@ module Rabl
|
|
41
41
|
engines[engines.index(engine)] = value
|
42
42
|
end
|
43
43
|
|
44
|
-
def to_hash(object = nil, settings =
|
44
|
+
def to_hash(object = nil, settings = nil, options = nil)
|
45
45
|
@_object = object if object
|
46
46
|
@options.merge!(options) if options
|
47
47
|
@settings.merge!(settings) if settings
|
@@ -168,9 +168,9 @@ module Rabl
|
|
168
168
|
name = is_name_value?(options[:root]) ? options[:root] : data_name(data)
|
169
169
|
object = data_object(data)
|
170
170
|
|
171
|
-
|
172
|
-
engine_options =
|
173
|
-
engine_options
|
171
|
+
engine_options = @options.slice(:child_root)
|
172
|
+
engine_options[:root] = is_collection?(object) && options.fetch(:object_root, @options[:child_root]) # child @users
|
173
|
+
engine_options[:object_root_name] = options[:object_root] if is_name_value?(options[:object_root])
|
174
174
|
|
175
175
|
object = { object => name } if data.is_a?(Hash) && object # child :users => :people
|
176
176
|
|
@@ -192,7 +192,7 @@ module Rabl
|
|
192
192
|
def extends(file, options = {}, &block)
|
193
193
|
return unless resolve_condition(options)
|
194
194
|
|
195
|
-
options = @options.slice(:child_root).merge(:object => @_object).merge(options)
|
195
|
+
options = @options.slice(:child_root).merge!(:object => @_object).merge!(options)
|
196
196
|
engines << partial_as_engine(file, options, &block)
|
197
197
|
end
|
198
198
|
|
data/lib/rabl/digestor.rb
CHANGED
@@ -2,7 +2,33 @@ module Rabl
|
|
2
2
|
class Digestor < ActionView::Digestor
|
3
3
|
# Override the original digest function to ignore partial which
|
4
4
|
# rabl doesn't use the Rails conventional _ symbol.
|
5
|
-
if Gem::Version.new(Rails.version) >= Gem::Version.new('
|
5
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('5.0.0.beta1')
|
6
|
+
def self.digest(name:, finder:, **options)
|
7
|
+
|
8
|
+
options.assert_valid_keys(:dependencies, :partial)
|
9
|
+
|
10
|
+
cache_key = ([ name ].compact + Array.wrap(options[:dependencies])).join('.')
|
11
|
+
|
12
|
+
# this is a correctly done double-checked locking idiom
|
13
|
+
# (Concurrent::Map's lookups have volatile semantics)
|
14
|
+
finder.digest_cache[cache_key] || @@digest_monitor.synchronize do
|
15
|
+
finder.digest_cache.fetch(cache_key) do # re-check under lock
|
16
|
+
begin
|
17
|
+
# Prevent re-entry or else recursive templates will blow the stack.
|
18
|
+
# There is no need to worry about other threads seeing the +false+ value,
|
19
|
+
# as they will then have to wait for this thread to let go of the @@digest_monitor lock.
|
20
|
+
|
21
|
+
pre_stored = finder.digest_cache.put_if_absent(cache_key, false).nil? # put_if_absent returns nil on insertion
|
22
|
+
|
23
|
+
finder.digest_cache[cache_key] = stored_digest = Digestor.new(name, finder, options).digest
|
24
|
+
ensure
|
25
|
+
# something went wrong or ActionView::Resolver.caching? is false, make sure not to corrupt the @@cache
|
26
|
+
finder.digest_cache.delete_pair(cache_key, false) if pre_stored && !stored_digest
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
elsif Gem::Version.new(Rails.version) >= Gem::Version.new('4.1')
|
6
32
|
def self.digest(options = {})
|
7
33
|
cache_key = [options[:name]] + Array.wrap(options[:dependencies])
|
8
34
|
@@cache[cache_key.join('.')] ||= begin
|
data/lib/rabl/engine.rb
CHANGED
@@ -75,7 +75,7 @@ module Rabl
|
|
75
75
|
# Returns a hash representation of the data object
|
76
76
|
# to_hash(:root => true, :child_root => true)
|
77
77
|
def to_hash(options = {})
|
78
|
-
options
|
78
|
+
options.reverse_merge!(@_options)
|
79
79
|
|
80
80
|
data = root_object
|
81
81
|
|
@@ -94,9 +94,7 @@ module Rabl
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def to_dumpable(options = {})
|
97
|
-
options
|
98
|
-
:child_root => Rabl.configuration.include_child_root
|
99
|
-
}.merge(options)
|
97
|
+
options.reverse_merge!({ :child_root => Rabl.configuration.include_child_root })
|
100
98
|
|
101
99
|
result = to_hash(options)
|
102
100
|
result = { collection_root_name => result } if collection_root_name
|
@@ -106,7 +104,7 @@ module Rabl
|
|
106
104
|
# Returns a json representation of the data object
|
107
105
|
# to_json(:root => true)
|
108
106
|
def to_json(options = {})
|
109
|
-
options
|
107
|
+
options.reverse_merge!({ :root => Rabl.configuration.include_json_root })
|
110
108
|
result = to_dumpable(options)
|
111
109
|
format_json(result)
|
112
110
|
end
|
@@ -263,7 +261,7 @@ module Rabl
|
|
263
261
|
# Extends an existing rabl template with additional attributes in the block
|
264
262
|
# extends("users/show", :object => @user) { attribute :full_name }
|
265
263
|
def extends(file, options = {}, &block)
|
266
|
-
options
|
264
|
+
options.reverse_merge!({ :view_path => options[:view_path] || view_path })
|
267
265
|
|
268
266
|
@_settings[:extends] << { :file => file, :options => options, :block => block }
|
269
267
|
end
|
@@ -357,7 +355,7 @@ module Rabl
|
|
357
355
|
end
|
358
356
|
|
359
357
|
def copy_instance_variables_from(object, exclude = []) #:nodoc:
|
360
|
-
vars = object.instance_variables
|
358
|
+
vars = object.instance_variables - exclude
|
361
359
|
vars.each { |name| instance_variable_set(name, object.instance_variable_get(name)) }
|
362
360
|
end
|
363
361
|
|
data/lib/rabl/helpers.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
require 'active_support/inflector' # for the sake of pluralizing
|
2
|
-
require 'set'
|
3
2
|
|
4
3
|
module Rabl
|
5
4
|
module Helpers
|
6
|
-
# Set of class names known to be objects, not collections
|
7
|
-
KNOWN_OBJECT_CLASSES = Set.new(['Struct', 'Hashie::Mash'])
|
8
|
-
|
9
5
|
# data_object(data) => <AR Object>
|
10
6
|
# data_object(@user => :person) => @user
|
11
7
|
# data_object(:user => :person) => @_object.send(:user)
|
@@ -86,7 +82,7 @@ module Rabl
|
|
86
82
|
def is_collection?(obj, follow_symbols = true)
|
87
83
|
data_obj = follow_symbols ? data_object(obj) : obj
|
88
84
|
data_obj && data_obj.respond_to?(:map) && data_obj.respond_to?(:each) &&
|
89
|
-
|
85
|
+
!(data_obj.is_a?(Struct) || defined?(Hashie::Mash) && data_obj.is_a?(Hashie::Mash))
|
90
86
|
end
|
91
87
|
|
92
88
|
# Returns the context_scope wrapping this engine, used for retrieving data, invoking methods, etc
|
@@ -127,12 +123,12 @@ module Rabl
|
|
127
123
|
def object_to_engine(object, options = {}, &block)
|
128
124
|
return if object.nil?
|
129
125
|
|
130
|
-
options
|
131
|
-
:format => "hash",
|
132
|
-
:view_path => view_path,
|
126
|
+
options.reverse_merge!({
|
127
|
+
:format => "hash".freeze,
|
128
|
+
:view_path => view_path,
|
133
129
|
:root => (options[:root] || false)
|
134
|
-
}
|
135
|
-
|
130
|
+
})
|
131
|
+
|
136
132
|
Engine.new(options[:source], options).apply(context_scope, :object => object, :locals => options[:locals], &block)
|
137
133
|
end
|
138
134
|
|
data/lib/rabl/template.rb
CHANGED
@@ -46,7 +46,7 @@ if defined?(ActionView) && defined?(Rails) && Rails.respond_to?(:version) && Rai
|
|
46
46
|
module Template::Handlers
|
47
47
|
class Rabl
|
48
48
|
class_attribute :default_format
|
49
|
-
self.default_format = Mime
|
49
|
+
self.default_format = Mime[:json]
|
50
50
|
|
51
51
|
def self.call(template)
|
52
52
|
source = template.source
|
data/lib/rabl/version.rb
CHANGED
data/rabl.gemspec
CHANGED
@@ -16,11 +16,9 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.rubyforge_project = "rabl"
|
17
17
|
|
18
18
|
s.files = `git ls-files`.split("\n")
|
19
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
19
|
s.require_paths = ["lib"]
|
22
20
|
|
23
|
-
|
21
|
+
|
24
22
|
if RUBY_VERSION < "1.9"
|
25
23
|
s.add_dependency 'activesupport', '>= 2.3.14', '<= 4'
|
26
24
|
else
|
data/test/builder_test.rb
CHANGED
@@ -357,6 +357,6 @@ context "Rabl::Builder" do
|
|
357
357
|
asserts "that it can use a hash variable on if condition and return true" do
|
358
358
|
scope = Rabl::Builder.new(ArbObj.new)
|
359
359
|
scope.send(:resolve_condition, { :if => { some: 'data' } })
|
360
|
-
end.equals(
|
360
|
+
end.equals({some: 'data'})
|
361
361
|
end
|
362
362
|
end
|
data/test/helpers_test.rb
CHANGED
@@ -122,9 +122,15 @@ context "Rabl::Helpers" do
|
|
122
122
|
@helper_class.is_collection?([@user])
|
123
123
|
end.equals(true)
|
124
124
|
|
125
|
-
asserts "returns
|
125
|
+
asserts "returns false for a Hashie::Mash with 1 key" do
|
126
126
|
obj = Hashie::Mash.new({:name => 'hello'})
|
127
127
|
@helper_class.is_collection?(obj)
|
128
128
|
end.equals(false)
|
129
|
+
|
130
|
+
asserts "returns false for a Hashie::Mash with 2 keys" do
|
131
|
+
obj = Hashie::Mash.new({:name => 'hello', :key2 => 'key2'})
|
132
|
+
@helper_class.is_collection?(obj)
|
133
|
+
end.equals(false)
|
134
|
+
|
129
135
|
end # is_collection method
|
130
136
|
end
|
data/test/plist_engine_test.rb
CHANGED
@@ -20,7 +20,7 @@ context "Rabl::Engine" do
|
|
20
20
|
scope = Object.new
|
21
21
|
scope.instance_variable_set :@user, User.new
|
22
22
|
template.render(scope)
|
23
|
-
end.matches "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
23
|
+
end.matches "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict/>\n</dict>\n</plist>\n"
|
24
24
|
|
25
25
|
asserts "that it can set root node" do
|
26
26
|
template = rabl %q{
|
@@ -29,7 +29,7 @@ context "Rabl::Engine" do
|
|
29
29
|
scope = Object.new
|
30
30
|
scope.instance_variable_set :@user, User.new
|
31
31
|
template.render(scope).split("").sort
|
32
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
32
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>person</key>\n\t<dict/>\n</dict>\n</plist>\n".split("").sort
|
33
33
|
end
|
34
34
|
|
35
35
|
context "#collection" do
|
@@ -40,7 +40,7 @@ context "Rabl::Engine" do
|
|
40
40
|
scope = Object.new
|
41
41
|
scope.instance_variable_set :@users, [User.new, User.new]
|
42
42
|
template.render(scope).split("").sort
|
43
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
43
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<array>\n\t<dict>\n\t\t<key>user</key>\n\t\t<dict/>\n\t</dict>\n\t<dict>\n\t\t<key>user</key>\n\t\t<dict/>\n\t</dict>\n</array>\n</plist>\n".split("").sort
|
44
44
|
|
45
45
|
asserts "that it sets root node for objects" do
|
46
46
|
template = rabl %{
|
@@ -49,7 +49,7 @@ context "Rabl::Engine" do
|
|
49
49
|
scope = Object.new
|
50
50
|
scope.instance_variable_set :@users, [User.new, User.new]
|
51
51
|
template.render(scope).split("").sort
|
52
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
52
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>person</key>\n\t<array>\n\t\t<dict>\n\t\t\t<key>person</key>\n\t\t\t<dict/>\n\t\t</dict>\n\t\t<dict>\n\t\t\t<key>person</key>\n\t\t\t<dict/>\n\t\t</dict>\n\t</array>\n</dict>\n</plist>\n".split("").sort
|
53
53
|
end
|
54
54
|
|
55
55
|
context "#attribute" do
|
@@ -61,7 +61,7 @@ context "Rabl::Engine" do
|
|
61
61
|
scope = Object.new
|
62
62
|
scope.instance_variable_set :@user, User.new(:name => 'irvine')
|
63
63
|
template.render(scope).split("").sort
|
64
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
64
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>name</key>\n\t\t<string>irvine</string>\n\t</dict>\n</dict>\n</plist>\n".split("").sort
|
65
65
|
|
66
66
|
asserts "that it can add attribute under a different key name through :as" do
|
67
67
|
template = rabl %{
|
@@ -71,7 +71,7 @@ context "Rabl::Engine" do
|
|
71
71
|
scope = Object.new
|
72
72
|
scope.instance_variable_set :@user, User.new(:name => 'irvine')
|
73
73
|
template.render(scope).split("").sort
|
74
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
74
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>city</key>\n\t\t<string>irvine</string>\n\t</dict>\n</dict>\n</plist>\n".split("").sort
|
75
75
|
|
76
76
|
asserts "that it can add attribute under a different key name through hash" do
|
77
77
|
template = rabl %{
|
@@ -81,7 +81,7 @@ context "Rabl::Engine" do
|
|
81
81
|
scope = Object.new
|
82
82
|
scope.instance_variable_set :@user, User.new(:name => 'irvine')
|
83
83
|
template.render(scope).split("").sort
|
84
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
84
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>city</key>\n\t\t<string>irvine</string>\n\t</dict>\n</dict>\n</plist>\n".split("").sort
|
85
85
|
end
|
86
86
|
|
87
87
|
context "#code" do
|
@@ -90,14 +90,14 @@ context "Rabl::Engine" do
|
|
90
90
|
code(:foo) { 'bar' }
|
91
91
|
}
|
92
92
|
template.render(Object.new).split("").sort
|
93
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
93
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>foo</key>\n\t<string>bar</string>\n</dict>\n</plist>\n".split("").sort
|
94
94
|
|
95
95
|
asserts "that it can be passed conditionals" do
|
96
96
|
template = rabl %{
|
97
97
|
code(:foo, :if => lambda { |i| false }) { 'bar' }
|
98
98
|
}
|
99
99
|
template.render(Object.new).split("").sort
|
100
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
100
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict/>\n</plist>\n".split("").sort
|
101
101
|
end
|
102
102
|
|
103
103
|
context "#child" do
|
@@ -109,7 +109,7 @@ context "Rabl::Engine" do
|
|
109
109
|
scope = Object.new
|
110
110
|
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
|
111
111
|
template.render(scope).split("").sort
|
112
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
112
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>user</key>\n\t\t<dict>\n\t\t\t<key>city</key>\n\t\t\t<string>LA</string>\n\t\t</dict>\n\t</dict>\n</dict>\n</plist>\n".split("").sort
|
113
113
|
|
114
114
|
asserts "that it can create a child node with different key" do
|
115
115
|
template = rabl %{
|
@@ -120,7 +120,7 @@ context "Rabl::Engine" do
|
|
120
120
|
scope = Object.new
|
121
121
|
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
|
122
122
|
template.render(scope)
|
123
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
123
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>name</key>\n\t\t<string>leo</string>\n\t\t<key>person</key>\n\t\t<dict>\n\t\t\t<key>city</key>\n\t\t\t<string>LA</string>\n\t\t</dict>\n\t</dict>\n</dict>\n</plist>\n"
|
124
124
|
end
|
125
125
|
|
126
126
|
context "#glue" do
|
@@ -134,7 +134,7 @@ context "Rabl::Engine" do
|
|
134
134
|
scope = Object.new
|
135
135
|
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12)
|
136
136
|
template.render(scope)
|
137
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
137
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>age</key>\n\t\t<integer>12</integer>\n\t\t<key>city</key>\n\t\t<string>LA</string>\n\t\t<key>name</key>\n\t\t<string>leo</string>\n\t</dict>\n</dict>\n</plist>\n"
|
138
138
|
end
|
139
139
|
|
140
140
|
teardown do
|
@@ -184,7 +184,7 @@ context "Rabl::Engine" do
|
|
184
184
|
scope = Object.new
|
185
185
|
scope.instance_variable_set :@user, User.new
|
186
186
|
template.render(scope)
|
187
|
-
end.matches "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
187
|
+
end.matches "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict/>\n</plist>\n"
|
188
188
|
|
189
189
|
asserts "that it can set root node" do
|
190
190
|
template = rabl %q{
|
@@ -193,7 +193,7 @@ context "Rabl::Engine" do
|
|
193
193
|
scope = Object.new
|
194
194
|
scope.instance_variable_set :@user, User.new
|
195
195
|
template.render(scope)
|
196
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
196
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict/>\n</plist>\n"
|
197
197
|
end
|
198
198
|
|
199
199
|
context "#collection" do
|
@@ -204,7 +204,7 @@ context "Rabl::Engine" do
|
|
204
204
|
scope = Object.new
|
205
205
|
scope.instance_variable_set :@users, [User.new, User.new]
|
206
206
|
template.render(scope)
|
207
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
207
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<array>\n\t<dict/>\n\t<dict/>\n</array>\n</plist>\n"
|
208
208
|
|
209
209
|
asserts "that it sets root node for objects" do
|
210
210
|
template = rabl %{
|
@@ -213,7 +213,7 @@ context "Rabl::Engine" do
|
|
213
213
|
scope = Object.new
|
214
214
|
scope.instance_variable_set :@users, [User.new, User.new]
|
215
215
|
template.render(scope)
|
216
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
216
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>person</key>\n\t<array>\n\t\t<dict/>\n\t\t<dict/>\n\t</array>\n</dict>\n</plist>\n"
|
217
217
|
end
|
218
218
|
|
219
219
|
context "#attribute" do
|
@@ -225,7 +225,7 @@ context "Rabl::Engine" do
|
|
225
225
|
scope = Object.new
|
226
226
|
scope.instance_variable_set :@user, User.new(:name => 'irvine')
|
227
227
|
template.render(scope)
|
228
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
228
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>name</key>\n\t<string>irvine</string>\n</dict>\n</plist>\n"
|
229
229
|
|
230
230
|
asserts "that it can add attribute under a different key name through :as" do
|
231
231
|
template = rabl %{
|
@@ -235,7 +235,7 @@ context "Rabl::Engine" do
|
|
235
235
|
scope = Object.new
|
236
236
|
scope.instance_variable_set :@user, User.new(:name => 'irvine')
|
237
237
|
template.render(scope)
|
238
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
238
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>city</key>\n\t<string>irvine</string>\n</dict>\n</plist>\n"
|
239
239
|
|
240
240
|
asserts "that it can add attribute under a different key name through hash" do
|
241
241
|
template = rabl %{
|
@@ -245,7 +245,7 @@ context "Rabl::Engine" do
|
|
245
245
|
scope = Object.new
|
246
246
|
scope.instance_variable_set :@user, User.new(:name => 'irvine')
|
247
247
|
template.render(scope)
|
248
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
248
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>city</key>\n\t<string>irvine</string>\n</dict>\n</plist>\n"
|
249
249
|
end
|
250
250
|
|
251
251
|
context "#code" do
|
@@ -254,14 +254,14 @@ context "Rabl::Engine" do
|
|
254
254
|
code(:foo) { 'bar' }
|
255
255
|
}
|
256
256
|
template.render(Object.new)
|
257
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
257
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>foo</key>\n\t<string>bar</string>\n</dict>\n</plist>\n"
|
258
258
|
|
259
259
|
asserts "that it can be passed conditionals" do
|
260
260
|
template = rabl %{
|
261
261
|
code(:foo, :if => lambda { |i| false }) { 'bar' }
|
262
262
|
}
|
263
263
|
template.render(Object.new)
|
264
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
264
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict/>\n</plist>\n"
|
265
265
|
end
|
266
266
|
|
267
267
|
context "#child" do
|
@@ -273,7 +273,7 @@ context "Rabl::Engine" do
|
|
273
273
|
scope = Object.new
|
274
274
|
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
|
275
275
|
template.render(scope).split("").sort
|
276
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
276
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>city</key>\n\t\t<string>LA</string>\n\t</dict>\n</dict>\n</plist>\n".split("").sort
|
277
277
|
|
278
278
|
asserts "that it can create a child node with different key" do
|
279
279
|
template = rabl %{
|
@@ -284,7 +284,7 @@ context "Rabl::Engine" do
|
|
284
284
|
scope = Object.new
|
285
285
|
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
|
286
286
|
template.render(scope)
|
287
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
287
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>name</key>\n\t<string>leo</string>\n\t<key>person</key>\n\t<dict>\n\t\t<key>city</key>\n\t\t<string>LA</string>\n\t</dict>\n</dict>\n</plist>\n"
|
288
288
|
end
|
289
289
|
|
290
290
|
context "#glue" do
|
@@ -298,7 +298,7 @@ context "Rabl::Engine" do
|
|
298
298
|
scope = Object.new
|
299
299
|
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA', :age => 12)
|
300
300
|
template.render(scope)
|
301
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
301
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>age</key>\n\t<integer>12</integer>\n\t<key>city</key>\n\t<string>LA</string>\n\t<key>name</key>\n\t<string>leo</string>\n</dict>\n</plist>\n"
|
302
302
|
end
|
303
303
|
|
304
304
|
teardown do
|
data/test/renderer_test.rb
CHANGED
@@ -385,6 +385,6 @@ context "Rabl::Renderer" do
|
|
385
385
|
|
386
386
|
user = User.new(:name => 'ivan')
|
387
387
|
Rabl::Renderer.plist(user, 'test', :view_path => tmp_path)
|
388
|
-
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple
|
388
|
+
end.equals "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>user</key>\n\t<dict>\n\t\t<key>age</key>\n\t\t<integer>24</integer>\n\t\t<key>float</key>\n\t\t<real>1234.56</real>\n\t\t<key>name</key>\n\t\t<string>ivan</string>\n\t</dict>\n</dict>\n</plist>\n"
|
389
389
|
end
|
390
390
|
end
|
metadata
CHANGED
@@ -1,139 +1,139 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Esquenazi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.3.14
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.3.14
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: riot
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.12.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.12.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rr
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 1.0.2
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.0.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: tilt
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: oj
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: msgpack
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - ~>
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: 0.4.5
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - ~>
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 0.4.5
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: bson
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - ~>
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: 1.7.0
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - ~>
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 1.7.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: plist
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
description: General ruby templating with json, bson, xml and msgpack support
|
@@ -143,12 +143,11 @@ executables: []
|
|
143
143
|
extensions: []
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
|
-
- .gitignore
|
147
|
-
- .travis.yml
|
146
|
+
- ".gitignore"
|
147
|
+
- ".travis.yml"
|
148
148
|
- CHANGELOG.md
|
149
149
|
- CONTRIBUTING.md
|
150
150
|
- Gemfile
|
151
|
-
- Gemfile.ci
|
152
151
|
- MIT-LICENSE
|
153
152
|
- README.md
|
154
153
|
- Rakefile
|
@@ -458,12 +457,12 @@ require_paths:
|
|
458
457
|
- lib
|
459
458
|
required_ruby_version: !ruby/object:Gem::Requirement
|
460
459
|
requirements:
|
461
|
-
- -
|
460
|
+
- - ">="
|
462
461
|
- !ruby/object:Gem::Version
|
463
462
|
version: '0'
|
464
463
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
465
464
|
requirements:
|
466
|
-
- -
|
465
|
+
- - ">="
|
467
466
|
- !ruby/object:Gem::Version
|
468
467
|
version: '0'
|
469
468
|
requirements: []
|
@@ -472,28 +471,4 @@ rubygems_version: 2.4.8
|
|
472
471
|
signing_key:
|
473
472
|
specification_version: 4
|
474
473
|
summary: General ruby templating with json, bson, xml and msgpack support
|
475
|
-
test_files:
|
476
|
-
- test/bson_engine_test.rb
|
477
|
-
- test/builder_test.rb
|
478
|
-
- test/configuration_test.rb
|
479
|
-
- test/engine_test.rb
|
480
|
-
- test/helpers_test.rb
|
481
|
-
- test/integration/posts_controller_test.rb
|
482
|
-
- test/integration/rails3_2/posts_controller_test.rb
|
483
|
-
- test/integration/rails3_2/users_controller_test.rb
|
484
|
-
- test/integration/rails4/posts_controller_test.rb
|
485
|
-
- test/integration/rails4/users_controller_test.rb
|
486
|
-
- test/integration/test_init.rb
|
487
|
-
- test/integration/users_controller_test.rb
|
488
|
-
- test/models/ormless.rb
|
489
|
-
- test/models/user.rb
|
490
|
-
- test/msgpack_engine_test.rb
|
491
|
-
- test/multi_builder_test.rb
|
492
|
-
- test/partials_test.rb
|
493
|
-
- test/plist_engine_test.rb
|
494
|
-
- test/renderer_test.rb
|
495
|
-
- test/silence.rb
|
496
|
-
- test/template_test.rb
|
497
|
-
- test/teststrap.rb
|
498
|
-
- test/xml_test.rb
|
499
|
-
has_rdoc:
|
474
|
+
test_files: []
|