twig_ruby 0.0.4 → 0.0.5
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/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: 4e727b10dc2226c2da43a9a2b8e1cd4a2e1b5a18ffb16eca116611b0d0f307cf
|
4
|
+
data.tar.gz: ef48d56a8bef43bd999cd17dc3def1371b58c12e4fba6c6bb143ba8b21dba6c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cbec5dd395ca0c306ab6eee643aa5954e46cd3181985e55fac994a2eecbdc4473aaba91a344e9681ad1aa28be3e77980461da775a740e908ec2dbb2fdbf73dc
|
7
|
+
data.tar.gz: fa32c024631b8cb528fb35463422b09e8b461ed75c1ef440bc4ccd8268686d928bcad868a82b9f98d5621a1e99047b2c4949589d7d967de23bcdf4ebe2b192ad
|
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
|
@@ -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.5
|
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-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|