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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1111e4a55512ff1a1c0c01c82e4a180d107387b687ea8caf4b0753b4207f3f02
4
- data.tar.gz: 5abf4c9493fdaf45de25ed18f328f92595a484ec4e11b7ed1c87278a55748cb6
3
+ metadata.gz: b49886a65ba68f1102f4c03b3054c6f0efd4cc576a1083e627981a8832986902
4
+ data.tar.gz: b5a5cf59633ba153be413a974bd32d6128d6e56e6f901e4a16afce9380f30e94
5
5
  SHA512:
6
- metadata.gz: 91be26b34ba29c6cfe18038c3c1c78889c0723540483a663571f32482e3d6d7eff6a6fac44603627f516b21beba7f0355c656b1fce3545d6277cb294c52f027e
7
- data.tar.gz: 56597ac885f021695f130bde7924309592e1f69154a117276c19d0ca56b2165b7a0d77fbfb79669885225976895440ee9464909f765f1d5ffce31d7ea4f13c24
6
+ metadata.gz: 85339a87b7bd1c5769cde431f56111d787d80091ba96872aba477b160084bdd18c416a469f1cd05677f0caec667a897e4908503914fc969fe536eb1f26e9a095
7
+ data.tar.gz: ae31dff4f46df762ca97ba74e26077b75885809e094848cbaf37cdc65fc9035e1fdf0543c7220d49707cf4d11f883ef38f60644ed1edf6d7d0efa8d54036aa50
@@ -396,10 +396,24 @@ module Tina4
396
396
  end
397
397
 
398
398
  def resolve_variable(expr)
399
- parts = expr.split(".")
399
+ parts = split_dot_parts(expr)
400
400
  value = @context
401
401
  parts.each do |part|
402
- if part =~ /\A(\w+)\[(.+?)\]\z/
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tina4
4
- VERSION = "3.10.1"
4
+ VERSION = "3.10.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tina4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.1
4
+ version: 3.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tina4 Team