twig_ruby 0.0.5 → 0.0.7

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: 4e727b10dc2226c2da43a9a2b8e1cd4a2e1b5a18ffb16eca116611b0d0f307cf
4
- data.tar.gz: ef48d56a8bef43bd999cd17dc3def1371b58c12e4fba6c6bb143ba8b21dba6c4
3
+ metadata.gz: 90966ffc0c05d3421292e27ff238d6356c101a1d7300b585db5fb80922dcb9c4
4
+ data.tar.gz: 3fc2d04f821ef986cb7f208e4067d57e7fd48f4e1675fe9f3e295c8a1b875ccf
5
5
  SHA512:
6
- metadata.gz: 1cbec5dd395ca0c306ab6eee643aa5954e46cd3181985e55fac994a2eecbdc4473aaba91a344e9681ad1aa28be3e77980461da775a740e908ec2dbb2fdbf73dc
7
- data.tar.gz: fa32c024631b8cb528fb35463422b09e8b461ed75c1ef440bc4ccd8268686d928bcad868a82b9f98d5621a1e99047b2c4949589d7d967de23bcdf4ebe2b192ad
6
+ metadata.gz: a33188e0a3454ab3e62a8b9e210c514c5466edb6d5a54769a1da2b0d401692a7d1514c9424f6e23a8e94e5436510ff5215cbd6ca9c6af17da8be08a6de9ff993
7
+ data.tar.gz: c87bf1bf264bc50dec8a60d9b412dd80c43abbfe022325fe4e34711a6cc4549e38453039e438530296bff835b315e86836550e7af95e919bfc0854404070b318
@@ -256,7 +256,7 @@ class TwigFixture
256
256
  templates = {}
257
257
  test.scan(/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=--TEMPLATE|\z)/mx).map do |name, contents|
258
258
  templates[name || 'index.twig'] = contents.
259
- gsub(/[\n]*\z/, '').
259
+ gsub(/\n*\z/, '').
260
260
  gsub('d/m/Y H:i:s P', '%d/%m/%Y %H:%M:%S %:z'). # Change dates to Ruby format
261
261
  gsub('Twig\Tests\TwigTestFoo', 'TwigTestFoo') # Change class name to match Ruby
262
262
  end
@@ -871,7 +871,8 @@ module Twig
871
871
  (
872
872
  object.is_a?(Hash) && (
873
873
  object.key?(attribute) ||
874
- (attribute.respond_to?(:to_sym) && object.key?(attribute.to_sym))
874
+ (attribute.respond_to?(:to_sym) && object.key?(attribute.to_sym)) ||
875
+ (attribute.respond_to?(:to_s) && object.key?(attribute.to_s))
875
876
  )
876
877
  )
877
878
  )
@@ -880,11 +881,11 @@ module Twig
880
881
  return object[attribute] || (attribute.is_a?(String) ? object[attribute.to_sym] : object[attribute.to_s])
881
882
  end
882
883
 
883
- if defined_test
884
- return false
885
- end
886
-
887
884
  if type == Template::ARRAY_CALL
885
+ if defined_test
886
+ return false
887
+ end
888
+
888
889
  if ignore_strict_check || !environment.strict_variables?
889
890
  return
890
891
  end
@@ -893,7 +894,13 @@ module Twig
893
894
  end
894
895
  end
895
896
 
896
- if object.respond_to?(attribute)
897
+ responds_to = begin
898
+ object.respond_to?(attribute)
899
+ rescue StandardError
900
+ false
901
+ end
902
+
903
+ if responds_to
897
904
  if defined_test
898
905
  return true
899
906
  end
@@ -933,7 +940,7 @@ module Twig
933
940
  end
934
941
  end
935
942
  # Constant could be nil but we should return if we find it
936
- elsif (constant = get_constant(object, attribute)) && constant[0] == :found
943
+ elsif (constant = get_constant(object, attribute.to_s)) && constant[0] == :found
937
944
  constant[1]
938
945
  else
939
946
  return if ignore_strict_check || !environment.strict_variables?
data/lib/twig/parser.rb CHANGED
@@ -233,9 +233,8 @@ module Twig
233
233
  # try 2 word tests
234
234
  name = "#{name} #{current_token.value}"
235
235
 
236
- if (test = environment.test(name))
237
- stream.next
238
- end
236
+ test = environment.test(name)
237
+ stream.next
239
238
  else
240
239
  test = environment.test(name)
241
240
  end
@@ -19,9 +19,15 @@ module Twig
19
19
  end
20
20
 
21
21
  name_token = stream.expect(Token::NAME_TYPE)
22
+ name = name_token.value
23
+
24
+ if type_token.value == 'test' && stream.test(Token::NAME_TYPE)
25
+ name = "#{name} #{stream.current.value}"
26
+ stream.next
27
+ end
22
28
 
23
29
  begin
24
- exists = !parser.environment.send(type_token.value, name_token.value).nil?
30
+ exists = !parser.environment.send(type_token.value, name).nil?
25
31
  rescue Error::Syntax
26
32
  exists = false
27
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twig_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Blanchette
8
8
  - Fabian Potencier
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-05 00:00:00.000000000 Z
11
+ date: 2025-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport