hanami 2.1.0.beta1 → 2.1.0.beta2
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 +20 -4
- data/README.md +1 -1
- data/lib/hanami/app.rb +5 -0
- data/lib/hanami/config/actions.rb +4 -7
- data/lib/hanami/config/assets.rb +84 -0
- data/lib/hanami/config/null_config.rb +3 -0
- data/lib/hanami/config.rb +17 -5
- data/lib/hanami/extensions/action.rb +4 -2
- data/lib/hanami/extensions/view/standard_helpers.rb +4 -0
- data/lib/hanami/helpers/assets_helper.rb +752 -0
- data/lib/hanami/middleware/assets.rb +21 -0
- data/lib/hanami/middleware/render_errors.rb +4 -7
- data/lib/hanami/providers/assets.rb +44 -0
- data/lib/hanami/rake_tasks.rb +19 -18
- data/lib/hanami/settings.rb +1 -1
- data/lib/hanami/slice.rb +25 -4
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami.rb +2 -2
- data/spec/integration/assets/assets_spec.rb +101 -0
- data/spec/integration/assets/serve_static_assets_spec.rb +152 -0
- data/spec/integration/logging/exception_logging_spec.rb +115 -0
- data/spec/integration/logging/notifications_spec.rb +68 -0
- data/spec/integration/logging/request_logging_spec.rb +128 -0
- data/spec/integration/rack_app/middleware_spec.rb +4 -4
- data/spec/integration/rack_app/rack_app_spec.rb +0 -221
- data/spec/integration/rake_tasks_spec.rb +107 -0
- data/spec/integration/view/context/assets_spec.rb +3 -9
- data/spec/integration/web/render_detailed_errors_spec.rb +17 -0
- data/spec/integration/web/render_errors_spec.rb +6 -4
- data/spec/support/app_integration.rb +46 -2
- data/spec/unit/hanami/config/actions/content_security_policy_spec.rb +24 -36
- data/spec/unit/hanami/config/actions/csrf_protection_spec.rb +4 -3
- data/spec/unit/hanami/config/actions/default_values_spec.rb +3 -2
- data/spec/unit/hanami/env_spec.rb +11 -25
- data/spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb +109 -0
- data/spec/unit/hanami/helpers/assets_helper/audio_tag_spec.rb +132 -0
- data/spec/unit/hanami/helpers/assets_helper/favicon_link_tag_spec.rb +91 -0
- data/spec/unit/hanami/helpers/assets_helper/image_tag_spec.rb +92 -0
- data/spec/unit/hanami/helpers/assets_helper/javascript_tag_spec.rb +143 -0
- data/spec/unit/hanami/helpers/assets_helper/stylesheet_link_tag_spec.rb +126 -0
- data/spec/unit/hanami/helpers/assets_helper/video_tag_spec.rb +132 -0
- data/spec/unit/hanami/version_spec.rb +1 -1
- metadata +32 -4
- data/lib/hanami/assets/app_config.rb +0 -61
- data/lib/hanami/assets/config.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06d7766d5bdb4f510945a2065cc15457acbf00f43970d691afda74219f0aeb02
|
4
|
+
data.tar.gz: 58935ca7f23c3d3612a91b277827ed941c30839d04c9bf577e35a095fa667f6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50a785250f4cf249c5721dd37a5e5a7a240282e5d3820fe848a53c133b1727ea57e5beb351429e636bb4a7d89812bfc53794b5357865b134598a5d54e60666db
|
7
|
+
data.tar.gz: 677f40136e0477c57e493e41ed9a25666d9b53d6dd4ae4c23ee6e61d062f9537c39d86eb16d264f194eda4209e5eb0e38fa0554fd3efaf2d39ea23afa1ead27b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,26 @@
|
|
2
2
|
|
3
3
|
The web, with simplicity.
|
4
4
|
|
5
|
+
## v2.1.0.beta2 - 2023-10-04
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- [Luca Guidi, Tim Riley] Reimplement assets integration (#1319, #1332, #1333, #1336)
|
10
|
+
- [Tim Riley] Introduce `Hanami::Helpers::AssetsHelper`, automatically included in view templates, scopes and parts when hanami-assets is bundled (#1319)
|
11
|
+
- [Tim Riley] Renamed assets helpers (#1319):
|
12
|
+
- Removed `#asset_path` in favour of `#asset_url` only
|
13
|
+
- Renamed `#javascript` to `#javascript_tag`, retaining `#js` alias
|
14
|
+
- Renamed `#stylesheet` to `#stylesheet_link_tag`, retaining `#css` alias
|
15
|
+
- Renamed `#image` to `#image_tag`
|
16
|
+
- Renamed `#favicon` to `#favicon_link_tag`, with `#favicon` retained as an alias
|
17
|
+
- Renamed `#video` to `#video_tag`
|
18
|
+
- Renamed `#audio` to `#audio_tag`
|
19
|
+
|
20
|
+
|
21
|
+
### Fixed
|
22
|
+
|
23
|
+
- [Tim Riley] Return appropriate response statuses based on error type (#1330)
|
24
|
+
|
5
25
|
## v2.1.0.beta1 - 2023-06-29
|
6
26
|
|
7
27
|
### Added
|
@@ -23,10 +43,6 @@ The web, with simplicity.
|
|
23
43
|
|
24
44
|
## v2.0.3 - 2023-02-01
|
25
45
|
|
26
|
-
### Added
|
27
|
-
|
28
|
-
- [Luca Guidi] Official support for Ruby 3.2
|
29
|
-
|
30
46
|
### Fixed
|
31
47
|
|
32
48
|
- [Adam Lassek] Ensure to setup a logger in a non-default Hanami env
|
data/README.md
CHANGED
@@ -62,7 +62,7 @@ You can give back to Open Source, by supporting Hanami development via [GitHub S
|
|
62
62
|
* Guides: https://guides.hanamirb.org
|
63
63
|
* Snippets: https://snippets.hanamirb.org
|
64
64
|
* Mailing List: http://hanamirb.org/mailing-list
|
65
|
-
* API Doc:
|
65
|
+
* API Doc: https://gemdocs.org/gems/hanami/latest
|
66
66
|
* Bugs/Issues: https://github.com/hanami/hanami/issues
|
67
67
|
* Stack Overflow: http://stackoverflow.com/questions/tagged/hanami
|
68
68
|
* Forum: https://discourse.hanamirb.org
|
data/lib/hanami/app.rb
CHANGED
@@ -161,6 +161,11 @@ 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
|
164
169
|
end
|
165
170
|
|
166
171
|
def prepare_autoloader
|
@@ -99,12 +99,7 @@ module Hanami
|
|
99
99
|
super()
|
100
100
|
|
101
101
|
@base_config = Hanami::Action.config.dup
|
102
|
-
@content_security_policy = ContentSecurityPolicy.new
|
103
|
-
if assets_server_url = options[:assets_server_url]
|
104
|
-
csp[:script_src] += " #{assets_server_url}"
|
105
|
-
csp[:style_src] += " #{assets_server_url}"
|
106
|
-
end
|
107
|
-
end
|
102
|
+
@content_security_policy = ContentSecurityPolicy.new
|
108
103
|
|
109
104
|
configure_defaults
|
110
105
|
end
|
@@ -118,7 +113,9 @@ module Hanami
|
|
118
113
|
private :initialize_copy
|
119
114
|
|
120
115
|
# @api private
|
121
|
-
def finalize!
|
116
|
+
def finalize!(app_config)
|
117
|
+
@base_config.root_directory = app_config.root
|
118
|
+
|
122
119
|
# A nil value for `csrf_protection` means it has not been explicitly configured
|
123
120
|
# (neither true nor false), so we can default it to whether sessions are enabled
|
124
121
|
self.csrf_protection = sessions.enabled? if csrf_protection.nil?
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/configurable"
|
4
|
+
require "hanami/assets"
|
5
|
+
|
6
|
+
module Hanami
|
7
|
+
class Config
|
8
|
+
# Hanami assets config
|
9
|
+
#
|
10
|
+
# This exposes all the settings from the standalone `Hanami::Assets` class, pre-configured with
|
11
|
+
# sensible defaults for actions within a full Hanami app. It also provides additional settings
|
12
|
+
# for further integration of actions with other full stack app components.
|
13
|
+
#
|
14
|
+
# @since 2.1.0
|
15
|
+
# @api public
|
16
|
+
class Assets
|
17
|
+
include Dry::Configurable
|
18
|
+
|
19
|
+
# @!attribute [rw] serve
|
20
|
+
# Serve static assets.
|
21
|
+
#
|
22
|
+
# When this is `true`, the app will serve static assets.
|
23
|
+
#
|
24
|
+
# If not set, this will:
|
25
|
+
#
|
26
|
+
# * Check if the `HANAMI_SERVE_ASSETS` environment variable is set to `"true"`.
|
27
|
+
# * If not, it will check if the app is running in the `development` or `test` environment.
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# config.assets.serve = true
|
31
|
+
#
|
32
|
+
# @return [Hanami::Config::Actions::Cookies]
|
33
|
+
#
|
34
|
+
# @api public
|
35
|
+
# @since 2.1.0
|
36
|
+
setting :serve
|
37
|
+
|
38
|
+
# @api private
|
39
|
+
attr_reader :base_config
|
40
|
+
protected :base_config
|
41
|
+
|
42
|
+
# @api private
|
43
|
+
def initialize(*, **options)
|
44
|
+
super()
|
45
|
+
|
46
|
+
@base_config = Hanami::Assets::Config.new(**options)
|
47
|
+
|
48
|
+
configure_defaults
|
49
|
+
end
|
50
|
+
|
51
|
+
# @api private
|
52
|
+
def initialize_copy(source)
|
53
|
+
super
|
54
|
+
@base_config = source.base_config.dup
|
55
|
+
end
|
56
|
+
private :initialize_copy
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def configure_defaults
|
61
|
+
self.serve =
|
62
|
+
if ENV.key?("HANAMI_SERVE_ASSETS")
|
63
|
+
ENV["HANAMI_SERVE_ASSETS"] == "true"
|
64
|
+
else
|
65
|
+
Hanami.env?(:development, :test)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def method_missing(name, *args, &block)
|
70
|
+
if config.respond_to?(name)
|
71
|
+
config.public_send(name, *args, &block)
|
72
|
+
elsif base_config.respond_to?(name)
|
73
|
+
base_config.public_send(name, *args, &block)
|
74
|
+
else
|
75
|
+
super
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def respond_to_missing?(name, _incude_all = false)
|
80
|
+
config.respond_to?(name) || base_config.respond_to?(name) || super
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/hanami/config.rb
CHANGED
@@ -99,6 +99,7 @@ module Hanami
|
|
99
99
|
rack.monitor
|
100
100
|
routes
|
101
101
|
settings
|
102
|
+
assets
|
102
103
|
]
|
103
104
|
|
104
105
|
# @!attribute [rw] no_auto_register_paths
|
@@ -263,6 +264,7 @@ module Hanami
|
|
263
264
|
attr_reader :assets
|
264
265
|
|
265
266
|
# @api private
|
267
|
+
# rubocop:disable Metrics/AbcSize
|
266
268
|
def initialize(app_name:, env:)
|
267
269
|
@app_name = app_name
|
268
270
|
@env = env
|
@@ -275,10 +277,6 @@ module Hanami
|
|
275
277
|
|
276
278
|
@logger = Config::Logger.new(env: env, app_name: app_name)
|
277
279
|
|
278
|
-
# TODO: Make assets config dependent
|
279
|
-
require "hanami/assets/app_config"
|
280
|
-
@assets = Hanami::Assets::AppConfig.new
|
281
|
-
|
282
280
|
@actions = load_dependent_config("hanami-controller") {
|
283
281
|
require_relative "config/actions"
|
284
282
|
Actions.new
|
@@ -295,8 +293,22 @@ module Hanami
|
|
295
293
|
Views.new
|
296
294
|
}
|
297
295
|
|
296
|
+
@assets = load_dependent_config("hanami-assets") {
|
297
|
+
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
|
+
)
|
307
|
+
}
|
308
|
+
|
298
309
|
yield self if block_given?
|
299
310
|
end
|
311
|
+
# rubocop:enable Metrics/AbcSize
|
300
312
|
|
301
313
|
# @api private
|
302
314
|
def initialize_copy(source)
|
@@ -323,7 +335,7 @@ module Hanami
|
|
323
335
|
def finalize!
|
324
336
|
# Finalize nested configs
|
325
337
|
assets.finalize!
|
326
|
-
actions.finalize!
|
338
|
+
actions.finalize!(self)
|
327
339
|
views.finalize!
|
328
340
|
logger.finalize!
|
329
341
|
router.finalize!
|
@@ -94,10 +94,12 @@ module Hanami
|
|
94
94
|
end
|
95
95
|
|
96
96
|
# @api private
|
97
|
-
def _handle_exception(request, _response,
|
97
|
+
def _handle_exception(request, _response, _exception)
|
98
|
+
super
|
99
|
+
rescue StandardError => exception
|
98
100
|
rack_monitor&.instrument(:error, exception: exception, env: request.env)
|
99
101
|
|
100
|
-
|
102
|
+
raise
|
101
103
|
end
|
102
104
|
|
103
105
|
# @api private
|