rabl 0.11.5 → 0.11.6
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 +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -2
- data/fixtures/rails4/Gemfile +1 -1
- data/lib/rabl/builder.rb +13 -27
- data/lib/rabl/engine.rb +6 -4
- data/lib/rabl/helpers.rb +2 -1
- data/lib/rabl/template.rb +3 -3
- data/lib/rabl/version.rb +1 -1
- data/test/builder_test.rb +51 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 852d10093718c0d837774cbb5503b64cd7474305
|
4
|
+
data.tar.gz: 39d7b1d6c51be9b181431d127b8e19456bcda4a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46aaee2c97be7740ec16880d9fa59fec495cc136e11854a9685137e593c06c8325e3fd4e9a07e929fe0d2c3b22b1aa8ab6a8319c90048f8882474779316d380f
|
7
|
+
data.tar.gz: a574e74f6489c8bbb40ce57c1d6ad8738d1d634f9fe9bc793eabf5a0dea6421329ad94a0f1ff22927ba6b31c69bb9499c087ba7eef12457627717fe7a100277f
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.11.6 (January 26th)
|
4
|
+
|
5
|
+
* Fix resolve_condition and simplify call_condition_proc (@vmeyet)
|
6
|
+
* Respect eagerly loaded collections by not always calling #to_ary (@DouweM)
|
7
|
+
* Move creation of options and engine in tilt template to avoid threading issues (@jseriff)
|
8
|
+
|
3
9
|
## 0.11.5 (December 5th)
|
4
10
|
|
5
11
|
* Check if context_scope includes ".settings.views" for Sinatra (@LTe)
|
data/Gemfile
CHANGED
@@ -3,7 +3,6 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in rabl.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem 'rake', :require => false
|
7
6
|
gem 'i18n', '~> 0.6'
|
8
7
|
|
9
8
|
platforms :mri_18 do
|
@@ -12,7 +11,7 @@ platforms :mri_18 do
|
|
12
11
|
end
|
13
12
|
|
14
13
|
group :test do
|
15
|
-
# RABL TEST
|
14
|
+
# RABL TEST
|
16
15
|
gem 'builder'
|
17
16
|
|
18
17
|
# FIXTURES
|
data/fixtures/rails4/Gemfile
CHANGED
data/lib/rabl/builder.rb
CHANGED
@@ -45,7 +45,7 @@ module Rabl
|
|
45
45
|
@_object = object if object
|
46
46
|
@options.merge!(options) if options
|
47
47
|
@settings.merge!(settings) if settings
|
48
|
-
|
48
|
+
|
49
49
|
cache_results do
|
50
50
|
@_result = {}
|
51
51
|
|
@@ -196,37 +196,23 @@ module Rabl
|
|
196
196
|
engines << partial_as_engine(file, options, &block)
|
197
197
|
end
|
198
198
|
|
199
|
-
# Evaluate conditions given a symbol to evaluate
|
200
|
-
def call_condition_proc(condition, object
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
block.call(condition.call(object))
|
206
|
-
elsif condition.is_a?(Symbol) && object.respond_to?(condition)
|
207
|
-
# condition is a property of the object
|
208
|
-
block.call(object.send(condition))
|
209
|
-
else
|
210
|
-
false
|
211
|
-
end
|
199
|
+
# Evaluate conditions given a symbol/proc/lambda/variable to evaluate
|
200
|
+
def call_condition_proc(condition, object)
|
201
|
+
# This will evaluate lambda, proc & symbol and call it with 1 argument
|
202
|
+
return condition.to_proc.call(object) if condition.respond_to?(:to_proc)
|
203
|
+
# Else we send directly the object
|
204
|
+
condition
|
212
205
|
end
|
213
206
|
|
214
207
|
# resolve_condition(:if => true) => true
|
208
|
+
# resolve_condition(:if => 'Im truthy') => true
|
215
209
|
# resolve_condition(:if => lambda { |m| false }) => false
|
216
|
-
# resolve_condition(:unless => lambda { |m|
|
210
|
+
# resolve_condition(:unless => lambda { |m| false }) => true
|
211
|
+
# resolve_condition(:unless => lambda { |m| false }, :if => proc { true}) => true
|
217
212
|
def resolve_condition(options)
|
218
|
-
|
219
|
-
|
220
|
-
result
|
221
|
-
if options.has_key?(:if)
|
222
|
-
result = options[:if] == true || call_condition_proc(options[:if], @_object)
|
223
|
-
end
|
224
|
-
|
225
|
-
if options.has_key?(:unless)
|
226
|
-
inverse_proc = lambda { |r| !r }
|
227
|
-
result = options[:unless] == false || call_condition_proc(options[:unless], @_object, &inverse_proc)
|
228
|
-
end
|
229
|
-
|
213
|
+
result = true
|
214
|
+
result &&= call_condition_proc(options[:if], @_object) if options.key?(:if)
|
215
|
+
result &&= !call_condition_proc(options[:unless], @_object) if options.key?(:unless)
|
230
216
|
result
|
231
217
|
end
|
232
218
|
|
data/lib/rabl/engine.rb
CHANGED
@@ -163,9 +163,11 @@ module Rabl
|
|
163
163
|
def object(template_data)
|
164
164
|
current_data = (@_locals[:object].nil? || template_data == false) ? template_data : @_locals[:object]
|
165
165
|
@_data_object = data_object(current_data)
|
166
|
-
@
|
166
|
+
@_root_name_data = template_data.is_a?(Hash) && !current_data.is_a?(Hash) ? template_data : current_data
|
167
|
+
@_root_name_data = @_root_name_data.values.first if @_root_name_data.is_a?(Hash)
|
167
168
|
|
168
|
-
|
169
|
+
# If we turn this around, `@_root_name_date ==` may trigger data to be loaded unnecessarily.
|
170
|
+
if false == @_root_name_data
|
169
171
|
@_object_root_name = false
|
170
172
|
@_collection_name = false
|
171
173
|
end
|
@@ -185,7 +187,7 @@ module Rabl
|
|
185
187
|
return @_data_name if defined?(@_data_name)
|
186
188
|
|
187
189
|
@_data_name = @_options[:object_root_name] || begin
|
188
|
-
data = @_locals[:object].nil? ? root_object : @_locals[:object]
|
190
|
+
data = defined?(@_root_name_data) ? @_root_name_data : (@_locals[:object].nil? ? root_object : @_locals[:object])
|
189
191
|
data_name(data)
|
190
192
|
end
|
191
193
|
end
|
@@ -201,7 +203,7 @@ module Rabl
|
|
201
203
|
|
202
204
|
@_object_root_name = options[:object_root] if options.has_key?(:object_root)
|
203
205
|
|
204
|
-
object(
|
206
|
+
object(data_object(data) || [])
|
205
207
|
end
|
206
208
|
|
207
209
|
# Sets the cache key to be used by ActiveSupport::Cache.expand_cache_key
|
data/lib/rabl/helpers.rb
CHANGED
@@ -35,7 +35,8 @@ module Rabl
|
|
35
35
|
data = data_object(data_token)
|
36
36
|
|
37
37
|
if is_collection?(data) # data is a collection
|
38
|
-
object_name =
|
38
|
+
object_name = collection_root_name if collection_root_name
|
39
|
+
object_name ||= data.table_name if data.respond_to?(:table_name)
|
39
40
|
|
40
41
|
if object_name.nil? && data.respond_to?(:first)
|
41
42
|
first = data.first
|
data/lib/rabl/template.rb
CHANGED
@@ -7,12 +7,12 @@ if defined?(Tilt)
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def prepare
|
10
|
-
|
11
|
-
@engine = ::Rabl::Engine.new(data, options)
|
10
|
+
#left empty so each invocation has a new hash of options and new rabl engine for thread safety
|
12
11
|
end
|
13
12
|
|
14
13
|
def evaluate(context_scope, locals, &block)
|
15
|
-
@
|
14
|
+
options = @options.merge(:source_location => file)
|
15
|
+
::Rabl::Engine.new(data, options).apply(context_scope, locals, &block).render
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/lib/rabl/version.rb
CHANGED
data/test/builder_test.rb
CHANGED
@@ -299,9 +299,59 @@ context "Rabl::Builder" do
|
|
299
299
|
scope.send :resolve_condition, { :unless => :cool? }
|
300
300
|
end.equals(true)
|
301
301
|
|
302
|
-
asserts "that it can use symbols as
|
302
|
+
asserts "that it can use symbols as unless condition and return false if method returns true" do
|
303
303
|
scope = Rabl::Builder.new(ArbObj.new)
|
304
304
|
scope.send :resolve_condition, { :unless => :smooth? }
|
305
305
|
end.equals(false)
|
306
|
+
|
307
|
+
asserts "that it can use :unless and :if at the same time and return true when if is true and unless is false" do
|
308
|
+
scope = Rabl::Builder.new(ArbObj.new)
|
309
|
+
scope.send :resolve_condition, { :if => true, :unless => false }
|
310
|
+
end.equals(true)
|
311
|
+
|
312
|
+
asserts "that it can use :unless and :if at the same time and return false when if is false and unless is false" do
|
313
|
+
scope = Rabl::Builder.new(ArbObj.new)
|
314
|
+
scope.send :resolve_condition, { :if => false, :unless => false }
|
315
|
+
end.equals(false)
|
316
|
+
|
317
|
+
asserts "that it can use :unless and :if at the same time and return false when if is true and unless is true" do
|
318
|
+
scope = Rabl::Builder.new(ArbObj.new)
|
319
|
+
scope.send :resolve_condition, { :if => true, :unless => true }
|
320
|
+
end.equals(false)
|
321
|
+
|
322
|
+
asserts "that it can use :unless and :if at the same time and return false when if is false and unless is true" do
|
323
|
+
scope = Rabl::Builder.new(ArbObj.new)
|
324
|
+
scope.send :resolve_condition, { :if => false, :unless => true }
|
325
|
+
end.equals(false)
|
326
|
+
|
327
|
+
asserts "that it can use lambda on if condition and return false if lambda returns false" do
|
328
|
+
scope = Rabl::Builder.new(ArbObj.new)
|
329
|
+
scope.send(:resolve_condition, { :if => lambda { |obj| false } })
|
330
|
+
end.equals(false)
|
331
|
+
|
332
|
+
asserts "that it can use lambda on if condition and return true if lambda returns true" do
|
333
|
+
scope = Rabl::Builder.new(ArbObj.new)
|
334
|
+
scope.send(:resolve_condition, { :if => lambda { |obj| true } })
|
335
|
+
end.equals(true)
|
336
|
+
|
337
|
+
asserts "that it can use proc on if condition and return false if proc returns false" do
|
338
|
+
scope = Rabl::Builder.new(ArbObj.new)
|
339
|
+
scope.send(:resolve_condition, { :if => proc { false } })
|
340
|
+
end.equals(false)
|
341
|
+
|
342
|
+
asserts "that it can use proc on if condition and return true if proc returns true" do
|
343
|
+
scope = Rabl::Builder.new(ArbObj.new)
|
344
|
+
scope.send(:resolve_condition, { :if => proc { true } })
|
345
|
+
end.equals(true)
|
346
|
+
|
347
|
+
asserts "that it can use a variable on if condition and return true if variable is truthy" do
|
348
|
+
scope = Rabl::Builder.new(ArbObj.new)
|
349
|
+
scope.send(:resolve_condition, { :if => 'Im truthy' })
|
350
|
+
end.equals('Im truthy')
|
351
|
+
|
352
|
+
asserts "that it can use a variable on if condition and return false if variable is falsy" do
|
353
|
+
scope = Rabl::Builder.new(ArbObj.new)
|
354
|
+
scope.send(:resolve_condition, { :if => nil })
|
355
|
+
end.equals(nil)
|
306
356
|
end
|
307
357
|
end
|
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.11.
|
4
|
+
version: 0.11.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Esquenazi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|