phlex-hanami 0.2.2 → 0.3.0
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 +18 -1
- data/lib/phlex/hanami/extensions/mailer.rb +5 -3
- data/lib/phlex/hanami/extensions/slice.rb +20 -0
- data/lib/phlex/hanami/mailer/renderable.rb +4 -7
- data/lib/phlex/hanami/renderable.rb +5 -5
- data/lib/phlex/hanami/slice_configured_context.rb +4 -1
- data/sig/phlex/hanami/extensions/slice.rbs +2 -0
- 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: af266b5dd1d9a3b34563f84a472fe71d4e49cd1d2ea4e64982c61631bed12730
|
|
4
|
+
data.tar.gz: 88d3d2d0fa2aae7942f8d1d6c11386dcc06d7cae3ad7a8cff0de4647e0addbe2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 74cef7af6b2d42741c0d900c1772c3cf8a58a07ed3a5eac60fb4e8a1da72b57b0ba3a613f3be2bba92db3aa35fd3c93b914b222b724384edfc7c1843d42c2d90
|
|
7
|
+
data.tar.gz: 0e9b852908aa28e2f236637093642ad2d4b8f22c4e6a9711fea40d7f7789e406a3aacb85c9fc0109d2d19a7a217e3951a34f6e8823c6db5172d9e14ebe7c4931
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [v0.3.0] - 2026-10-07
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- A view's `routes`, `path` and `url` now use the app's routes, even in a slice with a routes file of its own. That
|
|
15
|
+
slice's own routes knew only its own names and dropped the prefix it is mounted at, so `path(:posts)` in a slice
|
|
16
|
+
mounted at `/blog` gave `"/posts"`. A view now names the route the way an action does: `path(:blog_posts)` gives
|
|
17
|
+
`"/blog/posts"`. Slices mounted at `"/"` keep their names. With hanami-view bundled, Hanami builds the context, so
|
|
18
|
+
the fix comes with Hanami's next release. ([#7](https://github.com/aaronmallen/phlex-hanami/issues/7))
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- Mail views and layouts follow `config.actions.view_name_inference_base`. A slice that sets it to `"ui.views"` now
|
|
23
|
+
finds `ui.views.mailers.welcome`, `ui.views.layout` and `ui.views.mailers.layout`, where before it looked only
|
|
24
|
+
under `views`. ([#6](https://github.com/aaronmallen/phlex-hanami/issues/6))
|
|
25
|
+
|
|
10
26
|
## [v0.2.2] - 2026-09-26
|
|
11
27
|
|
|
12
28
|
### Added
|
|
@@ -130,7 +146,8 @@ Initial alpha release by the new maintainer [@aaronmallen](https://github.com/aa
|
|
|
130
146
|
|
|
131
147
|
Initial release, by the previous maintainer [@stephannv](https://github.com/stephannv).
|
|
132
148
|
|
|
133
|
-
[Unreleased]: https://github.com/aaronmallen/phlex-hanami/compare/0.
|
|
149
|
+
[Unreleased]: https://github.com/aaronmallen/phlex-hanami/compare/0.3.0...HEAD
|
|
150
|
+
[v0.3.0]: https://github.com/aaronmallen/phlex-hanami/compare/0.2.2...0.3.0
|
|
134
151
|
[v0.2.2]: https://github.com/aaronmallen/phlex-hanami/compare/0.2.1...0.2.2
|
|
135
152
|
[v0.2.1]: https://github.com/aaronmallen/phlex-hanami/compare/0.2.0...0.2.1
|
|
136
153
|
[v0.2.0]: https://github.com/aaronmallen/phlex-hanami/compare/0.2.0-alpha.3...0.2.0
|
|
@@ -42,8 +42,10 @@ module Phlex
|
|
|
42
42
|
#
|
|
43
43
|
# The key is derived the way hanami-mailer derives a template name: underscore the class
|
|
44
44
|
# name and drop the slice's own segment, so `MyApp::Mailers::Welcome` looks up
|
|
45
|
-
# `views.mailers.welcome`.
|
|
46
|
-
#
|
|
45
|
+
# `views.mailers.welcome`. The `views` is the slice's
|
|
46
|
+
# `config.actions.view_name_inference_base`, so mail views live where action views do.
|
|
47
|
+
# Resolved through the container on every call rather than memoized, so code reloading is
|
|
48
|
+
# not defeated.
|
|
47
49
|
#
|
|
48
50
|
# @return [Class, nil]
|
|
49
51
|
#
|
|
@@ -56,7 +58,7 @@ module Phlex
|
|
|
56
58
|
mailer_slice = slice
|
|
57
59
|
return nil unless mailer_slice && name
|
|
58
60
|
|
|
59
|
-
key =
|
|
61
|
+
key = Extensions::Slice.view_key(mailer_slice, view_name(mailer_slice))
|
|
60
62
|
return nil unless mailer_slice.key?(key)
|
|
61
63
|
|
|
62
64
|
view = mailer_slice[key]
|
|
@@ -109,6 +109,26 @@ module Phlex
|
|
|
109
109
|
define_view_context(slice)
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
+
# The container key for a view, under the base Hanami pairs an action's view with.
|
|
113
|
+
#
|
|
114
|
+
# Reads `config.actions.view_name_inference_base`, so a slice that keeps its views under
|
|
115
|
+
# `ui.views` finds its layouts and mail views there too. Falls back to `views` when
|
|
116
|
+
# hanami-action is not bundled, because Hanami has no such setting then.
|
|
117
|
+
#
|
|
118
|
+
# @example
|
|
119
|
+
# Slice.view_key(MyApp::App, "mailers.welcome") # => "views.mailers.welcome"
|
|
120
|
+
#
|
|
121
|
+
# @return [String]
|
|
122
|
+
#
|
|
123
|
+
# @api private
|
|
124
|
+
# @since 0.3.0
|
|
125
|
+
#: (singleton(::Hanami::Slice), String) -> String
|
|
126
|
+
def view_key(slice, name)
|
|
127
|
+
actions = slice.config.actions
|
|
128
|
+
base = actions.respond_to?(:view_name_inference_base) ? actions.view_name_inference_base : "views"
|
|
129
|
+
[base, name].compact.join(".")
|
|
130
|
+
end
|
|
131
|
+
|
|
112
132
|
private
|
|
113
133
|
|
|
114
134
|
#: (singleton(::Hanami::Slice)) -> Module
|
|
@@ -59,7 +59,8 @@ module Phlex
|
|
|
59
59
|
|
|
60
60
|
private
|
|
61
61
|
|
|
62
|
-
# A slice's conventional mail layout: `
|
|
62
|
+
# A slice's conventional mail layout: `views.mailers.layout` in its container, if it has
|
|
63
|
+
# one, under whatever base the slice pairs action views with.
|
|
63
64
|
#
|
|
64
65
|
# The web layout is the wrong one for an email — it carries the stylesheets, scripts and
|
|
65
66
|
# page chrome no mail client wants — so mail looks for its own, and renders without a
|
|
@@ -67,13 +68,9 @@ module Phlex
|
|
|
67
68
|
#: () -> singleton(::Phlex::SGML)?
|
|
68
69
|
def default_layout
|
|
69
70
|
return nil unless slice
|
|
70
|
-
return nil unless slice.namespace.const_defined?(:Views, false)
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
mailers = views.const_get(:Mailers, false)
|
|
76
|
-
mailers.const_get(:Layout, false) if mailers.const_defined?(:Layout, false)
|
|
72
|
+
key = Extensions::Slice.view_key(slice, "mailers.layout")
|
|
73
|
+
slice[key] if slice.key?(key)
|
|
77
74
|
end
|
|
78
75
|
|
|
79
76
|
# The slice's view context, built without a request.
|
|
@@ -140,15 +140,15 @@ module Phlex
|
|
|
140
140
|
input.slice(*parameters.filter_map { |type, name| name if KEYWORD_TYPES.include?(type) })
|
|
141
141
|
end
|
|
142
142
|
|
|
143
|
-
# The slice's conventional layout: `
|
|
144
|
-
#
|
|
143
|
+
# The slice's conventional layout: `views.layout` in its container, if it has one, under
|
|
144
|
+
# whatever base the slice pairs action views with. Resolved on each call rather than
|
|
145
|
+
# memoized, so code reloading is not defeated.
|
|
145
146
|
#: () -> singleton(::Phlex::SGML)?
|
|
146
147
|
def default_layout
|
|
147
148
|
return nil unless slice
|
|
148
|
-
return nil unless slice.namespace.const_defined?(:Views, false)
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
key = Extensions::Slice.view_key(slice, "layout")
|
|
151
|
+
slice[key] if slice.key?(key)
|
|
152
152
|
end
|
|
153
153
|
end
|
|
154
154
|
end
|
|
@@ -69,9 +69,12 @@ module Phlex
|
|
|
69
69
|
slice["i18n"] if slice.key?("i18n")
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
+
# Resolves from the app, not the slice. A slice with its own routes file registers its own
|
|
73
|
+
# "routes", which knows only that slice's names and none of the prefix it is mounted at.
|
|
74
|
+
# Actions resolve the app's, so this keeps a view and an action in the same slice in step.
|
|
72
75
|
#: () -> ::Hanami::Slice::RoutesHelper?
|
|
73
76
|
def resolve_routes
|
|
74
|
-
slice["routes"] if slice.key?("routes")
|
|
77
|
+
slice.app["routes"] if slice.app.key?("routes")
|
|
75
78
|
end
|
|
76
79
|
end
|
|
77
80
|
end
|
|
@@ -14,6 +14,8 @@ module Phlex
|
|
|
14
14
|
|
|
15
15
|
def self.view_context_class: (singleton(::Hanami::Slice)) -> (singleton(::Hanami::View::Context) | singleton(Context))
|
|
16
16
|
|
|
17
|
+
def self.view_key: (singleton(::Hanami::Slice), String) -> String
|
|
18
|
+
|
|
17
19
|
private def self.views_namespace: (singleton(::Hanami::Slice)) -> Module
|
|
18
20
|
end
|
|
19
21
|
end
|