tina4ruby 3.10.1 → 3.10.2
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/lib/tina4/template.rb +39 -2
- data/lib/tina4/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b49886a65ba68f1102f4c03b3054c6f0efd4cc576a1083e627981a8832986902
|
|
4
|
+
data.tar.gz: b5a5cf59633ba153be413a974bd32d6128d6e56e6f901e4a16afce9380f30e94
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 85339a87b7bd1c5769cde431f56111d787d80091ba96872aba477b160084bdd18c416a469f1cd05677f0caec667a897e4908503914fc969fe536eb1f26e9a095
|
|
7
|
+
data.tar.gz: ae31dff4f46df762ca97ba74e26077b75885809e094848cbaf37cdc65fc9035e1fdf0543c7220d49707cf4d11f883ef38f60644ed1edf6d7d0efa8d54036aa50
|
data/lib/tina4/template.rb
CHANGED
|
@@ -396,10 +396,24 @@ module Tina4
|
|
|
396
396
|
end
|
|
397
397
|
|
|
398
398
|
def resolve_variable(expr)
|
|
399
|
-
parts = expr
|
|
399
|
+
parts = split_dot_parts(expr)
|
|
400
400
|
value = @context
|
|
401
401
|
parts.each do |part|
|
|
402
|
-
if part =~ /\A(\w+)\
|
|
402
|
+
if part =~ /\A(\w+)\((.*)?\)\z/m
|
|
403
|
+
# Method call: e.g. t("key") or greet("hello", "world")
|
|
404
|
+
method_name = Regexp.last_match(1)
|
|
405
|
+
args_str = Regexp.last_match(2)
|
|
406
|
+
callable = access_value(value, method_name)
|
|
407
|
+
if callable.respond_to?(:call)
|
|
408
|
+
args = args_str && !args_str.strip.empty? ? parse_filter_args(args_str) : []
|
|
409
|
+
value = callable.call(*args)
|
|
410
|
+
elsif callable.respond_to?(method_name.to_sym)
|
|
411
|
+
args = args_str && !args_str.strip.empty? ? parse_filter_args(args_str) : []
|
|
412
|
+
value = callable.send(method_name.to_sym, *args)
|
|
413
|
+
else
|
|
414
|
+
return nil
|
|
415
|
+
end
|
|
416
|
+
elsif part =~ /\A(\w+)\[(.+?)\]\z/
|
|
403
417
|
base = Regexp.last_match(1)
|
|
404
418
|
index = Regexp.last_match(2)
|
|
405
419
|
value = access_value(value, base)
|
|
@@ -417,6 +431,29 @@ module Tina4
|
|
|
417
431
|
value
|
|
418
432
|
end
|
|
419
433
|
|
|
434
|
+
# Split expression on dots, but not dots inside parentheses
|
|
435
|
+
def split_dot_parts(expr)
|
|
436
|
+
parts = []
|
|
437
|
+
current = +""
|
|
438
|
+
depth = 0
|
|
439
|
+
expr.each_char do |ch|
|
|
440
|
+
if ch == "("
|
|
441
|
+
depth += 1
|
|
442
|
+
current << ch
|
|
443
|
+
elsif ch == ")"
|
|
444
|
+
depth -= 1
|
|
445
|
+
current << ch
|
|
446
|
+
elsif ch == "." && depth == 0
|
|
447
|
+
parts << current
|
|
448
|
+
current = +""
|
|
449
|
+
else
|
|
450
|
+
current << ch
|
|
451
|
+
end
|
|
452
|
+
end
|
|
453
|
+
parts << current unless current.empty?
|
|
454
|
+
parts
|
|
455
|
+
end
|
|
456
|
+
|
|
420
457
|
def access_value(obj, key)
|
|
421
458
|
return nil if obj.nil?
|
|
422
459
|
if obj.is_a?(Hash)
|
data/lib/tina4/version.rb
CHANGED