hanami 2.1.0.rc1 → 2.1.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/hanami.gemspec +2 -2
- data/lib/hanami/app.rb +0 -5
- data/lib/hanami/config/actions.rb +3 -4
- data/lib/hanami/config/assets.rb +1 -1
- data/lib/hanami/config/views.rb +10 -2
- data/lib/hanami/config.rb +21 -16
- data/lib/hanami/extensions/view/context.rb +122 -10
- data/lib/hanami/extensions/view/part.rb +14 -2
- data/lib/hanami/extensions/view/scope.rb +7 -0
- data/lib/hanami/extensions/view/slice_configured_context.rb +12 -8
- data/lib/hanami/extensions/view/slice_configured_helpers.rb +12 -1
- data/lib/hanami/extensions/view/slice_configured_part.rb +4 -5
- data/lib/hanami/extensions/view/slice_configured_view.rb +12 -4
- data/lib/hanami/extensions/view/standard_helpers.rb +4 -0
- data/lib/hanami/extensions/view.rb +5 -3
- data/lib/hanami/helpers/assets_helper.rb +71 -70
- data/lib/hanami/helpers/form_helper/form_builder.rb +54 -54
- data/lib/hanami/helpers/form_helper/values.rb +8 -8
- data/lib/hanami/helpers/form_helper.rb +9 -9
- data/lib/hanami/providers/assets.rb +4 -1
- data/lib/hanami/rake_tasks.rb +1 -9
- data/lib/hanami/slice.rb +10 -0
- data/lib/hanami/version.rb +1 -1
- data/spec/integration/assets/assets_spec.rb +67 -24
- data/spec/integration/assets/cross_slice_assets_helpers_spec.rb +130 -0
- data/spec/integration/view/context/assets_spec.rb +57 -31
- data/spec/support/app_integration.rb +12 -6
- data/spec/unit/hanami/config/render_detailed_errors_spec.rb +1 -1
- data/spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb +11 -0
- data/spec/unit/hanami/version_spec.rb +1 -1
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f126bd2f756323d71dfe0eedd34a45f998882fd1ef2e0afcc8d05c27de224e3a
|
4
|
+
data.tar.gz: c9b360c13dbb7ce88e935df753a4d9ec4234f02bc625c403664fb44617ff6261
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef015d93dfbd94b0f0617cc0966f1d081e06859b2559de39c3b180dc9afc9d0e9034d53dc66117ea7305e80afd8f643a4204246dcba202da8f3c49b59c108426
|
7
|
+
data.tar.gz: bced4c311fbcf6ee66e3036cb70fd9f9edc7cb897f6ff26eca660b30a94629297ec5abc3dfb5c849d04f682f66d45e0c2aa55b46829b9ce7b5edeef80a3e9247
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,25 @@
|
|
2
2
|
|
3
3
|
The web, with simplicity.
|
4
4
|
|
5
|
+
## v2.1.0.rc3 - 2024-02-16
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
- [Tim Riley] Return `nil` when setting content via `#content_for` on the app's view context. This
|
10
|
+
allows it to be used with tempalte output tags (such as ERB's `<%=`) that capture a block for the
|
11
|
+
given content. (#1369)
|
12
|
+
|
13
|
+
## Fixed
|
14
|
+
|
15
|
+
- [Tim Riley] Ensure assets Rake task for Heroku works (#1368)
|
16
|
+
|
17
|
+
## v2.1.0.rc2 - 2023-11-08
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
|
21
|
+
- [Tim Riley] Enable `config.render_detailed_errors` in development mode only by default. (#1365)
|
22
|
+
- [Tim Riley] Remove current_path from context (#1362)
|
23
|
+
|
5
24
|
## v2.1.0.rc1 - 2023-11-01
|
6
25
|
|
7
26
|
### Added
|
data/hanami.gemspec
CHANGED
@@ -38,8 +38,8 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_dependency "dry-monitor", "~> 1.0", ">= 1.0.1", "< 2"
|
39
39
|
spec.add_dependency "dry-system", "~> 1.0", "< 2"
|
40
40
|
spec.add_dependency "dry-logger", "~> 1.0", "< 2"
|
41
|
-
spec.add_dependency "hanami-cli", "
|
42
|
-
spec.add_dependency "hanami-utils", "~> 2.1.
|
41
|
+
spec.add_dependency "hanami-cli", "= 2.1.0.rc3"
|
42
|
+
spec.add_dependency "hanami-utils", "~> 2.1.rc"
|
43
43
|
spec.add_dependency "zeitwerk", "~> 2.6"
|
44
44
|
|
45
45
|
spec.add_development_dependency "rspec", "~> 3.8"
|
data/lib/hanami/app.rb
CHANGED
@@ -161,11 +161,6 @@ module Hanami
|
|
161
161
|
require_relative "providers/rack"
|
162
162
|
register_provider(:rack, source: Hanami::Providers::Rack, namespace: true)
|
163
163
|
end
|
164
|
-
|
165
|
-
if Hanami.bundled?("hanami-assets")
|
166
|
-
require_relative "providers/assets"
|
167
|
-
register_provider(:assets, source: Providers::Assets.for_slice(self))
|
168
|
-
end
|
169
164
|
end
|
170
165
|
|
171
166
|
def prepare_autoloader
|
@@ -88,20 +88,19 @@ module Hanami
|
|
88
88
|
# @since 2.1.0
|
89
89
|
setting :method_override, default: true
|
90
90
|
|
91
|
-
# The following settings are for view and assets integration with actions, and are NOT
|
92
|
-
# publicly released as of 2.0.0. We'll make full documentation available when these become
|
93
|
-
# public in a subsequent release.
|
94
|
-
|
95
91
|
# @!attribute [rw] name_inference_base
|
96
92
|
# @api private
|
93
|
+
# @since 2.1.0
|
97
94
|
setting :name_inference_base, default: "actions"
|
98
95
|
|
99
96
|
# @!attribute [rw] view_name_inferrer
|
100
97
|
# @api private
|
98
|
+
# @since 2.1.0
|
101
99
|
setting :view_name_inferrer, default: Slice::ViewNameInferrer
|
102
100
|
|
103
101
|
# @!attribute [rw] view_name_inference_base
|
104
102
|
# @api private
|
103
|
+
# @since 2.1.0
|
105
104
|
setting :view_name_inference_base, default: "views"
|
106
105
|
|
107
106
|
# @api private
|
data/lib/hanami/config/assets.rb
CHANGED
@@ -9,7 +9,7 @@ module Hanami
|
|
9
9
|
#
|
10
10
|
# This exposes all the settings from the standalone `Hanami::Assets` class, pre-configured with
|
11
11
|
# sensible defaults for actions within a full Hanami app. It also provides additional settings
|
12
|
-
# for further integration of
|
12
|
+
# for further integration of assets with other full stack app components.
|
13
13
|
#
|
14
14
|
# @since 2.1.0
|
15
15
|
# @api public
|
data/lib/hanami/config/views.rb
CHANGED
@@ -7,16 +7,22 @@ module Hanami
|
|
7
7
|
class Config
|
8
8
|
# Hanami views config
|
9
9
|
#
|
10
|
-
# This
|
10
|
+
# This exposes all the settings from the standalone `Hanami::View` class, pre-configured with
|
11
|
+
# sensible defaults for actions within a full Hanami app. It also provides additional settings
|
12
|
+
# for further integration of views with other full stack app components.
|
11
13
|
#
|
12
|
-
# @
|
14
|
+
# @since 2.1.0
|
15
|
+
# @api public
|
13
16
|
class Views
|
14
17
|
include Dry::Configurable
|
15
18
|
|
19
|
+
# @api private
|
20
|
+
# @since 2.1.0
|
16
21
|
attr_reader :base_config
|
17
22
|
protected :base_config
|
18
23
|
|
19
24
|
# @api private
|
25
|
+
# @since 2.1.0
|
20
26
|
def initialize(*)
|
21
27
|
super
|
22
28
|
|
@@ -26,6 +32,7 @@ module Hanami
|
|
26
32
|
end
|
27
33
|
|
28
34
|
# @api private
|
35
|
+
# @since 2.1.0
|
29
36
|
def initialize_copy(source)
|
30
37
|
super
|
31
38
|
@base_config = source.base_config.dup
|
@@ -33,6 +40,7 @@ module Hanami
|
|
33
40
|
private :initialize_copy
|
34
41
|
|
35
42
|
# @api private
|
43
|
+
# @since 2.1.0
|
36
44
|
def finalize!
|
37
45
|
return self if frozen?
|
38
46
|
|
data/lib/hanami/config.rb
CHANGED
@@ -99,7 +99,6 @@ module Hanami
|
|
99
99
|
rack.monitor
|
100
100
|
routes
|
101
101
|
settings
|
102
|
-
assets
|
103
102
|
]
|
104
103
|
|
105
104
|
# @!attribute [rw] no_auto_register_paths
|
@@ -251,16 +250,30 @@ module Hanami
|
|
251
250
|
|
252
251
|
# Returns the app's views config, or a null config if hanami-view is not bundled.
|
253
252
|
#
|
254
|
-
#
|
253
|
+
# @example When hanami-view is bundled
|
254
|
+
# config.views.paths # => [...]
|
255
255
|
#
|
256
|
-
# @
|
256
|
+
# @example When hanami-view is not bundled
|
257
|
+
# config.views.paths # => NoMethodError
|
258
|
+
#
|
259
|
+
# @return [Hanami::Config::Views, Hanami::Config::NullConfig]
|
260
|
+
#
|
261
|
+
# @api public
|
262
|
+
# @since 2.1.0
|
257
263
|
attr_reader :views
|
258
264
|
|
259
|
-
# Returns the app's
|
265
|
+
# Returns the app's views config, or a null config if hanami-view is not bundled.
|
260
266
|
#
|
261
|
-
#
|
267
|
+
# @example When hanami-view is bundled
|
268
|
+
# config.views.paths # => [...]
|
262
269
|
#
|
263
|
-
# @
|
270
|
+
# @example When hanami-view is not bundled
|
271
|
+
# config.views.paths # => NoMethodError
|
272
|
+
#
|
273
|
+
# @return [Hanami::Config::Assets, Hanami::Config::NullConfig]
|
274
|
+
#
|
275
|
+
# @api public
|
276
|
+
# @since 2.1.0
|
264
277
|
attr_reader :assets
|
265
278
|
|
266
279
|
# @api private
|
@@ -272,7 +285,7 @@ module Hanami
|
|
272
285
|
# Apply default values that are only knowable at initialize-time (vs require-time)
|
273
286
|
self.root = Dir.pwd
|
274
287
|
self.render_errors = (env == :production)
|
275
|
-
self.render_detailed_errors = (env
|
288
|
+
self.render_detailed_errors = (env == :development)
|
276
289
|
load_from_env
|
277
290
|
|
278
291
|
@logger = Config::Logger.new(env: env, app_name: app_name)
|
@@ -295,15 +308,7 @@ module Hanami
|
|
295
308
|
|
296
309
|
@assets = load_dependent_config("hanami-assets") {
|
297
310
|
require_relative "config/assets"
|
298
|
-
|
299
|
-
public_dir = root.join("public")
|
300
|
-
|
301
|
-
Hanami::Config::Assets.new(
|
302
|
-
# TODO: check if `sources` are still needed
|
303
|
-
sources: root.join("app", "assets"),
|
304
|
-
destination: public_dir.join("assets"),
|
305
|
-
manifest_path: public_dir.join("assets.json")
|
306
|
-
)
|
311
|
+
Hanami::Config::Assets.new
|
307
312
|
}
|
308
313
|
|
309
314
|
yield self if block_given?
|
@@ -7,15 +7,15 @@ module Hanami
|
|
7
7
|
module View
|
8
8
|
# View context for views in Hanami apps.
|
9
9
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# @api private
|
10
|
+
# @api public
|
11
|
+
# @since 2.1.0
|
13
12
|
module Context
|
14
13
|
class << self
|
15
14
|
# Returns a context class for the given slice. If a context class is not defined, defines
|
16
15
|
# a class named `Views::Context` within the slice's namespace.
|
17
16
|
#
|
18
17
|
# @api private
|
18
|
+
# @since 2.1.0
|
19
19
|
def context_class(slice)
|
20
20
|
views_namespace = views_namespace(slice)
|
21
21
|
|
@@ -30,6 +30,8 @@ module Hanami
|
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
+
# @api private
|
34
|
+
# @since 2.1.0
|
33
35
|
def context_superclass(slice)
|
34
36
|
return Hanami::View::Context if Hanami.app.equal?(slice)
|
35
37
|
|
@@ -44,8 +46,10 @@ module Hanami
|
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
|
-
#
|
49
|
+
# @api private
|
50
|
+
# @since 2.1.0
|
48
51
|
def views_namespace(slice)
|
52
|
+
# TODO: this could be moved into the top-level Extensions::View
|
49
53
|
if slice.namespace.const_defined?(:Views)
|
50
54
|
slice.namespace.const_get(:Views)
|
51
55
|
else
|
@@ -54,6 +58,8 @@ module Hanami
|
|
54
58
|
end
|
55
59
|
end
|
56
60
|
|
61
|
+
# @api private
|
62
|
+
# @since 2.1.0
|
57
63
|
module ClassExtension
|
58
64
|
def self.included(context_class)
|
59
65
|
super
|
@@ -63,18 +69,39 @@ module Hanami
|
|
63
69
|
context_class.prepend(InstanceMethods)
|
64
70
|
end
|
65
71
|
|
72
|
+
# @api private
|
73
|
+
# @since 2.1.0
|
66
74
|
module ClassMethods
|
75
|
+
# @api private
|
76
|
+
# @since 2.1.0
|
67
77
|
def configure_for_slice(slice)
|
68
78
|
extend SliceConfiguredContext.new(slice)
|
69
79
|
end
|
70
80
|
end
|
71
81
|
|
82
|
+
# @api public
|
83
|
+
# @since 2.1.0
|
72
84
|
module InstanceMethods
|
85
|
+
# Returns the app's inflector.
|
86
|
+
#
|
87
|
+
# @return [Dry::Inflector] the inflector
|
88
|
+
#
|
89
|
+
# @api public
|
90
|
+
# @since 2.1.0
|
73
91
|
attr_reader :inflector
|
74
92
|
|
93
|
+
# Returns the app's settings.
|
94
|
+
#
|
95
|
+
# @return [Hanami::Settings] the settings
|
96
|
+
#
|
97
|
+
# @api public
|
98
|
+
# @since 2.1.0
|
75
99
|
attr_reader :settings
|
76
100
|
|
77
101
|
# @see SliceConfiguredContext#define_new
|
102
|
+
#
|
103
|
+
# @api private
|
104
|
+
# @since 2.1.0
|
78
105
|
def initialize( # rubocop:disable Metrics/ParameterLists
|
79
106
|
inflector: nil,
|
80
107
|
settings: nil,
|
@@ -94,6 +121,8 @@ module Hanami
|
|
94
121
|
super(**args)
|
95
122
|
end
|
96
123
|
|
124
|
+
# @api private
|
125
|
+
# @since 2.1.0
|
97
126
|
def initialize_copy(source)
|
98
127
|
# The standard implementation of initialize_copy will make shallow copies of all
|
99
128
|
# instance variables from the source. This is fine for most of our ivars.
|
@@ -104,22 +133,54 @@ module Hanami
|
|
104
133
|
@content_for = source.instance_variable_get(:@content_for).dup
|
105
134
|
end
|
106
135
|
|
136
|
+
# Returns the app's assets.
|
137
|
+
#
|
138
|
+
# @return [Hanami::Assets] the assets
|
139
|
+
#
|
140
|
+
# @raise [Hanami::ComponentLoadError] if the hanami-assets gem is not bundled
|
141
|
+
#
|
142
|
+
# @api public
|
143
|
+
# @since 2.1.0
|
107
144
|
def assets
|
108
145
|
unless @assets
|
109
|
-
|
146
|
+
msg =
|
147
|
+
if Hanami.bundled?("hanami-assets")
|
148
|
+
"Have you put files into your assets directory?"
|
149
|
+
else
|
150
|
+
"The hanami-assets gem is required to access assets."
|
151
|
+
end
|
152
|
+
|
153
|
+
raise Hanami::ComponentLoadError, "Assets not available. #{msg}"
|
110
154
|
end
|
111
155
|
|
112
156
|
@assets
|
113
157
|
end
|
114
158
|
|
159
|
+
# Returns the current request, if the view is rendered from within an action.
|
160
|
+
#
|
161
|
+
# @return [Hanami::Action::Request] the request
|
162
|
+
#
|
163
|
+
# @raise [Hanami::ComponentLoadError] if the view is not rendered from within a request
|
164
|
+
#
|
165
|
+
# @api public
|
166
|
+
# @since 2.1.0
|
115
167
|
def request
|
116
168
|
unless @request
|
117
|
-
raise Hanami::ComponentLoadError, "
|
169
|
+
raise Hanami::ComponentLoadError, "Request not available. Only views rendered from Hanami::Action instances have a request."
|
118
170
|
end
|
119
171
|
|
120
172
|
@request
|
121
173
|
end
|
122
174
|
|
175
|
+
# Returns the app's routes helper.
|
176
|
+
#
|
177
|
+
# @return [Hanami::Slice::RoutesHelper] the routes helper
|
178
|
+
#
|
179
|
+
# @raise [Hanami::ComponentLoadError] if the hanami-router gem is not bundled or routes
|
180
|
+
# are not defined
|
181
|
+
#
|
182
|
+
# @api public
|
183
|
+
# @since 2.1.0
|
123
184
|
def routes
|
124
185
|
unless @routes
|
125
186
|
raise Hanami::ComponentLoadError, "the hanami-router gem is required to access routes"
|
@@ -128,28 +189,79 @@ module Hanami
|
|
128
189
|
@routes
|
129
190
|
end
|
130
191
|
|
192
|
+
# @overload content_for(key, value = nil, &block)
|
193
|
+
# Stores a string or block of template markup for later use.
|
194
|
+
#
|
195
|
+
# @param key [Symbol] the content key, for later retrieval
|
196
|
+
# @param value [String, nil] the content, if no block is given
|
197
|
+
#
|
198
|
+
# @return [String] the content
|
199
|
+
#
|
200
|
+
# @example
|
201
|
+
# content_for(:page_title, "Hello world")
|
202
|
+
#
|
203
|
+
# @example In a template
|
204
|
+
# <%= content_for :page_title do %>
|
205
|
+
# <h1>Hello world</h1>
|
206
|
+
# <% end %>
|
207
|
+
#
|
208
|
+
# @overload content_for(key)
|
209
|
+
# Returns the previously stored content for the given key.
|
210
|
+
#
|
211
|
+
# @param key [Symbol] the content key
|
212
|
+
#
|
213
|
+
# @return [String, nil] the content, or nil if no content previously stored with the
|
214
|
+
# key
|
215
|
+
#
|
216
|
+
# @api public
|
217
|
+
# @since 2.1.0
|
131
218
|
def content_for(key, value = nil)
|
132
219
|
if block_given?
|
133
220
|
@content_for[key] = yield
|
221
|
+
nil
|
134
222
|
elsif value
|
135
223
|
@content_for[key] = value
|
224
|
+
nil
|
136
225
|
else
|
137
226
|
@content_for[key]
|
138
227
|
end
|
139
228
|
end
|
140
229
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
230
|
+
# Returns the current request's CSRF token.
|
231
|
+
#
|
232
|
+
# @return [String] the token
|
233
|
+
#
|
234
|
+
# @raise [Hanami::ComponentLoadError] if the view is not rendered from within a request
|
235
|
+
# @raise [Hanami::Action::MissingSessionError] if sessions are not enabled
|
236
|
+
#
|
237
|
+
# @api public
|
238
|
+
# @since 2.1.0
|
145
239
|
def csrf_token
|
146
240
|
request.session[Hanami::Action::CSRFProtection::CSRF_TOKEN]
|
147
241
|
end
|
148
242
|
|
243
|
+
# Returns the session for the current request.
|
244
|
+
#
|
245
|
+
# @return [Rack::Session::Abstract::SessionHash] the session hash
|
246
|
+
#
|
247
|
+
# @raise [Hanami::ComponentLoadError] if the view is not rendered from within a request
|
248
|
+
# @raise [Hanami::Action::MissingSessionError] if sessions are not enabled
|
249
|
+
#
|
250
|
+
# @api public
|
251
|
+
# @since 2.1.0
|
149
252
|
def session
|
150
253
|
request.session
|
151
254
|
end
|
152
255
|
|
256
|
+
# Returns the flash hash for the current request.
|
257
|
+
#
|
258
|
+
# @return []
|
259
|
+
#
|
260
|
+
# @raise [Hanami::ComponentLoadError] if the view is not rendered from within a request
|
261
|
+
# @raise [Hanami::Action::MissingSessionError] if sessions are not enabled
|
262
|
+
#
|
263
|
+
# @api public
|
264
|
+
# @since 2.1.0
|
153
265
|
def flash
|
154
266
|
request.flash
|
155
267
|
end
|
@@ -3,9 +3,11 @@
|
|
3
3
|
module Hanami
|
4
4
|
module Extensions
|
5
5
|
module View
|
6
|
-
# @api
|
6
|
+
# @api public
|
7
7
|
# @since 2.1.0
|
8
8
|
module Part
|
9
|
+
# @api private
|
10
|
+
# @since 2.1.0
|
9
11
|
def self.included(part_class)
|
10
12
|
super
|
11
13
|
|
@@ -13,7 +15,11 @@ module Hanami
|
|
13
15
|
part_class.extend(ClassMethods)
|
14
16
|
end
|
15
17
|
|
18
|
+
# @api private
|
19
|
+
# @since 2.1.0
|
16
20
|
module ClassMethods
|
21
|
+
# @api private
|
22
|
+
# @since 2.1.0
|
17
23
|
def configure_for_slice(slice)
|
18
24
|
extend SliceConfiguredPart.new(slice)
|
19
25
|
|
@@ -28,7 +34,7 @@ module Hanami
|
|
28
34
|
#
|
29
35
|
# Use this when you need to access helpers inside your part classes.
|
30
36
|
#
|
31
|
-
# @return
|
37
|
+
# @return [Object] the helpers object
|
32
38
|
#
|
33
39
|
# @api public
|
34
40
|
# @since 2.1.0
|
@@ -50,10 +56,16 @@ module Hanami
|
|
50
56
|
|
51
57
|
include StandardHelpers
|
52
58
|
|
59
|
+
# @api private
|
60
|
+
# @since 2.1.0
|
53
61
|
def self.configure_for_slice(slice)
|
54
62
|
extend SliceConfiguredHelpers.new(slice)
|
55
63
|
end
|
56
64
|
|
65
|
+
# Returns the context for the current view rendering.
|
66
|
+
#
|
67
|
+
# @return [Hanami::View::Context] the context
|
68
|
+
#
|
57
69
|
# @api public
|
58
70
|
# @since 2.1.0
|
59
71
|
attr_reader :_context
|
@@ -4,7 +4,10 @@ module Hanami
|
|
4
4
|
module Extensions
|
5
5
|
module View
|
6
6
|
# @api private
|
7
|
+
# @since 2.1.0
|
7
8
|
module Scope
|
9
|
+
# @api private
|
10
|
+
# @since 2.1.0
|
8
11
|
def self.included(scope_class)
|
9
12
|
super
|
10
13
|
|
@@ -13,7 +16,11 @@ module Hanami
|
|
13
16
|
scope_class.extend(ClassMethods)
|
14
17
|
end
|
15
18
|
|
19
|
+
# @api private
|
20
|
+
# @since 2.1.0
|
16
21
|
module ClassMethods
|
22
|
+
# @api private
|
23
|
+
# @since 2.1.0
|
17
24
|
def configure_for_slice(slice)
|
18
25
|
extend SliceConfiguredHelpers.new(slice)
|
19
26
|
end
|
@@ -3,35 +3,39 @@
|
|
3
3
|
module Hanami
|
4
4
|
module Extensions
|
5
5
|
module View
|
6
|
-
# Provides slice-specific configuration and behavior for any view context class
|
7
|
-
#
|
6
|
+
# Provides slice-specific configuration and behavior for any view context class defined within
|
7
|
+
# a slice's module namespace.
|
8
8
|
#
|
9
|
-
# @api
|
10
|
-
# @since 2.
|
9
|
+
# @api public
|
10
|
+
# @since 2.1.0
|
11
11
|
class SliceConfiguredContext < Module
|
12
12
|
attr_reader :slice
|
13
13
|
|
14
|
+
# @api private
|
15
|
+
# @since 2.1.0
|
14
16
|
def initialize(slice)
|
15
17
|
super()
|
16
18
|
@slice = slice
|
17
19
|
end
|
18
20
|
|
21
|
+
# @api private
|
22
|
+
# @since 2.1.0
|
19
23
|
def extended(_context_class)
|
20
24
|
define_new
|
21
25
|
end
|
22
26
|
|
27
|
+
# @api public
|
28
|
+
# @since 2.1.0
|
23
29
|
def inspect
|
24
30
|
"#<#{self.class.name}[#{slice.name}]>"
|
25
31
|
end
|
26
32
|
|
27
33
|
private
|
28
34
|
|
29
|
-
# Defines a {.new} method on the context class that resolves key components from
|
30
|
-
#
|
31
|
-
# dependencies.
|
35
|
+
# Defines a {.new} method on the context class that resolves key components from the app
|
36
|
+
# container and provides them to {#initialize} as injected dependencies.
|
32
37
|
#
|
33
38
|
# This includes the following app components:
|
34
|
-
#
|
35
39
|
# - the configured inflector as `inflector`
|
36
40
|
# - "settings" from the app container as `settings`
|
37
41
|
# - "routes" from the app container as `routes`
|
@@ -3,19 +3,30 @@
|
|
3
3
|
module Hanami
|
4
4
|
module Extensions
|
5
5
|
module View
|
6
|
-
#
|
6
|
+
# Provides slice-specific helper methods any view object requiring access to helpers.
|
7
|
+
#
|
8
|
+
# @api public
|
9
|
+
# @since 2.1.0
|
7
10
|
class SliceConfiguredHelpers < Module
|
8
11
|
attr_reader :slice
|
9
12
|
|
13
|
+
# @api private
|
14
|
+
# @since 2.1.0
|
10
15
|
def initialize(slice)
|
11
16
|
super()
|
12
17
|
@slice = slice
|
13
18
|
end
|
14
19
|
|
20
|
+
# @api private
|
21
|
+
# @since 2.1.0
|
15
22
|
def extended(klass)
|
16
23
|
include_helpers(klass)
|
17
24
|
end
|
18
25
|
|
26
|
+
# @return [String]
|
27
|
+
#
|
28
|
+
# @api public
|
29
|
+
# @since 2.1.0
|
19
30
|
def inspect
|
20
31
|
"#<#{self.class.name}[#{slice.name}]>"
|
21
32
|
end
|
@@ -6,7 +6,7 @@ module Hanami
|
|
6
6
|
# Provides slice-specific configuration and behavior for any view part class defined within a
|
7
7
|
# slice's module namespace.
|
8
8
|
#
|
9
|
-
# @api
|
9
|
+
# @api public
|
10
10
|
# @since 2.1.0
|
11
11
|
class SliceConfiguredPart < Module
|
12
12
|
attr_reader :slice
|
@@ -24,7 +24,9 @@ module Hanami
|
|
24
24
|
define_new
|
25
25
|
end
|
26
26
|
|
27
|
-
# @
|
27
|
+
# @return [String]
|
28
|
+
#
|
29
|
+
# @api public
|
28
30
|
# @since 2.1.0
|
29
31
|
def inspect
|
30
32
|
"#<#{self.class.name}[#{slice.name}]>"
|
@@ -49,9 +51,6 @@ module Hanami
|
|
49
51
|
# # Useful when unit testing parts
|
50
52
|
# part = MyApp::Views::Parts::Post.new(value: hello_world_post)
|
51
53
|
# part.title_tag # => "<h1>Hello world</h1>"
|
52
|
-
#
|
53
|
-
# @api private
|
54
|
-
# @since 2.1.0
|
55
54
|
def define_new
|
56
55
|
slice = self.slice
|
57
56
|
|
@@ -3,11 +3,11 @@
|
|
3
3
|
module Hanami
|
4
4
|
module Extensions
|
5
5
|
module View
|
6
|
-
# Provides slice-specific configuration and behavior for any view class defined
|
7
|
-
#
|
6
|
+
# Provides slice-specific configuration and behavior for any view class defined within a
|
7
|
+
# slice's module namespace.
|
8
8
|
#
|
9
|
-
# @api
|
10
|
-
# @since 2.
|
9
|
+
# @api public
|
10
|
+
# @since 2.1.0
|
11
11
|
class SliceConfiguredView < Module
|
12
12
|
TEMPLATES_DIR = "templates"
|
13
13
|
VIEWS_DIR = "views"
|
@@ -16,17 +16,25 @@ module Hanami
|
|
16
16
|
|
17
17
|
attr_reader :slice
|
18
18
|
|
19
|
+
# @api private
|
20
|
+
# @since 2.1.0
|
19
21
|
def initialize(slice)
|
20
22
|
super()
|
21
23
|
@slice = slice
|
22
24
|
end
|
23
25
|
|
26
|
+
# @api private
|
27
|
+
# @since 2.1.0
|
24
28
|
def extended(view_class)
|
25
29
|
load_app_view
|
26
30
|
configure_view(view_class)
|
27
31
|
define_inherited
|
28
32
|
end
|
29
33
|
|
34
|
+
# @return [String]
|
35
|
+
#
|
36
|
+
# @api public
|
37
|
+
# @since 2.1.0
|
30
38
|
def inspect
|
31
39
|
"#<#{self.class.name}[#{slice.name}]>"
|
32
40
|
end
|
@@ -3,6 +3,10 @@
|
|
3
3
|
module Hanami
|
4
4
|
module Extensions
|
5
5
|
module View
|
6
|
+
# Module including the standard library of Hanami helpers
|
7
|
+
#
|
8
|
+
# @api public
|
9
|
+
# @since 2.1.0
|
6
10
|
module StandardHelpers
|
7
11
|
include Hanami::View::Helpers::EscapeHelper
|
8
12
|
include Hanami::View::Helpers::NumberFormattingHelper
|