hanami-view 3.0.0 → 3.0.1
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/CHANGELOG.md +12 -1
- data/lib/hanami/view/renderer.rb +28 -5
- data/lib/hanami/view/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: cfd4f5b396df91cbef8969c45d2619115365a83856411998e92f9bf9ba35d027
|
|
4
|
+
data.tar.gz: fd73d60f403a32f11a4261caf786dc33ba7f53c891edbf50dfcfe44f2445fb5c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c7958b7d98292e6595c0abde96ce7ba136d2ac75d2036d415668ded39a6a44435349b5fa6ea0bf87486e3a7c55ff54bce5be971a62bc7b70e5d2cad18dad4ff9
|
|
7
|
+
data.tar.gz: 4baa7d74944594e1af1357ed042b1cae7cc1577200e026f9da575142ac199824dece54a67158bf1a3e1f1a698ac72774e01433d20052d306fa8d3a0a670d08e4
|
data/CHANGELOG.md
CHANGED
|
@@ -19,7 +19,18 @@ and this project adheres to [Break Versioning](https://www.taoensso.com/break-ve
|
|
|
19
19
|
|
|
20
20
|
### Security
|
|
21
21
|
|
|
22
|
-
[Unreleased]: https://github.com/hanami/view/compare/v3.0.
|
|
22
|
+
[Unreleased]: https://github.com/hanami/view/compare/v3.0.1...HEAD
|
|
23
|
+
|
|
24
|
+
## [3.0.1] - 2026-08-14
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- Report the calling template as the current template name inside blocks passed to `render`, instead of the partial the block is yielded into. (@timriley in #281)
|
|
29
|
+
- Look up bare-named partials in the directory containing the template that renders them, instead of a same-named directory at the root. (@timriley in #282)
|
|
30
|
+
|
|
31
|
+
Previously, a partial rendered via a relative path (e.g. `render("shared/fields")` from `posts/show`) would look for its own bare-named partials under `shared/` at the root, rather than `posts/shared/`.
|
|
32
|
+
|
|
33
|
+
[3.0.1]: https://github.com/hanami/view/compare/v3.0.0...v3.0.1
|
|
23
34
|
|
|
24
35
|
## [3.0.0] - 2026-06-30
|
|
25
36
|
|
data/lib/hanami/view/renderer.rb
CHANGED
|
@@ -16,7 +16,7 @@ module Hanami
|
|
|
16
16
|
# rendered, its parent directory (e.g. `"users"` for `"users/index"`) is pushed onto the stack
|
|
17
17
|
# so that a partial referenced by its bare name (e.g. `render("form")` from inside
|
|
18
18
|
# `users/index.html.erb`) can be found alongside the template that renders it. The stack is
|
|
19
|
-
#
|
|
19
|
+
# snapshot-and-restored around each render via `ensure`.
|
|
20
20
|
#
|
|
21
21
|
# `#lookup` tries every combination of a path and a prefix, joining each pair with the
|
|
22
22
|
# requested name to find a matching file. `paths` are checked in configured order; an earlier
|
|
@@ -48,20 +48,21 @@ module Hanami
|
|
|
48
48
|
|
|
49
49
|
def template(name, format, scope, &block)
|
|
50
50
|
old_prefixes = @prefixes.dup
|
|
51
|
+
old_template_names = @current_template_names
|
|
51
52
|
|
|
52
53
|
result = lookup(name, format)
|
|
53
54
|
raise TemplateNotFoundError.new(name, format, config_data.paths) unless result
|
|
54
55
|
|
|
55
56
|
template_path, relative_path = result
|
|
56
57
|
|
|
57
|
-
new_prefix = File.dirname(
|
|
58
|
+
new_prefix = File.dirname(relative_path)
|
|
58
59
|
@prefixes << new_prefix unless @prefixes.include?(new_prefix)
|
|
59
|
-
@current_template_names
|
|
60
|
+
@current_template_names = old_template_names + [resolve_template_name(relative_path)]
|
|
60
61
|
|
|
61
|
-
render(template_path, scope, &block)
|
|
62
|
+
render(template_path, scope, &yielded_block(block, old_template_names))
|
|
62
63
|
ensure
|
|
63
64
|
@prefixes = old_prefixes
|
|
64
|
-
@current_template_names
|
|
65
|
+
@current_template_names = old_template_names
|
|
65
66
|
end
|
|
66
67
|
|
|
67
68
|
def partial(name, format, scope, &block)
|
|
@@ -107,6 +108,28 @@ module Hanami
|
|
|
107
108
|
}
|
|
108
109
|
end
|
|
109
110
|
|
|
111
|
+
# Wraps a block yielded into a template so that, while it runs, `#current_template_name`
|
|
112
|
+
# reports the template that _wrote_ the block, not the one yielding to it.
|
|
113
|
+
#
|
|
114
|
+
# A block passed to `render` is written inside the calling template, so its contents belong to
|
|
115
|
+
# that template even though they're evaluated during the rendering of another.
|
|
116
|
+
#
|
|
117
|
+
# @return [Proc, nil]
|
|
118
|
+
def yielded_block(block, caller_template_names)
|
|
119
|
+
return nil unless block
|
|
120
|
+
|
|
121
|
+
proc { |*args|
|
|
122
|
+
yielding_template_names = @current_template_names
|
|
123
|
+
@current_template_names = caller_template_names
|
|
124
|
+
|
|
125
|
+
begin
|
|
126
|
+
block.call(*args)
|
|
127
|
+
ensure
|
|
128
|
+
@current_template_names = yielding_template_names
|
|
129
|
+
end
|
|
130
|
+
}
|
|
131
|
+
end
|
|
132
|
+
|
|
110
133
|
# Derives the rendered template's name from its relative path, suitable for tracking on
|
|
111
134
|
# `@current_template_names` and surfacing via `#current_template_name`.
|
|
112
135
|
#
|
data/lib/hanami/view/version.rb
CHANGED