twig_ruby 0.0.4 → 0.0.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/README.md +9 -1
- data/lib/tasks/twig_parity.rake +1 -1
- data/lib/twig/extension/core.rb +12 -6
- data/lib/twig/node/expression/name.rb +2 -7
- data/lib/twig/runtime/context.rb +18 -0
- data/lib/twig/token_parser/yield.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a2cec3c9f7ff1aee90cc8728a14a711376ecfb5c0dcad92d02bd4e25a926a91
|
4
|
+
data.tar.gz: dca954724b75bea4b3ed372371791e2cdc16d6f1e8a6429d876e4d5e14ed34f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdaf2674839c428dc0a784c4173407d89ddce53027342a33c81ca550335ea9bbc3b4c609ded535d8249eed06f2d45e3d544f4419cf9e303b2c51a9f8fe08e197
|
7
|
+
data.tar.gz: 69dab9d2e128182be3d75a1948d3c4c1cc79b392121ce87c091bae7fa1c52c5fe7ec123102d85615eb2430ffa1454b158ab25139e9f5a55d8639bb4a18becb96
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Implementation of [Twig](https://twig.symfony.com/) in Ruby.
|
|
21
21
|
## Installation
|
22
22
|
|
23
23
|
```bash
|
24
|
-
bundle add
|
24
|
+
bundle add twig_ruby
|
25
25
|
```
|
26
26
|
|
27
27
|
## Quick Start
|
@@ -187,6 +187,14 @@ can be used with helpers like `form_with`
|
|
187
187
|
{{ f.email_field(:email) }}
|
188
188
|
{% endyield %}
|
189
189
|
```
|
190
|
+
|
191
|
+
Rails helpers can also be called. Parenthesis is only required when passing arguments:
|
192
|
+
|
193
|
+
```twig
|
194
|
+
{{ stylesheet_link_tag(:app, "data-turbo-track": "reload") }}
|
195
|
+
{{ javascript_importmap_tags }}
|
196
|
+
```
|
197
|
+
|
190
198
|
### Cache Tag
|
191
199
|
|
192
200
|
The way the `cache` tag works in Rails is that it captures output from the buffer that
|
data/lib/tasks/twig_parity.rake
CHANGED
@@ -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(
|
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
|
data/lib/twig/extension/core.rb
CHANGED
@@ -880,11 +880,11 @@ module Twig
|
|
880
880
|
return object[attribute] || (attribute.is_a?(String) ? object[attribute.to_sym] : object[attribute.to_s])
|
881
881
|
end
|
882
882
|
|
883
|
-
if defined_test
|
884
|
-
return false
|
885
|
-
end
|
886
|
-
|
887
883
|
if type == Template::ARRAY_CALL
|
884
|
+
if defined_test
|
885
|
+
return false
|
886
|
+
end
|
887
|
+
|
888
888
|
if ignore_strict_check || !environment.strict_variables?
|
889
889
|
return
|
890
890
|
end
|
@@ -893,7 +893,13 @@ module Twig
|
|
893
893
|
end
|
894
894
|
end
|
895
895
|
|
896
|
-
|
896
|
+
responds_to = begin
|
897
|
+
object.respond_to?(attribute)
|
898
|
+
rescue StandardError
|
899
|
+
false
|
900
|
+
end
|
901
|
+
|
902
|
+
if responds_to
|
897
903
|
if defined_test
|
898
904
|
return true
|
899
905
|
end
|
@@ -933,7 +939,7 @@ module Twig
|
|
933
939
|
end
|
934
940
|
end
|
935
941
|
# Constant could be nil but we should return if we find it
|
936
|
-
elsif (constant = get_constant(object, attribute)) && constant[0] == :found
|
942
|
+
elsif (constant = get_constant(object, attribute.to_s)) && constant[0] == :found
|
937
943
|
constant[1]
|
938
944
|
else
|
939
945
|
return if ignore_strict_check || !environment.strict_variables?
|
@@ -30,13 +30,8 @@ module Twig
|
|
30
30
|
|
31
31
|
compiler.add_debug_info(self)
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
get = "context.call_context.instance_variable_get('#{name}')"
|
36
|
-
else
|
37
|
-
check = "context.key?(:#{name})"
|
38
|
-
get = "context[:#{name}]"
|
39
|
-
end
|
33
|
+
check = "context.has?(:#{name})"
|
34
|
+
get = "context.get(:#{name})"
|
40
35
|
|
41
36
|
if define_test_enabled?
|
42
37
|
if attributes[:always_defined] || SPECIAL_VARS.key?(name)
|
data/lib/twig/runtime/context.rb
CHANGED
@@ -52,6 +52,24 @@ module Twig
|
|
52
52
|
self.class.new(other, call_context:, output_buffer:)
|
53
53
|
end
|
54
54
|
|
55
|
+
def has?(name)
|
56
|
+
if name[0] == '@'
|
57
|
+
call_context.instance_variable_defined?(name)
|
58
|
+
else
|
59
|
+
key?(name) || call_context.respond_to?(name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def get(name)
|
64
|
+
if name[0] == '@'
|
65
|
+
call_context.instance_variable_get(name)
|
66
|
+
elsif key?(name)
|
67
|
+
self[name]
|
68
|
+
elsif call_context.respond_to?(name)
|
69
|
+
call_context.send(name)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
55
73
|
def push_stack
|
56
74
|
stack.push({ remove: [], replace: {} })
|
57
75
|
end
|
@@ -27,6 +27,16 @@ module Twig
|
|
27
27
|
body = parser.subparse(method(:decide_yield_end), drop_needle: true)
|
28
28
|
stream.expect(Token::BLOCK_END_TYPE)
|
29
29
|
|
30
|
+
# If it's a context variable, turn it into a helper method
|
31
|
+
# ex: {% yield turbo_frame_tag do %}
|
32
|
+
if expr.is_a?(Node::Expression::Variable::Context)
|
33
|
+
expr = Node::Expression::HelperMethod.new(
|
34
|
+
expr.attributes[:name],
|
35
|
+
Node::Nodes.new({}),
|
36
|
+
lineno
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
30
40
|
Node::Yield.new(expr, body, arguments, lineno)
|
31
41
|
end
|
32
42
|
|
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.
|
4
|
+
version: 0.0.6
|
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-
|
11
|
+
date: 2025-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|