hanami 2.0.0.alpha8 → 2.0.0.beta1
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 +442 -241
- data/FEATURES.md +30 -9
- data/README.md +1 -3
- data/hanami.gemspec +21 -11
- data/lib/hanami/app.rb +141 -0
- data/lib/hanami/assets/application_configuration.rb +10 -4
- data/lib/hanami/configuration/actions/content_security_policy.rb +5 -5
- data/lib/hanami/configuration/actions/cookies.rb +2 -2
- data/lib/hanami/configuration/actions.rb +10 -4
- data/lib/hanami/configuration/logger.rb +4 -4
- data/lib/hanami/configuration/router.rb +2 -6
- data/lib/hanami/configuration/sessions.rb +1 -1
- data/lib/hanami/configuration/views.rb +9 -4
- data/lib/hanami/configuration.rb +118 -46
- data/lib/hanami/constants.rb +24 -2
- data/lib/hanami/errors.rb +1 -1
- data/lib/hanami/{application → extensions}/action/slice_configured_action.rb +9 -9
- data/lib/hanami/extensions/action.rb +79 -0
- data/lib/hanami/extensions/view/context.rb +106 -0
- data/lib/hanami/{application → extensions}/view/slice_configured_context.rb +10 -10
- data/lib/hanami/{application → extensions}/view/slice_configured_view.rb +12 -6
- data/lib/hanami/extensions/view.rb +33 -0
- data/lib/hanami/extensions.rb +10 -0
- data/lib/hanami/providers/inflector.rb +13 -0
- data/lib/hanami/providers/logger.rb +13 -0
- data/lib/hanami/providers/rack.rb +27 -0
- data/lib/hanami/providers/routes.rb +33 -0
- data/lib/hanami/providers/settings.rb +23 -0
- data/lib/hanami/rake_tasks.rb +61 -0
- data/lib/hanami/routes.rb +51 -0
- data/lib/hanami/server.rb +1 -1
- data/lib/hanami/settings/dotenv_store.rb +58 -0
- data/lib/hanami/settings.rb +90 -0
- data/lib/hanami/setup.rb +4 -2
- data/lib/hanami/{application → slice}/router.rb +18 -13
- data/lib/hanami/slice/routes_helper.rb +37 -0
- data/lib/hanami/{application → slice}/routing/middleware/stack.rb +43 -5
- data/lib/hanami/slice/routing/resolver.rb +97 -0
- data/lib/hanami/{application → slice}/view_name_inferrer.rb +3 -3
- data/lib/hanami/slice.rb +246 -73
- data/lib/hanami/slice_configurable.rb +4 -17
- data/lib/hanami/slice_name.rb +6 -6
- data/lib/hanami/slice_registrar.rb +119 -0
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami/web/rack_logger.rb +1 -1
- data/lib/hanami.rb +34 -26
- data/spec/integration/application_middleware_stack_spec.rb +84 -0
- data/spec/integration/assets/cdn_spec.rb +48 -0
- data/spec/integration/assets/fingerprint_spec.rb +42 -0
- data/spec/integration/assets/helpers_spec.rb +50 -0
- data/spec/integration/assets/serve_spec.rb +70 -0
- data/spec/integration/assets/subresource_integrity_spec.rb +54 -0
- data/spec/integration/body_parsers_spec.rb +50 -0
- data/spec/integration/cli/assets/precompile_spec.rb +147 -0
- data/spec/integration/cli/assets_spec.rb +14 -0
- data/spec/integration/cli/console_spec.rb +105 -0
- data/spec/integration/cli/db/apply_spec.rb +74 -0
- data/spec/integration/cli/db/console_spec.rb +40 -0
- data/spec/integration/cli/db/create_spec.rb +50 -0
- data/spec/integration/cli/db/drop_spec.rb +54 -0
- data/spec/integration/cli/db/migrate_spec.rb +108 -0
- data/spec/integration/cli/db/prepare_spec.rb +36 -0
- data/spec/integration/cli/db/rollback_spec.rb +96 -0
- data/spec/integration/cli/db/version_spec.rb +38 -0
- data/spec/integration/cli/db_spec.rb +21 -0
- data/spec/integration/cli/destroy/action_spec.rb +143 -0
- data/spec/integration/cli/destroy/app_spec.rb +118 -0
- data/spec/integration/cli/destroy/mailer_spec.rb +74 -0
- data/spec/integration/cli/destroy/migration_spec.rb +70 -0
- data/spec/integration/cli/destroy/model_spec.rb +113 -0
- data/spec/integration/cli/destroy_spec.rb +18 -0
- data/spec/integration/cli/generate/action_spec.rb +469 -0
- data/spec/integration/cli/generate/app_spec.rb +215 -0
- data/spec/integration/cli/generate/mailer_spec.rb +189 -0
- data/spec/integration/cli/generate/migration_spec.rb +72 -0
- data/spec/integration/cli/generate/model_spec.rb +290 -0
- data/spec/integration/cli/generate/secret_spec.rb +56 -0
- data/spec/integration/cli/generate_spec.rb +19 -0
- data/spec/integration/cli/new/database_spec.rb +235 -0
- data/spec/integration/cli/new/hanami_head_spec.rb +27 -0
- data/spec/integration/cli/new/template_spec.rb +118 -0
- data/spec/integration/cli/new/test_spec.rb +274 -0
- data/spec/integration/cli/new_spec.rb +970 -0
- data/spec/integration/cli/plugins_spec.rb +39 -0
- data/spec/integration/cli/routes_spec.rb +49 -0
- data/spec/integration/cli/server_spec.rb +626 -0
- data/spec/integration/cli/version_spec.rb +85 -0
- data/spec/integration/early_hints_spec.rb +35 -0
- data/spec/integration/handle_exceptions_spec.rb +244 -0
- data/spec/integration/head_spec.rb +89 -0
- data/spec/integration/http_headers_spec.rb +29 -0
- data/spec/integration/mailer_spec.rb +32 -0
- data/spec/integration/middleware_spec.rb +81 -0
- data/spec/integration/mount_applications_spec.rb +88 -0
- data/spec/integration/project_initializers_spec.rb +40 -0
- data/spec/integration/rackup_spec.rb +35 -0
- data/spec/integration/rake/with_minitest_spec.rb +67 -0
- data/spec/integration/rake/with_rspec_spec.rb +69 -0
- data/spec/integration/routing_helpers_spec.rb +61 -0
- data/spec/integration/security/content_security_policy_spec.rb +46 -0
- data/spec/integration/security/csrf_protection_spec.rb +42 -0
- data/spec/integration/security/force_ssl_spec.rb +29 -0
- data/spec/integration/security/x_content_type_options_spec.rb +46 -0
- data/spec/integration/security/x_frame_options_spec.rb +46 -0
- data/spec/integration/security/x_xss_protection_spec.rb +46 -0
- data/spec/integration/send_file_spec.rb +51 -0
- data/spec/integration/sessions_spec.rb +247 -0
- data/spec/integration/static_middleware_spec.rb +21 -0
- data/spec/integration/streaming_spec.rb +41 -0
- data/spec/integration/unsafe_send_file_spec.rb +52 -0
- data/spec/isolation/hanami/application/already_configured_spec.rb +19 -0
- data/spec/isolation/hanami/application/inherit_anonymous_class_spec.rb +10 -0
- data/spec/isolation/hanami/application/inherit_concrete_class_spec.rb +14 -0
- data/spec/isolation/hanami/application/not_configured_spec.rb +9 -0
- data/spec/isolation/hanami/application/routes/configured_spec.rb +44 -0
- data/spec/isolation/hanami/application/routes/not_configured_spec.rb +16 -0
- data/spec/isolation/hanami/boot/success_spec.rb +50 -0
- data/spec/new_integration/action/configuration_spec.rb +26 -0
- data/spec/new_integration/action/cookies_spec.rb +58 -0
- data/spec/new_integration/action/csrf_protection_spec.rb +54 -0
- data/spec/new_integration/action/routes_spec.rb +73 -0
- data/spec/new_integration/action/sessions_spec.rb +50 -0
- data/spec/new_integration/action/view_integration_spec.rb +165 -0
- data/spec/new_integration/action/view_rendering/automatic_rendering_spec.rb +247 -0
- data/spec/new_integration/action/view_rendering/paired_view_inference_spec.rb +115 -0
- data/spec/new_integration/action/view_rendering_spec.rb +107 -0
- data/spec/new_integration/code_loading/loading_from_app_spec.rb +152 -0
- data/spec/new_integration/code_loading/loading_from_slice_spec.rb +165 -0
- data/spec/new_integration/container/application_routes_helper_spec.rb +48 -0
- data/spec/new_integration/container/auto_injection_spec.rb +53 -0
- data/spec/new_integration/container/auto_registration_spec.rb +86 -0
- data/spec/new_integration/container/autoloader_spec.rb +80 -0
- data/spec/new_integration/container/imports_spec.rb +253 -0
- data/spec/new_integration/container/prepare_container_spec.rb +123 -0
- data/spec/new_integration/container/shutdown_spec.rb +91 -0
- data/spec/new_integration/container/standard_bootable_components_spec.rb +124 -0
- data/spec/new_integration/rack_app/middleware_spec.rb +215 -0
- data/spec/new_integration/rack_app/non_booted_rack_app_spec.rb +105 -0
- data/spec/new_integration/rack_app/rack_app_spec.rb +524 -0
- data/spec/new_integration/settings_spec.rb +115 -0
- data/spec/new_integration/slices/external_slice_spec.rb +92 -0
- data/spec/new_integration/slices/slice_configuration_spec.rb +40 -0
- data/spec/new_integration/slices/slice_routing_spec.rb +226 -0
- data/spec/new_integration/slices/slice_settings_spec.rb +141 -0
- data/spec/new_integration/slices_spec.rb +101 -0
- data/spec/new_integration/view/configuration_spec.rb +49 -0
- data/spec/new_integration/view/context/assets_spec.rb +67 -0
- data/spec/new_integration/view/context/inflector_spec.rb +48 -0
- data/spec/new_integration/view/context/request_spec.rb +61 -0
- data/spec/new_integration/view/context/routes_spec.rb +86 -0
- data/spec/new_integration/view/context/settings_spec.rb +50 -0
- data/spec/new_integration/view/inflector_spec.rb +57 -0
- data/spec/new_integration/view/part_namespace_spec.rb +96 -0
- data/spec/new_integration/view/path_spec.rb +56 -0
- data/spec/new_integration/view/template_spec.rb +68 -0
- data/spec/new_integration/view/views_spec.rb +103 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/app_integration.rb +91 -0
- data/spec/support/coverage.rb +1 -0
- data/spec/support/fixtures/hanami-plugin/Gemfile +8 -0
- data/spec/support/fixtures/hanami-plugin/README.md +35 -0
- data/spec/support/fixtures/hanami-plugin/Rakefile +4 -0
- data/spec/support/fixtures/hanami-plugin/bin/console +15 -0
- data/spec/support/fixtures/hanami-plugin/bin/setup +8 -0
- data/spec/support/fixtures/hanami-plugin/hanami-plugin.gemspec +28 -0
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/cli.rb +19 -0
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/version.rb +7 -0
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin.rb +8 -0
- data/spec/support/rspec.rb +27 -0
- data/spec/support/shared_examples/cli/generate/app.rb +494 -0
- data/spec/support/shared_examples/cli/generate/migration.rb +32 -0
- data/spec/support/shared_examples/cli/generate/model.rb +81 -0
- data/spec/support/shared_examples/cli/new.rb +97 -0
- data/spec/unit/hanami/configuration/actions/content_security_policy_spec.rb +102 -0
- data/spec/unit/hanami/configuration/actions/cookies_spec.rb +46 -0
- data/spec/unit/hanami/configuration/actions/csrf_protection_spec.rb +57 -0
- data/spec/unit/hanami/configuration/actions/default_values_spec.rb +52 -0
- data/spec/unit/hanami/configuration/actions/sessions_spec.rb +50 -0
- data/spec/unit/hanami/configuration/actions_spec.rb +78 -0
- data/spec/unit/hanami/configuration/base_url_spec.rb +25 -0
- data/spec/unit/hanami/configuration/inflector_spec.rb +35 -0
- data/spec/unit/hanami/configuration/logger_spec.rb +203 -0
- data/spec/unit/hanami/configuration/views_spec.rb +120 -0
- data/spec/unit/hanami/configuration_spec.rb +43 -0
- data/spec/unit/hanami/env_spec.rb +54 -0
- data/spec/unit/hanami/routes_spec.rb +25 -0
- data/spec/unit/hanami/settings/dotenv_store_spec.rb +119 -0
- data/spec/unit/hanami/settings_spec.rb +56 -0
- data/spec/unit/hanami/slice_configurable_spec.rb +104 -0
- data/spec/unit/hanami/slice_name_spec.rb +47 -0
- data/spec/unit/hanami/slice_spec.rb +17 -0
- data/spec/unit/hanami/version_spec.rb +7 -0
- data/spec/unit/hanami/web/rack_logger_spec.rb +78 -0
- metadata +353 -57
- data/lib/hanami/application/action.rb +0 -72
- data/lib/hanami/application/container/providers/inflector.rb +0 -7
- data/lib/hanami/application/container/providers/logger.rb +0 -7
- data/lib/hanami/application/container/providers/rack_logger.rb +0 -15
- data/lib/hanami/application/container/providers/rack_monitor.rb +0 -12
- data/lib/hanami/application/container/providers/routes_helper.rb +0 -9
- data/lib/hanami/application/container/providers/settings.rb +0 -7
- data/lib/hanami/application/routes.rb +0 -55
- data/lib/hanami/application/routes_helper.rb +0 -34
- data/lib/hanami/application/routing/resolver/node.rb +0 -50
- data/lib/hanami/application/routing/resolver/trie.rb +0 -59
- data/lib/hanami/application/routing/resolver.rb +0 -87
- data/lib/hanami/application/routing/router.rb +0 -36
- data/lib/hanami/application/settings/dotenv_store.rb +0 -60
- data/lib/hanami/application/settings.rb +0 -93
- data/lib/hanami/application/slice_registrar.rb +0 -106
- data/lib/hanami/application/view/context.rb +0 -95
- data/lib/hanami/application/view.rb +0 -24
- data/lib/hanami/application.rb +0 -273
- data/lib/hanami/cli/application/cli.rb +0 -40
- data/lib/hanami/cli/application/command.rb +0 -47
- data/lib/hanami/cli/application/commands/console.rb +0 -81
- data/lib/hanami/cli/application/commands.rb +0 -16
- data/lib/hanami/cli/base_command.rb +0 -48
- data/lib/hanami/cli/commands/command.rb +0 -171
- data/lib/hanami/cli/commands/server.rb +0 -88
- data/lib/hanami/cli/commands.rb +0 -65
- data/lib/hanami/configuration/middleware.rb +0 -20
- data/lib/hanami/configuration/source_dirs.rb +0 -42
data/FEATURES.md
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
# Hanami
|
|
2
|
+
|
|
2
3
|
### The web, with simplicity.
|
|
3
4
|
|
|
4
5
|
## Features
|
|
5
6
|
|
|
7
|
+
## v2.0.0.beta1 - 2021-07-20
|
|
8
|
+
|
|
9
|
+
- Generate new apps using `app/` directory
|
|
10
|
+
|
|
11
|
+
## v2.0.0.alpha8 - 2021-05-19
|
|
12
|
+
|
|
13
|
+
## v2.0.0.alpha7.1 - 2021-03-09
|
|
14
|
+
|
|
15
|
+
## v2.0.0.alpha7 - 2021-03-08
|
|
16
|
+
|
|
17
|
+
## v2.0.0.alpha6 - 2021-02-10
|
|
18
|
+
|
|
19
|
+
## v2.0.0.alpha5 - 2021-01-12
|
|
20
|
+
|
|
21
|
+
## v2.0.0.alpha4 - 2021-12-07
|
|
22
|
+
|
|
23
|
+
## v2.0.0.alpha3 - 2021-11-09
|
|
24
|
+
|
|
25
|
+
## v2.0.0.alpha2 - 2021-05-04
|
|
26
|
+
|
|
6
27
|
## v2.0.0.alpha1 - 2019-01-30
|
|
7
28
|
|
|
8
29
|
## v1.3.3 - 2019-09-20
|
|
@@ -110,14 +131,14 @@
|
|
|
110
131
|
- Assets preprocessors support (eg. Sass, ES6, Opal, Less, CoffeScript..)
|
|
111
132
|
- Assets compressors (eg. YUI, UglifyJS2, Google Closure Compiler, Sass..)
|
|
112
133
|
- Assets helpers:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
134
|
+
- `javascript`
|
|
135
|
+
- `stylesheet`
|
|
136
|
+
- `favicon`
|
|
137
|
+
- `image`
|
|
138
|
+
- `video`
|
|
139
|
+
- `audio`
|
|
140
|
+
- `asset_path`
|
|
141
|
+
- `asset_url`
|
|
121
142
|
- Content Delivery Network (CDN) support for static assets (CDN mode)
|
|
122
143
|
- Checksum suffix for static assets in production mode (Digest mode)
|
|
123
144
|
- Support for third party gems as assets distribution channel (eg. `lotus-jquery`)
|
|
@@ -159,7 +180,7 @@
|
|
|
159
180
|
- `Lotus.env` and `Lotus.env?` for current environment introspection (eg. `Lotus.env?(:test)` or `Lotus.env?(:staging, :production)`)
|
|
160
181
|
- Allow repositories to execute raw query/commands against database
|
|
161
182
|
- Automatic timestamps update for entities
|
|
162
|
-
– Dirty Tracking for entities (via `Lotus::Entity::DirtyTracking`)
|
|
183
|
+
– Dirty Tracking for entities (via `Lotus::Entity::DirtyTracking`)
|
|
163
184
|
- Nested RESTful resource(s)
|
|
164
185
|
- String pluralization and singularization
|
|
165
186
|
|
data/README.md
CHANGED
|
@@ -14,10 +14,8 @@ It's made up of smaller, single-purpose libraries.
|
|
|
14
14
|
This repository is for the full-stack framework,
|
|
15
15
|
which provides the glue that ties all the parts together:
|
|
16
16
|
|
|
17
|
-
* [**Hanami::Model**](https://github.com/hanami/model) - Persistence with entities, repositories and data mapper
|
|
18
17
|
* [**Hanami::View**](https://github.com/hanami/view) - Presentation with a separation between views and templates
|
|
19
18
|
* [**Hanami::Controller**](https://github.com/hanami/controller) - Full featured, fast and testable actions for Rack
|
|
20
|
-
* [**Hanami::Validations**](https://github.com/hanami/validations) - Validations mixin for Ruby objects
|
|
21
19
|
* [**Hanami::Router**](https://github.com/hanami/router) - Rack compatible HTTP router for Ruby
|
|
22
20
|
* [**Hanami::Helpers**](https://github.com/hanami/helpers) - View helpers for Ruby applications
|
|
23
21
|
* [**Hanami::Mailer**](https://github.com/hanami/mailer) - Mail for Ruby applications
|
|
@@ -54,7 +52,7 @@ Please follow along with the [Getting Started guide](https://guides.hanamirb.org
|
|
|
54
52
|
|
|
55
53
|
## Donations
|
|
56
54
|
|
|
57
|
-
You can give back to Open Source, by supporting Hanami development via
|
|
55
|
+
You can give back to Open Source, by supporting Hanami development via [GitHub Sponsors](https://github.com/sponsors/hanami).
|
|
58
56
|
|
|
59
57
|
### Supporters
|
|
60
58
|
|
data/hanami.gemspec
CHANGED
|
@@ -14,23 +14,33 @@ Gem::Specification.new do |spec|
|
|
|
14
14
|
spec.homepage = "http://hanamirb.org"
|
|
15
15
|
spec.license = "MIT"
|
|
16
16
|
|
|
17
|
-
spec.files =
|
|
18
|
-
|
|
17
|
+
spec.files = Dir[
|
|
18
|
+
"CODE_OF_CONDUCT.md",
|
|
19
|
+
"CHANGELOG.md",
|
|
20
|
+
"FEATURES.md",
|
|
21
|
+
"LICENSE.md",
|
|
22
|
+
"README.md",
|
|
23
|
+
"hanami.gemspec",
|
|
24
|
+
"lib/**/*"
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
spec.test_files = Dir["spec/**/*"]
|
|
19
28
|
spec.require_paths = ["lib"]
|
|
20
29
|
spec.metadata["rubygems_mfa_required"] = "true"
|
|
21
30
|
spec.required_ruby_version = ">= 3.0"
|
|
22
31
|
|
|
23
32
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
24
33
|
|
|
25
|
-
spec.add_dependency "bundler",
|
|
26
|
-
spec.add_dependency "dry-configurable",
|
|
27
|
-
spec.add_dependency "dry-core",
|
|
28
|
-
spec.add_dependency "dry-
|
|
29
|
-
spec.add_dependency "dry-
|
|
30
|
-
spec.add_dependency "dry-system",
|
|
31
|
-
spec.add_dependency "
|
|
32
|
-
spec.add_dependency "hanami-
|
|
33
|
-
spec.add_dependency "
|
|
34
|
+
spec.add_dependency "bundler", ">= 1.16", "< 3"
|
|
35
|
+
spec.add_dependency "dry-configurable", "~> 0.15"
|
|
36
|
+
spec.add_dependency "dry-core", "~> 0.7"
|
|
37
|
+
spec.add_dependency "dry-types", "~> 1.5"
|
|
38
|
+
spec.add_dependency "dry-inflector", "~> 0.2", ">= 0.2.1"
|
|
39
|
+
spec.add_dependency "dry-system", "~> 0.25", ">= 0.25.0"
|
|
40
|
+
spec.add_dependency "dry-monitor", "~> 0.6", ">= 0.6.0"
|
|
41
|
+
spec.add_dependency "hanami-cli", "~> 2.0.alpha"
|
|
42
|
+
spec.add_dependency "hanami-utils", "~> 2.0.alpha"
|
|
43
|
+
spec.add_dependency "zeitwerk", "~> 2.4"
|
|
34
44
|
|
|
35
45
|
spec.add_development_dependency "rspec", "~> 3.8"
|
|
36
46
|
spec.add_development_dependency "rack-test", "~> 1.1"
|
data/lib/hanami/app.rb
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "zeitwerk"
|
|
4
|
+
require_relative "configuration"
|
|
5
|
+
require_relative "constants"
|
|
6
|
+
require_relative "slice"
|
|
7
|
+
require_relative "slice_name"
|
|
8
|
+
|
|
9
|
+
module Hanami
|
|
10
|
+
# The Hanami app is a singular slice tasked with managing the core components of
|
|
11
|
+
# the app and coordinating overall app boot.
|
|
12
|
+
#
|
|
13
|
+
# For smaller apps, the app may be the only slice present, whereas larger apps
|
|
14
|
+
# may consist of many slices, with the app reserved for holding a small number
|
|
15
|
+
# of shared components only.
|
|
16
|
+
#
|
|
17
|
+
# @see Slice
|
|
18
|
+
#
|
|
19
|
+
# @api public
|
|
20
|
+
# @since 2.0.0
|
|
21
|
+
class App < Slice
|
|
22
|
+
@_mutex = Mutex.new
|
|
23
|
+
|
|
24
|
+
def self.inherited(subclass)
|
|
25
|
+
super
|
|
26
|
+
|
|
27
|
+
Hanami.app = subclass
|
|
28
|
+
|
|
29
|
+
subclass.extend(ClassMethods)
|
|
30
|
+
|
|
31
|
+
@_mutex.synchronize do
|
|
32
|
+
subclass.class_eval do
|
|
33
|
+
@configuration = Hanami::Configuration.new(app_name: slice_name, env: Hanami.env)
|
|
34
|
+
@autoloader = Zeitwerk::Loader.new
|
|
35
|
+
|
|
36
|
+
prepare_base_load_path
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# App class interface
|
|
42
|
+
module ClassMethods
|
|
43
|
+
attr_reader :autoloader, :configuration
|
|
44
|
+
|
|
45
|
+
def app_name
|
|
46
|
+
slice_name
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def prepare_base_load_path
|
|
52
|
+
base_path = root.join(LIB_DIR)
|
|
53
|
+
$LOAD_PATH.unshift(base_path) unless $LOAD_PATH.include?(base_path)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def prepare_all
|
|
57
|
+
# Make app-wide notifications available as early as possible
|
|
58
|
+
container.use(:notifications)
|
|
59
|
+
|
|
60
|
+
# Ensure all basic slice preparation is complete before we make adjustments below
|
|
61
|
+
# (which rely on the basic prepare steps having already run)
|
|
62
|
+
super
|
|
63
|
+
|
|
64
|
+
# Run specific prepare steps for the app slice. Note also that some
|
|
65
|
+
# standard steps have been skipped via the empty method overrides below.
|
|
66
|
+
prepare_app_component_dirs
|
|
67
|
+
prepare_app_providers
|
|
68
|
+
|
|
69
|
+
# The autoloader must be setup after the container is configured, which is the
|
|
70
|
+
# point at which any component dirs from other slices are added to the autoloader
|
|
71
|
+
app = self
|
|
72
|
+
container.after(:configure) do
|
|
73
|
+
app.send(:prepare_app_autoloader)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Skip standard slice prepare steps that do not apply to the app slice
|
|
78
|
+
def prepare_container_component_dirs; end
|
|
79
|
+
def prepare_container_imports; end
|
|
80
|
+
|
|
81
|
+
# rubocop:disable Metrics/AbcSize
|
|
82
|
+
|
|
83
|
+
def prepare_app_component_dirs
|
|
84
|
+
# Component files in both `app/` and `app/lib/` define classes in the
|
|
85
|
+
# app's namespace
|
|
86
|
+
|
|
87
|
+
if root.join(APP_DIR, LIB_DIR).directory?
|
|
88
|
+
container.config.component_dirs.add(File.join(APP_DIR, LIB_DIR)) do |dir|
|
|
89
|
+
dir.namespaces.add_root(key: nil, const: app_name.name)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# When auto-registering components in app/, ignore files in `app/lib/` (these will
|
|
94
|
+
# be auto-registered as above), as well as the configured no_auto_register_paths
|
|
95
|
+
no_auto_register_paths = ([LIB_DIR] + configuration.no_auto_register_paths)
|
|
96
|
+
.map { |path|
|
|
97
|
+
path.end_with?(File::SEPARATOR) ? path : "#{path}#{File::SEPARATOR}"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if root.join(APP_DIR).directory?
|
|
101
|
+
container.config.component_dirs.add(APP_DIR) do |dir|
|
|
102
|
+
dir.namespaces.add_root(key: nil, const: app_name.name)
|
|
103
|
+
dir.auto_register = -> component {
|
|
104
|
+
relative_path = component.file_path.relative_path_from(root.join(APP_DIR)).to_s
|
|
105
|
+
!relative_path.start_with?(*no_auto_register_paths)
|
|
106
|
+
}
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def prepare_app_providers
|
|
112
|
+
require_relative "providers/inflector"
|
|
113
|
+
register_provider(:inflector, source: Hanami::Providers::Inflector)
|
|
114
|
+
|
|
115
|
+
# Allow logger to be replaced by users with a manual provider, for advanced cases
|
|
116
|
+
unless container.providers.find_and_load_provider(:logger)
|
|
117
|
+
require_relative "providers/logger"
|
|
118
|
+
register_provider(:logger, source: Hanami::Providers::Logger)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
require_relative "providers/rack"
|
|
122
|
+
register_provider(:rack, source: Hanami::Providers::Rack, namespace: true)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def prepare_app_autoloader
|
|
126
|
+
# Component dirs are automatically pushed to the autoloader by dry-system's
|
|
127
|
+
# zeitwerk plugin. This method adds other dirs that are not otherwise configured
|
|
128
|
+
# as component dirs.
|
|
129
|
+
|
|
130
|
+
# Autoload classes from `lib/[app_namespace]/`
|
|
131
|
+
if root.join(LIB_DIR, app_name.name).directory?
|
|
132
|
+
autoloader.push_dir(root.join(LIB_DIR, app_name.name), namespace: namespace)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
autoloader.setup
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# rubocop:enable Metrics/AbcSize
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
@@ -10,6 +10,11 @@ module Hanami
|
|
|
10
10
|
class ApplicationConfiguration
|
|
11
11
|
include Dry::Configurable
|
|
12
12
|
|
|
13
|
+
# @since 2.0.0
|
|
14
|
+
# @api private
|
|
15
|
+
attr_reader :base_configuration
|
|
16
|
+
protected :base_configuration
|
|
17
|
+
|
|
13
18
|
setting :server_url, default: "http://localhost:8080"
|
|
14
19
|
|
|
15
20
|
# @since 2.0.0
|
|
@@ -20,6 +25,11 @@ module Hanami
|
|
|
20
25
|
@base_configuration = Assets::Configuration.new
|
|
21
26
|
end
|
|
22
27
|
|
|
28
|
+
def initialize_copy(source)
|
|
29
|
+
super
|
|
30
|
+
@base_configuration = source.base_configuration.dup
|
|
31
|
+
end
|
|
32
|
+
|
|
23
33
|
# @since 2.0.0
|
|
24
34
|
# @api private
|
|
25
35
|
def finalize!
|
|
@@ -37,10 +47,6 @@ module Hanami
|
|
|
37
47
|
|
|
38
48
|
private
|
|
39
49
|
|
|
40
|
-
# @since 2.0.0
|
|
41
|
-
# @api private
|
|
42
|
-
attr_reader :base_configuration
|
|
43
|
-
|
|
44
50
|
# @since 2.0.0
|
|
45
51
|
# @api private
|
|
46
52
|
def method_missing(name, *args, &block)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Hanami
|
|
4
4
|
class Configuration
|
|
5
5
|
class Actions
|
|
6
|
-
# Configuration for Content Security Policy in Hanami
|
|
6
|
+
# Configuration for Content Security Policy in Hanami apps
|
|
7
7
|
#
|
|
8
8
|
# @since 2.0.0
|
|
9
9
|
class ContentSecurityPolicy
|
|
@@ -47,7 +47,7 @@ module Hanami
|
|
|
47
47
|
#
|
|
48
48
|
# @example
|
|
49
49
|
# module MyApp
|
|
50
|
-
# class
|
|
50
|
+
# class App < Hanami::App
|
|
51
51
|
# config.actions.content_security_policy[:base_uri] # => "'self'"
|
|
52
52
|
# end
|
|
53
53
|
# end
|
|
@@ -65,14 +65,14 @@ module Hanami
|
|
|
65
65
|
#
|
|
66
66
|
# @example Replace a default value
|
|
67
67
|
# module MyApp
|
|
68
|
-
# class
|
|
68
|
+
# class App < Hanami::App
|
|
69
69
|
# config.actions.content_security_policy[:plugin_types] = nil
|
|
70
70
|
# end
|
|
71
71
|
# end
|
|
72
72
|
#
|
|
73
73
|
# @example Append to a default value
|
|
74
74
|
# module MyApp
|
|
75
|
-
# class
|
|
75
|
+
# class App < Hanami::App
|
|
76
76
|
# config.actions.content_security_policy[:script_src] += " https://my.cdn.test"
|
|
77
77
|
# end
|
|
78
78
|
# end
|
|
@@ -89,7 +89,7 @@ module Hanami
|
|
|
89
89
|
#
|
|
90
90
|
# @example
|
|
91
91
|
# module MyApp
|
|
92
|
-
# class
|
|
92
|
+
# class App < Hanami::App
|
|
93
93
|
# config.actions.content_security_policy.delete(:object_src)
|
|
94
94
|
# end
|
|
95
95
|
# end
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
module Hanami
|
|
4
4
|
class Configuration
|
|
5
5
|
class Actions
|
|
6
|
-
# Wrapper for
|
|
6
|
+
# Wrapper for app-level configuration of HTTP cookies for Hanami actions.
|
|
7
7
|
# This decorates the hash of cookie options that is otherwise directly configurable
|
|
8
|
-
# on actions, and adds the `enabled?` method to allow
|
|
8
|
+
# on actions, and adds the `enabled?` method to allow app base action to
|
|
9
9
|
# determine whether to include the `Action::Cookies` module.
|
|
10
10
|
#
|
|
11
11
|
# @since 2.0.0
|
|
@@ -5,7 +5,7 @@ require "hanami/action/configuration"
|
|
|
5
5
|
require_relative "actions/cookies"
|
|
6
6
|
require_relative "actions/sessions"
|
|
7
7
|
require_relative "actions/content_security_policy"
|
|
8
|
-
require_relative "../
|
|
8
|
+
require_relative "../slice/view_name_inferrer"
|
|
9
9
|
|
|
10
10
|
module Hanami
|
|
11
11
|
class Configuration
|
|
@@ -20,14 +20,14 @@ module Hanami
|
|
|
20
20
|
setting :csrf_protection
|
|
21
21
|
|
|
22
22
|
setting :name_inference_base, default: "actions"
|
|
23
|
-
setting :view_context_identifier, default: "
|
|
24
|
-
setting :view_name_inferrer, default:
|
|
23
|
+
setting :view_context_identifier, default: "views.context"
|
|
24
|
+
setting :view_name_inferrer, default: Slice::ViewNameInferrer
|
|
25
25
|
setting :view_name_inference_base, default: "views"
|
|
26
26
|
|
|
27
27
|
attr_accessor :content_security_policy
|
|
28
28
|
|
|
29
29
|
attr_reader :base_configuration
|
|
30
|
-
|
|
30
|
+
protected :base_configuration
|
|
31
31
|
|
|
32
32
|
def initialize(*, **options)
|
|
33
33
|
super()
|
|
@@ -43,6 +43,12 @@ module Hanami
|
|
|
43
43
|
configure_defaults
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
+
def initialize_copy(source)
|
|
47
|
+
super
|
|
48
|
+
@base_configuration = source.base_configuration.dup
|
|
49
|
+
@content_security_policy = source.content_security_policy.dup
|
|
50
|
+
end
|
|
51
|
+
|
|
46
52
|
def finalize!
|
|
47
53
|
# A nil value for `csrf_protection` means it has not been explicitly configured
|
|
48
54
|
# (neither true nor false), so we can default it to whether sessions are enabled
|
|
@@ -11,7 +11,7 @@ module Hanami
|
|
|
11
11
|
class Logger
|
|
12
12
|
include Dry::Configurable
|
|
13
13
|
|
|
14
|
-
attr_reader :
|
|
14
|
+
attr_reader :app_name
|
|
15
15
|
|
|
16
16
|
protected :config
|
|
17
17
|
|
|
@@ -29,8 +29,8 @@ module Hanami
|
|
|
29
29
|
|
|
30
30
|
setting :logger_class, default: Hanami::Logger
|
|
31
31
|
|
|
32
|
-
def initialize(env:,
|
|
33
|
-
@
|
|
32
|
+
def initialize(env:, app_name:)
|
|
33
|
+
@app_name = app_name
|
|
34
34
|
|
|
35
35
|
config.level = case env
|
|
36
36
|
when :production
|
|
@@ -59,7 +59,7 @@ module Hanami
|
|
|
59
59
|
|
|
60
60
|
def instance
|
|
61
61
|
logger_class.new(
|
|
62
|
-
|
|
62
|
+
app_name.name,
|
|
63
63
|
*options,
|
|
64
64
|
stream: stream,
|
|
65
65
|
level: level,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "dry/configurable"
|
|
4
|
-
require_relative "../
|
|
4
|
+
require_relative "../slice/routing/resolver"
|
|
5
5
|
|
|
6
6
|
module Hanami
|
|
7
7
|
class Configuration
|
|
@@ -22,11 +22,7 @@ module Hanami
|
|
|
22
22
|
@base_configuration = base_configuration
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
setting :
|
|
26
|
-
|
|
27
|
-
setting :routes_class_name, default: "Routes"
|
|
28
|
-
|
|
29
|
-
setting :resolver, default: Application::Routing::Resolver
|
|
25
|
+
setting :resolver, default: Slice::Routing::Resolver
|
|
30
26
|
|
|
31
27
|
# @api private
|
|
32
28
|
# @since 2.0.0
|
|
@@ -11,10 +11,10 @@ module Hanami
|
|
|
11
11
|
class Views
|
|
12
12
|
include Dry::Configurable
|
|
13
13
|
|
|
14
|
-
setting :parts_path, default: "
|
|
14
|
+
setting :parts_path, default: "views/parts"
|
|
15
15
|
|
|
16
16
|
attr_reader :base_configuration
|
|
17
|
-
|
|
17
|
+
protected :base_configuration
|
|
18
18
|
|
|
19
19
|
def initialize(*)
|
|
20
20
|
super
|
|
@@ -24,6 +24,11 @@ module Hanami
|
|
|
24
24
|
configure_defaults
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
def initialize_copy(source)
|
|
28
|
+
super
|
|
29
|
+
@base_configuration = source.base_configuration.dup
|
|
30
|
+
end
|
|
31
|
+
|
|
27
32
|
# Returns the list of available settings
|
|
28
33
|
#
|
|
29
34
|
# @return [Set]
|
|
@@ -47,11 +52,11 @@ module Hanami
|
|
|
47
52
|
def configure_defaults
|
|
48
53
|
self.paths = ["templates"]
|
|
49
54
|
self.template_inference_base = "views"
|
|
50
|
-
self.layout = "
|
|
55
|
+
self.layout = "app"
|
|
51
56
|
end
|
|
52
57
|
|
|
53
58
|
# An inflector for views is not configurable via `config.views.inflector` on an
|
|
54
|
-
# `Hanami::
|
|
59
|
+
# `Hanami::App`. The app-wide inflector is already configurable
|
|
55
60
|
# there as `config.inflector` and will be used as the default inflector for views.
|
|
56
61
|
#
|
|
57
62
|
# A custom inflector may still be provided in an `Hanami::View` subclass, via
|