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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bb01643b7c075e6b220c2d7ad70e885caba136346380f4236f716350ff7de98
4
- data.tar.gz: fc0766f20a6709feae68138171b2f0e15723c59c30adf90fcfaa4dfef8bc8986
3
+ metadata.gz: af266b5dd1d9a3b34563f84a472fe71d4e49cd1d2ea4e64982c61631bed12730
4
+ data.tar.gz: 88d3d2d0fa2aae7942f8d1d6c11386dcc06d7cae3ad7a8cff0de4647e0addbe2
5
5
  SHA512:
6
- metadata.gz: d30170e3f93a92fdde6d70db733abc97a3384673e9bffa8629737a972aacf2194f1791fe8335a1889c8ed69ec05796c87e8c503e248bc77f3ff2bffb8c46d213
7
- data.tar.gz: 12d33fe3ddf6952ea5714be91db82b954db1848d2bad93e74bbaa8c5b1643c66ec68bf5ad9e3e9c1db0a02ca7f5ee4822c3863c899b6d2d9f1345dbf2f7457e2
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.2.2...HEAD
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`. Resolved through the container on every call rather than
46
- # memoized, so code reloading is not defeated.
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 = "views.#{view_name(mailer_slice)}"
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: `Views::Mailers::Layout`, if it defines one.
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
- views = slice.namespace.const_get(:Views, false)
73
- return nil unless views.const_defined?(:Mailers, false)
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: `Views::Layout` in the slice's namespace, if it defines
144
- # one. Resolved on each call rather than memoized, so code reloading is not defeated.
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
- views = slice.namespace.const_get(:Views, false)
151
- views.const_get(:Layout, false) if views.const_defined?(:Layout, false)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-hanami
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Allen