hanami 1.3.5 → 2.0.0.alpha4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +196 -5
- data/FEATURES.md +1 -3
- data/README.md +4 -4
- data/hanami.gemspec +27 -30
- data/lib/hanami/application/autoloader/inflector_adapter.rb +22 -0
- data/lib/hanami/application/container/boot/inflector.rb +7 -0
- data/lib/hanami/application/container/boot/logger.rb +7 -0
- data/lib/hanami/application/container/boot/rack_logger.rb +19 -0
- data/lib/hanami/application/container/boot/rack_monitor.rb +12 -0
- data/lib/hanami/application/container/boot/routes_helper.rb +9 -0
- data/lib/hanami/application/container/boot/settings.rb +7 -0
- data/lib/hanami/application/router.rb +59 -0
- data/lib/hanami/application/routes.rb +55 -0
- data/lib/hanami/application/routes_helper.rb +34 -0
- data/lib/hanami/application/routing/middleware/stack.rb +89 -0
- data/lib/hanami/application/routing/resolver/node.rb +50 -0
- data/lib/hanami/application/routing/resolver/trie.rb +59 -0
- data/lib/hanami/application/routing/resolver.rb +87 -0
- data/lib/hanami/application/settings/dotenv_store.rb +60 -0
- data/lib/hanami/application/settings.rb +93 -0
- data/lib/hanami/application.rb +349 -174
- data/lib/hanami/assets/application_configuration.rb +63 -0
- data/lib/hanami/assets/configuration.rb +54 -0
- data/lib/hanami/boot.rb +5 -0
- data/lib/hanami/cli/application/cli.rb +40 -0
- data/lib/hanami/cli/application/command.rb +47 -0
- data/lib/hanami/cli/application/commands/console.rb +81 -0
- data/lib/hanami/cli/application/commands.rb +16 -0
- data/lib/hanami/cli/base_command.rb +48 -0
- data/lib/hanami/cli/commands/command.rb +23 -31
- data/lib/hanami/cli/commands/server.rb +63 -14
- data/lib/hanami/cli/commands.rb +5 -41
- data/lib/hanami/configuration/logger.rb +40 -0
- data/lib/hanami/configuration/middleware.rb +9 -29
- data/lib/hanami/configuration/null_configuration.rb +14 -0
- data/lib/hanami/configuration/router.rb +52 -0
- data/lib/hanami/configuration/sessions.rb +50 -0
- data/lib/hanami/configuration.rb +152 -185
- data/lib/hanami/init.rb +5 -0
- data/lib/hanami/server.rb +5 -69
- data/lib/hanami/setup.rb +8 -2
- data/lib/hanami/slice.rb +167 -0
- data/lib/hanami/version.rb +3 -1
- data/lib/hanami/web/rack_logger.rb +96 -0
- data/lib/hanami.rb +42 -241
- metadata +88 -222
- data/bin/hanami +0 -6
- data/lib/hanami/action/csrf_protection.rb +0 -211
- data/lib/hanami/action/routing_helpers.rb +0 -40
- data/lib/hanami/app.rb +0 -96
- data/lib/hanami/application_configuration.rb +0 -1495
- data/lib/hanami/application_name.rb +0 -108
- data/lib/hanami/application_namespace.rb +0 -14
- data/lib/hanami/assets/asset.rb +0 -72
- data/lib/hanami/assets/static.rb +0 -102
- data/lib/hanami/cli/commands/assets/precompile.rb +0 -42
- data/lib/hanami/cli/commands/assets.rb +0 -16
- data/lib/hanami/cli/commands/console.rb +0 -95
- data/lib/hanami/cli/commands/db/apply.rb +0 -32
- data/lib/hanami/cli/commands/db/console.rb +0 -44
- data/lib/hanami/cli/commands/db/create.rb +0 -32
- data/lib/hanami/cli/commands/db/drop.rb +0 -32
- data/lib/hanami/cli/commands/db/migrate.rb +0 -39
- data/lib/hanami/cli/commands/db/prepare.rb +0 -32
- data/lib/hanami/cli/commands/db/rollback.rb +0 -59
- data/lib/hanami/cli/commands/db/version.rb +0 -32
- data/lib/hanami/cli/commands/db.rb +0 -32
- data/lib/hanami/cli/commands/destroy/action.rb +0 -137
- data/lib/hanami/cli/commands/destroy/app.rb +0 -159
- data/lib/hanami/cli/commands/destroy/mailer.rb +0 -74
- data/lib/hanami/cli/commands/destroy/migration.rb +0 -51
- data/lib/hanami/cli/commands/destroy/model.rb +0 -84
- data/lib/hanami/cli/commands/destroy.rb +0 -26
- data/lib/hanami/cli/commands/generate/action/action.erb +0 -7
- data/lib/hanami/cli/commands/generate/action/action_spec.minitest.erb +0 -11
- data/lib/hanami/cli/commands/generate/action/action_spec.rspec.erb +0 -9
- data/lib/hanami/cli/commands/generate/action/action_without_view.erb +0 -7
- data/lib/hanami/cli/commands/generate/action/view.erb +0 -7
- data/lib/hanami/cli/commands/generate/action/view_spec.minitest.erb +0 -12
- data/lib/hanami/cli/commands/generate/action/view_spec.rspec.erb +0 -10
- data/lib/hanami/cli/commands/generate/action.rb +0 -321
- data/lib/hanami/cli/commands/generate/app/application.erb +0 -313
- data/lib/hanami/cli/commands/generate/app/favicon.ico +0 -0
- data/lib/hanami/cli/commands/generate/app/gitkeep.erb +0 -0
- data/lib/hanami/cli/commands/generate/app/layout.erb +0 -7
- data/lib/hanami/cli/commands/generate/app/layout_spec.minitest.erb +0 -10
- data/lib/hanami/cli/commands/generate/app/layout_spec.rspec.erb +0 -10
- data/lib/hanami/cli/commands/generate/app/routes.erb +0 -5
- data/lib/hanami/cli/commands/generate/app/template.erb.erb +0 -10
- data/lib/hanami/cli/commands/generate/app/template.haml.erb +0 -7
- data/lib/hanami/cli/commands/generate/app/template.slim.erb +0 -8
- data/lib/hanami/cli/commands/generate/app.rb +0 -243
- data/lib/hanami/cli/commands/generate/mailer/mailer.erb +0 -9
- data/lib/hanami/cli/commands/generate/mailer/mailer_spec.minitest.erb +0 -7
- data/lib/hanami/cli/commands/generate/mailer/mailer_spec.rspec.erb +0 -5
- data/lib/hanami/cli/commands/generate/mailer.rb +0 -104
- data/lib/hanami/cli/commands/generate/migration/migration.erb +0 -4
- data/lib/hanami/cli/commands/generate/migration.rb +0 -41
- data/lib/hanami/cli/commands/generate/model/entity.erb +0 -2
- data/lib/hanami/cli/commands/generate/model/entity_spec.minitest.erb +0 -5
- data/lib/hanami/cli/commands/generate/model/entity_spec.rspec.erb +0 -3
- data/lib/hanami/cli/commands/generate/model/migration.erb +0 -10
- data/lib/hanami/cli/commands/generate/model/repository.erb +0 -5
- data/lib/hanami/cli/commands/generate/model/repository_spec.minitest.erb +0 -5
- data/lib/hanami/cli/commands/generate/model/repository_spec.rspec.erb +0 -3
- data/lib/hanami/cli/commands/generate/model.rb +0 -125
- data/lib/hanami/cli/commands/generate/secret.rb +0 -48
- data/lib/hanami/cli/commands/generate.rb +0 -28
- data/lib/hanami/cli/commands/new/.env.development.erb +0 -3
- data/lib/hanami/cli/commands/new/.env.test.erb +0 -3
- data/lib/hanami/cli/commands/new/.gitkeep.erb +0 -0
- data/lib/hanami/cli/commands/new/Gemfile.erb +0 -57
- data/lib/hanami/cli/commands/new/README.md.erb +0 -33
- data/lib/hanami/cli/commands/new/config/boot.erb +0 -2
- data/lib/hanami/cli/commands/new/config/environment.erb +0 -49
- data/lib/hanami/cli/commands/new/config.ru.erb +0 -3
- data/lib/hanami/cli/commands/new/gitignore.erb +0 -4
- data/lib/hanami/cli/commands/new/gitignore_with_sqlite.erb +0 -5
- data/lib/hanami/cli/commands/new/hanamirc.erb +0 -3
- data/lib/hanami/cli/commands/new/lib/project.erb +0 -2
- data/lib/hanami/cli/commands/new/minitest/Rakefile.erb +0 -12
- data/lib/hanami/cli/commands/new/minitest/features_helper.erb +0 -11
- data/lib/hanami/cli/commands/new/minitest/spec_helper.erb +0 -7
- data/lib/hanami/cli/commands/new/rspec/Rakefile.erb +0 -9
- data/lib/hanami/cli/commands/new/rspec/capybara.erb +0 -8
- data/lib/hanami/cli/commands/new/rspec/features_helper.erb +0 -12
- data/lib/hanami/cli/commands/new/rspec/rspec.erb +0 -2
- data/lib/hanami/cli/commands/new/rspec/spec_helper.erb +0 -103
- data/lib/hanami/cli/commands/new/schema.sql.erb +0 -0
- data/lib/hanami/cli/commands/new.rb +0 -578
- data/lib/hanami/cli/commands/project.rb +0 -421
- data/lib/hanami/cli/commands/routes.rb +0 -21
- data/lib/hanami/cli/commands/templates.rb +0 -31
- data/lib/hanami/cli/commands/version.rb +0 -19
- data/lib/hanami/common_logger.rb +0 -109
- data/lib/hanami/components/app/assets.rb +0 -59
- data/lib/hanami/components/app/controller.rb +0 -74
- data/lib/hanami/components/app/routes.rb +0 -59
- data/lib/hanami/components/app/view.rb +0 -44
- data/lib/hanami/components/component.rb +0 -182
- data/lib/hanami/components/components.rb +0 -479
- data/lib/hanami/components/routes_inspector.rb +0 -72
- data/lib/hanami/components.rb +0 -156
- data/lib/hanami/config/cookies.rb +0 -69
- data/lib/hanami/config/framework_configuration.rb +0 -43
- data/lib/hanami/config/load_paths.rb +0 -46
- data/lib/hanami/config/mapper.rb +0 -47
- data/lib/hanami/config/routes.rb +0 -20
- data/lib/hanami/config/security.rb +0 -110
- data/lib/hanami/config/sessions.rb +0 -119
- data/lib/hanami/configuration/app.rb +0 -21
- data/lib/hanami/early_hints.rb +0 -129
- data/lib/hanami/env.rb +0 -69
- data/lib/hanami/environment.rb +0 -541
- data/lib/hanami/environment_application_configurations.rb +0 -37
- data/lib/hanami/frameworks.rb +0 -22
- data/lib/hanami/hanamirc.rb +0 -169
- data/lib/hanami/mailer/glue.rb +0 -27
- data/lib/hanami/middleware_stack.rb +0 -172
- data/lib/hanami/rake_helper.rb +0 -78
- data/lib/hanami/rake_tasks.rb +0 -3
- data/lib/hanami/rendering_policy.rb +0 -94
- data/lib/hanami/routes.rb +0 -219
- data/lib/hanami/routing/default.rb +0 -32
- data/lib/hanami/static.rb +0 -63
- data/lib/hanami/templates/default.html.erb +0 -30
- data/lib/hanami/templates/welcome.html.erb +0 -52
- data/lib/hanami/views/default.rb +0 -37
- data/lib/hanami/views/default_template_finder.rb +0 -22
- data/lib/hanami/views/null_view.rb +0 -15
- data/lib/hanami/welcome.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2188bc3aee5a164b6610c6bc97fad9f0bba0384bf11a80be27228e7f19dad4e0
|
4
|
+
data.tar.gz: 7fa39987132cf6bfda0b0986a36894d08297c1df06b31354cfbeae934d73a813
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7b1aad0186fcdaa94593ba4ff5d01cf4f8d4431aaffba173c3c795c2c0c76993a27da3aa503b0ce59fd67467615c86c50a4ab227986e38dd0986e91c30766a5
|
7
|
+
data.tar.gz: cd2d8b82bc7f98e906686fdab7299282b1c1be4b29278c9ee5b0f9b3cefbb7d31fa83013a840b2b9fa2b8e2b2f3f8c0582ca3587b35ced91f65db6f853d67cf7
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,204 @@
|
|
1
1
|
# Hanami
|
2
2
|
The web, with simplicity.
|
3
3
|
|
4
|
-
##
|
5
|
-
###
|
6
|
-
- [
|
7
|
-
|
4
|
+
## v2.0.0.alpha4 - 2021-12-07
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Manage Content Security Policy (CSP) with "zero-defaults" policy. New API to change CSP values and to disable the feature.
|
7
|
+
```ruby
|
8
|
+
# Read a CSP value
|
9
|
+
|
10
|
+
module MyApp
|
11
|
+
class Application < Hanami::Application
|
12
|
+
config.actions.content_security_policy[:base_uri] # => "'self'"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
# Override a default CSP value
|
19
|
+
|
20
|
+
module MyApp
|
21
|
+
class Application < Hanami::Application
|
22
|
+
# This line will generate the following CSP fragment
|
23
|
+
# plugin-types ;
|
24
|
+
config.actions.content_security_policy[:plugin_types] = nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# Append to a default CSP value
|
31
|
+
|
32
|
+
module MyApp
|
33
|
+
class Application < Hanami::Application
|
34
|
+
# This line will generate the following CSP fragment
|
35
|
+
# script-src 'self' https://my.cdn.test;
|
36
|
+
config.actions.content_security_policy[:script_src] += " https://my.cdn.test"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
# Add a custom CSP key. Useful when CSP standard evolves.
|
43
|
+
|
44
|
+
module MyApp
|
45
|
+
class Application < Hanami::Application
|
46
|
+
# This line will generate the following CSP fragment
|
47
|
+
# my-custom-setting 'self';
|
48
|
+
config.actions.content_security_policy[:my-custom-setting] = "'self'"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
# Delete a CSP key.
|
55
|
+
|
56
|
+
module MyApp
|
57
|
+
class Application < Hanami::Application
|
58
|
+
config.actions.content_security_policy.delete(:object_src)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
# Disable CSP feature.
|
65
|
+
|
66
|
+
module MyApp
|
67
|
+
class Application < Hanami::Application
|
68
|
+
config.actions.content_security_policy = false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
## v2.0.0.alpha3 - 2021-11-09
|
74
|
+
### Added
|
75
|
+
- [Luca Guidi] Added `Hanami.shutdown` to stop all bootable components in the application container
|
76
|
+
- [Tim Riley] Added `component_dir_paths` application setting to allow for components to be loaded from additional directories inside each slice directory. To begin with, this defaults to `%w[actions repositories views]`. Components inside these directories are expected to be namespaced to match the directory name; e.g. given a `main` slice, `slices/main/actions/home.rb` is expected to define `Main::Actions::Home`, and will be registered in the slice container as `"actions.home"`.
|
77
|
+
|
78
|
+
### Changed
|
79
|
+
- [Tim Riley] A slice's classes can now be defined directly inside `slices/[slice_name]/lib/`; e.g. given a `main` slice, `slices/main/lib/example.rb` is expected to define `Main::Example`, and will be registered in the slice container as `"example"`
|
80
|
+
- [Tim Riley] The root `lib/` directory is no longer configured as a component dir, and classes inside `lib/[app_namespace]/` will no longer be auto-registered into the container. If you need to share components, create them in their own slices as appropriate, and import those slices into the other slices that require them.
|
81
|
+
- [Tim Riley] `lib/[app_namespace]/` is configured for autoloading, and `lib/` is added to `$LOAD_PATH` to support explicit requires for source files outside `lib/[app_namespace]/`.
|
82
|
+
- [Tim Riley] (Internal) Ported `Hanami::Configuration` and related classes to use dry-configurable
|
83
|
+
- [Tim Riley] Application inflector can be entirely replaced, if required, via `Hanami::Configuration#inflector=`. Custom inflection rules can still be provided to the default inflector via `Hanami::Configuration#inflections`.
|
84
|
+
- [Marc Busqué] App settings are defined within a concrete class rather than an anonymous block, to allow for users to leverage the typical behavior of Ruby classes, such as for defining their own types module to use for coercing setting values. This class also relies on dry-configurable for its settings implementation, so the standard dry-configurable `setting` API is available, such as the `constructor:` and `default:` options.
|
85
|
+
```ruby
|
86
|
+
# frozen_string_literal: true
|
87
|
+
|
88
|
+
require "dry/types"
|
89
|
+
require "hanami/application/settings"
|
90
|
+
|
91
|
+
module TestApp
|
92
|
+
class Settings < Hanami::Application::Settings
|
93
|
+
# Example usage of a types module (previously not possible inside the anonymous block)
|
94
|
+
Types = Dry.Types()
|
95
|
+
|
96
|
+
setting :session_secret, constructor: Types::String.constrained(min_size: 20)
|
97
|
+
|
98
|
+
setting :some_bool, constructor: Types::Params::Bool, default: false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
```
|
102
|
+
- [Marc Busqué] Application `settings_loader` and `settings_loader_options` have been replaced with `settings_store`, which is an updated abstraction for providing setting values to work with the new `Hanami::Application::Settings` implementation noted above (see `Application::Settings::DotenvStore` for the default store, which provides the same behavior as previously)
|
103
|
+
- [Marc Busqué] Routes are defined within a concrete class rather than an anonymous block, to provide consistency with the settings (noted above), as well a place for additional behavior (in future releases):
|
104
|
+
```ruby
|
105
|
+
# frozen_string_literal: true
|
106
|
+
|
107
|
+
require "hanami/application/routes"
|
108
|
+
|
109
|
+
module MyApp
|
110
|
+
class Routes < Hanami::Application::Routes
|
111
|
+
define do
|
112
|
+
slice :main, at: "/" do
|
113
|
+
root to: "home.show"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
## v2.0.0.alpha2 - 2021-05-04
|
121
|
+
### Added
|
122
|
+
- [Luca Guidi] Official support for Ruby: MRI 3.0
|
123
|
+
- [Tim Riley] Code autoloading via Zeitwerk
|
124
|
+
- [Tim Riley] `Hanami::Application` subclasses generate and configure a `Dry::System::Container`, accessible via `.container` and `AppNamespace::Container`, with several common container methods available directly via the application subclass (e.g. `Bookshelf::Application["foo"]` or `Hanami.application["foo"]`)
|
125
|
+
- [Tim Riley] Introduced `Hanami::Application.register_bootable` to register custom components
|
126
|
+
- [Tim Riley] Introduced `Hanami::Application.keys` to get the list of resolved components
|
127
|
+
- [Tim Riley] Dynamically create an auto-injection mixin (e.g. `Bookshelf::Deps`)
|
128
|
+
```ruby
|
129
|
+
# frozen_string_literal: true
|
130
|
+
|
131
|
+
module Bookshelf
|
132
|
+
class CreateThing
|
133
|
+
include Deps[service_client: "some_service.client"]
|
134
|
+
|
135
|
+
def call(attrs)
|
136
|
+
# Validate attrs, etc.
|
137
|
+
service_client.create(attrs)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
```
|
142
|
+
- [Tim Riley] Introduced application settings. They are accessible via `Hanami.application.settings` in `config/settings.rb`
|
143
|
+
- [Tim Riley] Introduced application slices to organise high-level application concerns. Slices are generated based on subdirectories of `slices/`, and map onto corresponding ruby module namespaces, e.g. `slices/main` -> `Main`, with the slice instance itself being `Main::Slice` (as well as being accessible via `Hanami.application.slices[:main]`)
|
144
|
+
- [Tim Riley] Each slice generates and configures has its own `Dry::System::Container`, accessible via the slice instance (e.g. `Main::Slice.container`) as well as via its own constant (e.g. `Main::Container`)
|
145
|
+
- [Tim Riley] Slice containers automatically import the application container, under the `"application"` namespace
|
146
|
+
- [Tim Riley] Allow slice containers to be imported by other slice containers
|
147
|
+
|
148
|
+
### Changed
|
149
|
+
- [Luca Guidi] Drop support for Ruby: MRI 2.5
|
150
|
+
- [Tim Riley] Removed `config.cookies` in favor of `config.actions.cookies`
|
151
|
+
- [Tim Riley] Removed `config.sessions` in favor of `config.actions.sessions`
|
152
|
+
- [Tim Riley] Removed `config.security` settings
|
153
|
+
|
154
|
+
## v2.0.0.alpha1 - 2019-01-30
|
155
|
+
### Added
|
156
|
+
- [Luca Guidi] Implemented from scratch `hanami version`
|
157
|
+
- [Luca Guidi] Implemented from scratch `hanami server`
|
158
|
+
- [Luca Guidi] Main configuration is opinionated: when a setting is not specified in generated code, it uses a framework default.
|
159
|
+
- [Luca Guidi] Main configuration setting `environment`: to yield env based settings (e.g. `config.environment(:production) { |c| c.logger = {...} }`)
|
160
|
+
- [Luca Guidi] Main configuration setting `base_url`: to set the base URL of the app (e.g. `config.base_url = "https://example.com"`)
|
161
|
+
- [Luca Guidi] Main configuration setting `logger`: to set the logger options (e.g. `config.logger = { level: :info, format: :json }`)
|
162
|
+
- [Luca Guidi] Main configuration setting `routes`: to set the path to routes file (e.g. `config.routes = "path/to/routes"`)
|
163
|
+
- [Luca Guidi] Main configuration setting `cookies`: to set cookies options (e.g. `config.cookies = { max_age: 300 }`)
|
164
|
+
- [Luca Guidi] Main configuration setting `sessions`: to set session options (e.g. `config.sessions = :cookie, { secret: "abc" }`)
|
165
|
+
- [Luca Guidi] Main configuration setting `default_request_format`: to set the fallback for request format (aka MIME Type) (e.g. `config.default_request_format = :json`)
|
166
|
+
- [Luca Guidi] Main configuration setting `default_response_format`: to set the default response format (aka MIME Type) (e.g. `config.default_response_format = :json`)
|
167
|
+
- [Luca Guidi] Main configuration setting `middleware` to mount Rack middleware (e.g. `config.middleware.use MyMiddleware, "argument"`)
|
168
|
+
- [Luca Guidi] Main configuration setting `security` to set security settings (see below)
|
169
|
+
- [Luca Guidi] Main configuration setting `inflections` to configure inflections (e.g. `config.inflections { |i| i.plural "virus", "viruses" }`)
|
170
|
+
- [Luca Guidi] Main configuration security setting `x_frame_options`: defaults to `"deny"` (e.g. `config.security.x_frame_options = "sameorigin"`)
|
171
|
+
- [Luca Guidi] Main configuration security setting `x_content_type_options`: defaults to `"nosniff"` (e.g. `config.security.x_content_type_options = nil`)
|
172
|
+
- [Luca Guidi] Main configuration security setting `x_xss_protection`: defaults to `"1; mode=block"` (e.g. `config.security.x_xss_protection = "1"`)
|
173
|
+
- [Luca Guidi] Main configuration security setting `content_security_policy`: defaults to `"form-action 'self'; frame-ancestors 'self'; base-uri 'self'; default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self' https: data:; style-src 'self' 'unsafe-inline' https:; font-src 'self'; object-src 'none'; plugin-types application/pdf; child-src 'self'; frame-src 'self'; media-src 'self'"`
|
174
|
+
(e.g. `config.security.content_security_policy[:style_src] += " https://my.cdn.example"` to add another source)
|
175
|
+
(e.g. `config.security.content_security_policy[:plugin_types] = nil` to override the settings)
|
8
176
|
|
9
177
|
### Changed
|
10
|
-
- [Luca Guidi]
|
178
|
+
- [Luca Guidi] Drop support for Ruby: MRI 2.3, and 2.4.
|
179
|
+
- [Luca Guidi] `Hanami::Application` must be used as superclass for main application under `config/application.rb` (e.g. `Bookshelf::Application`)
|
180
|
+
- [Luca Guidi] Main configuration is available at `config/application.rb` instead of `config/enviroment.rb`
|
181
|
+
- [Luca Guidi] Removed `Hanami.configure` in favor of main application configuration (e.g. `Bookshelf::Application.config`)
|
182
|
+
- [Luca Guidi] Removed DSL syntax for main configuration (from `cookies max_age: 600` to `config.cookies = { max_age: 600 }`)
|
183
|
+
- [Luca Guidi] Per enviroment settings must be wrapped in a block (e.g. `config.enviroment(:production) { |c| c.logger = {} }`)
|
184
|
+
- [Luca Guidi] Concrete applications are no longer supported (e.g. `Web::Application` in `apps/web/application.rb`)
|
185
|
+
- [Luca Guidi] Main routes must be configured at `config/routes.rb`:
|
186
|
+
```ruby
|
187
|
+
# frozen_string_literal: true
|
188
|
+
|
189
|
+
Hanami.application.routes do
|
190
|
+
mount :web, at: "/" do
|
191
|
+
root to: "home#index"
|
192
|
+
end
|
193
|
+
|
194
|
+
mount :admin, at: "/admin" do
|
195
|
+
root to: "home#index"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
```
|
199
|
+
- [Luca Guidi] Per application routes are no longer supported (e.g. `apps/web/config/routes.rb`)
|
200
|
+
- [Luca Guidi] Removed `shotgun` and code reloading from the core. Code reloading is implemented by `hanami-reloader` gem.
|
201
|
+
- [Luca Guidi] Removed support for `.hanamirc`
|
11
202
|
|
12
203
|
## v1.3.4 - 2021-05-02
|
13
204
|
### Fixed
|
data/FEATURES.md
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ The web, with simplicity.
|
|
4
4
|
|
5
5
|
## Version
|
6
6
|
|
7
|
-
**This branch contains the code for `hanami`
|
7
|
+
**This branch contains the code for `hanami` 2.0.x.**
|
8
8
|
|
9
9
|
## Frameworks
|
10
10
|
|
@@ -29,14 +29,14 @@ These components are designed to be used independently or together in a Hanami a
|
|
29
29
|
## Status
|
30
30
|
|
31
31
|
[![Gem Version](https://badge.fury.io/rb/hanami.svg)](https://badge.fury.io/rb/hanami)
|
32
|
-
[![CI](https://github.com/hanami/hanami/workflows/ci/badge.svg?branch=
|
33
|
-
[![Test Coverage](https://codecov.io/gh/hanami/hanami/branch/
|
32
|
+
[![CI](https://github.com/hanami/hanami/workflows/ci/badge.svg?branch=main)](https://github.com/hanami/hanami/actions?query=workflow%3Aci+branch%3Amain)
|
33
|
+
[![Test Coverage](https://codecov.io/gh/hanami/hanami/branch/main/graph/badge.svg)](https://codecov.io/gh/hanami/hanami)
|
34
34
|
[![Depfu](https://badges.depfu.com/badges/ba000e0f69e6ef1c44cd3038caaa1841/overview.svg)](https://depfu.com/github/hanami/hanami?project=Bundler)
|
35
35
|
[![Inline Docs](http://inch-ci.org/github/hanami/hanami.svg)](http://inch-ci.org/github/hanami/hanami)
|
36
36
|
|
37
37
|
## Installation
|
38
38
|
|
39
|
-
__Hanami__ supports Ruby (MRI) 2.
|
39
|
+
__Hanami__ supports Ruby (MRI) 2.6+
|
40
40
|
|
41
41
|
```shell
|
42
42
|
gem install hanami
|
data/hanami.gemspec
CHANGED
@@ -1,40 +1,37 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
5
|
+
require "hanami/version"
|
5
6
|
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
8
|
+
spec.name = "hanami"
|
8
9
|
spec.version = Hanami::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
10
|
+
spec.authors = ["Luca Guidi"]
|
11
|
+
spec.email = ["me@lucaguidi.com"]
|
12
|
+
spec.summary = "The web, with simplicity"
|
13
|
+
spec.description = "Hanami is a web framework for Ruby"
|
14
|
+
spec.homepage = "http://hanamirb.org"
|
15
|
+
spec.license = "MIT"
|
15
16
|
|
16
17
|
spec.files = `git ls-files -c -o --exclude-standard -z -- lib/* bin/* LICENSE.md README.md CODE_OF_CONDUCT.md CHANGELOG.md FEATURES.md hanami.gemspec`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test)/})
|
19
|
-
spec.require_paths = [
|
20
|
-
spec.required_ruby_version =
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.required_ruby_version = ">= 2.6.0"
|
21
21
|
|
22
|
-
spec.metadata[
|
22
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
23
23
|
|
24
|
-
spec.add_dependency
|
25
|
-
spec.add_dependency
|
26
|
-
spec.add_dependency
|
27
|
-
spec.add_dependency
|
28
|
-
spec.add_dependency
|
29
|
-
spec.add_dependency
|
30
|
-
spec.add_dependency
|
31
|
-
spec.add_dependency
|
32
|
-
spec.add_dependency
|
33
|
-
spec.add_dependency 'concurrent-ruby', '~> 1.0'
|
34
|
-
spec.add_dependency 'bundler', '>= 1.6', '< 3'
|
24
|
+
spec.add_dependency "bundler", ">= 1.16", "< 3"
|
25
|
+
spec.add_dependency "dry-configurable", "~> 0.12", ">= 0.12.1"
|
26
|
+
spec.add_dependency "dry-core", "~> 0.4"
|
27
|
+
spec.add_dependency "dry-inflector", "~> 0.2", ">= 0.2.1"
|
28
|
+
spec.add_dependency "dry-monitor"
|
29
|
+
spec.add_dependency "dry-system", "~> 0.19", ">= 0.21.0"
|
30
|
+
spec.add_dependency "hanami-cli", "~> 2.0.alpha"
|
31
|
+
spec.add_dependency "hanami-utils", "~> 2.0.alpha"
|
32
|
+
spec.add_dependency "zeitwerk", "~> 2.4"
|
35
33
|
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency 'rake', '~> 13.0'
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
35
|
+
spec.add_development_dependency "rack-test", "~> 1.1"
|
36
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
40
37
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Hanami
|
2
|
+
class Application
|
3
|
+
module Autoloader
|
4
|
+
# Allows the Hanami standard inflector (from dry-inflector) to be used with Zeitwerk
|
5
|
+
class InflectorAdapter
|
6
|
+
def initialize(inflector)
|
7
|
+
@inflector = inflector
|
8
|
+
end
|
9
|
+
|
10
|
+
def camelize(basename, _abspath)
|
11
|
+
# Discard unused `_abspath` argument before calling our own inflector's
|
12
|
+
# `#camelize` (which takes only one argument)
|
13
|
+
inflector.camelize(basename)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :inflector
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Hanami.application.register_bootable :rack_logger do |container|
|
4
|
+
start do
|
5
|
+
require "hanami/web/rack_logger"
|
6
|
+
|
7
|
+
use :logger
|
8
|
+
use :rack_monitor
|
9
|
+
|
10
|
+
rack_logger = Hanami::Web::RackLogger.new(
|
11
|
+
container[:logger],
|
12
|
+
filter_params: Hanami.application.configuration.logger.filter_params
|
13
|
+
)
|
14
|
+
|
15
|
+
rack_logger.attach container[:rack_monitor]
|
16
|
+
|
17
|
+
register :rack_logger, rack_logger
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Hanami.application.register_bootable :rack_monitor do |container|
|
4
|
+
start do
|
5
|
+
require "dry/monitor"
|
6
|
+
require "dry/monitor/rack/middleware"
|
7
|
+
|
8
|
+
middleware = Dry::Monitor::Rack::Middleware.new(container[:notifications])
|
9
|
+
|
10
|
+
register :rack_monitor, middleware
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hanami/router"
|
4
|
+
require "hanami/application/routing/middleware/stack"
|
5
|
+
|
6
|
+
module Hanami
|
7
|
+
class Application
|
8
|
+
# Hanami application router
|
9
|
+
# @since 2.0.0
|
10
|
+
class Router < ::Hanami::Router
|
11
|
+
# @since 2.0.0
|
12
|
+
# @api private
|
13
|
+
def initialize(routes:, stack: Routing::Middleware::Stack.new, **kwargs, &blk)
|
14
|
+
@stack = stack
|
15
|
+
instance_eval(&blk)
|
16
|
+
super(**kwargs, &routes)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @since 2.0.0
|
20
|
+
# @api private
|
21
|
+
def freeze
|
22
|
+
return self if frozen?
|
23
|
+
|
24
|
+
remove_instance_variable(:@stack)
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
# @since 2.0.0
|
29
|
+
# @api private
|
30
|
+
def use(middleware, *args, &blk)
|
31
|
+
@stack.use(middleware, *args, &blk)
|
32
|
+
end
|
33
|
+
|
34
|
+
# @since 2.0.0
|
35
|
+
# @api private
|
36
|
+
def scope(*args, &blk)
|
37
|
+
@stack.with(args.first) do
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# @since 2.0.0
|
43
|
+
def slice(name, at:, &blk)
|
44
|
+
path = prefixed_path(at)
|
45
|
+
@resolver.register_slice_at_path(name, path)
|
46
|
+
|
47
|
+
scope(path, &blk)
|
48
|
+
end
|
49
|
+
|
50
|
+
# @since 2.0.0
|
51
|
+
# @api private
|
52
|
+
def to_rack_app
|
53
|
+
return self if @stack.empty?
|
54
|
+
|
55
|
+
@stack.to_rack_app(self)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hanami
|
4
|
+
class Application
|
5
|
+
# Application routes
|
6
|
+
#
|
7
|
+
# Users are expected to inherit from this class to define their application
|
8
|
+
# routes.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # config/routes.rb
|
12
|
+
# # frozen_string_literal: true
|
13
|
+
#
|
14
|
+
# require "hanami/application/routes"
|
15
|
+
#
|
16
|
+
# module MyApp
|
17
|
+
# class Routes < Hanami::Application::Routes
|
18
|
+
# define do
|
19
|
+
# slice :main, at: "/" do
|
20
|
+
# root to: "home.show"
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# See {Hanami::Application::Router} for the syntax allowed within the
|
27
|
+
# `define` block.
|
28
|
+
#
|
29
|
+
# @see Hanami::Application::Router
|
30
|
+
# @since 2.0.0
|
31
|
+
class Routes
|
32
|
+
# Defines application routes
|
33
|
+
#
|
34
|
+
# @yield DSL syntax to define application routes executed in the context
|
35
|
+
# of {Hanami::Application::Router}
|
36
|
+
#
|
37
|
+
# @return [Proc]
|
38
|
+
def self.define(&block)
|
39
|
+
@_routes = block
|
40
|
+
end
|
41
|
+
|
42
|
+
# @api private
|
43
|
+
def self.routes
|
44
|
+
@_routes || raise(<<~MSG)
|
45
|
+
Routes need to be defined before being able to fetch them. E.g.,
|
46
|
+
define do
|
47
|
+
slice :main, at: "/" do
|
48
|
+
root to: "home.show"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
MSG
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hanami
|
4
|
+
class Application
|
5
|
+
# Hanami application routes helpers
|
6
|
+
#
|
7
|
+
# An instance of this class gets registered in the container
|
8
|
+
# (`routes_helper` key) once the Hanami application is booted. You can use
|
9
|
+
# it to get the route helpers for your application.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# MyApp::Application["routes_helper"].path(:root) # => "/"
|
13
|
+
#
|
14
|
+
# @see Hanami::Router::UrlHelpers
|
15
|
+
# @since 2.0.0
|
16
|
+
class RoutesHelper
|
17
|
+
# @since 2.0.0
|
18
|
+
# @api private
|
19
|
+
def initialize(router)
|
20
|
+
@router = router
|
21
|
+
end
|
22
|
+
|
23
|
+
# @see Hanami::Router::UrlHelpers#path
|
24
|
+
def path(*args, **kwargs, &block)
|
25
|
+
@router.path(*args, **kwargs, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @see Hanami::Router::UrlHelpers#url
|
29
|
+
def url(*args, **kwargs, &block)
|
30
|
+
@router.url(*args, **kwargs, &block)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rack/builder"
|
4
|
+
|
5
|
+
module Hanami
|
6
|
+
class Application
|
7
|
+
module Routing
|
8
|
+
# Hanami::Applicatione::Router middleware stack
|
9
|
+
#
|
10
|
+
# @since 2.0.0
|
11
|
+
# @api private
|
12
|
+
module Middleware
|
13
|
+
# Middleware stack
|
14
|
+
#
|
15
|
+
# @since 2.0.0
|
16
|
+
# @api private
|
17
|
+
class Stack
|
18
|
+
# @since 2.0.0
|
19
|
+
# @api private
|
20
|
+
ROOT_PREFIX = "/"
|
21
|
+
private_constant :ROOT_PREFIX
|
22
|
+
|
23
|
+
# @since 2.0.0
|
24
|
+
# @api private
|
25
|
+
def initialize
|
26
|
+
@prefix = ROOT_PREFIX
|
27
|
+
@stack = Hash.new { |hash, key| hash[key] = [] }
|
28
|
+
end
|
29
|
+
|
30
|
+
# @since 2.0.0
|
31
|
+
# @api private
|
32
|
+
def use(middleware, *args, &blk)
|
33
|
+
@stack[@prefix].push([middleware, args, blk])
|
34
|
+
end
|
35
|
+
|
36
|
+
# @since 2.0.0
|
37
|
+
# @api private
|
38
|
+
def with(path)
|
39
|
+
prefix = @prefix
|
40
|
+
@prefix = path
|
41
|
+
yield
|
42
|
+
ensure
|
43
|
+
@prefix = prefix
|
44
|
+
end
|
45
|
+
|
46
|
+
# @since 2.0.0
|
47
|
+
# @api private
|
48
|
+
def to_rack_app(app) # rubocop:disable Metrics/MethodLength
|
49
|
+
s = self
|
50
|
+
|
51
|
+
Rack::Builder.new do
|
52
|
+
s.each do |prefix, stack|
|
53
|
+
s.mapped(self, prefix) do
|
54
|
+
stack.each do |middleware, args, blk|
|
55
|
+
use(middleware, *args, &blk)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
run app
|
60
|
+
end
|
61
|
+
end.to_app
|
62
|
+
end
|
63
|
+
|
64
|
+
# @since 2.0.0
|
65
|
+
# @api private
|
66
|
+
def empty?
|
67
|
+
@stack.empty?
|
68
|
+
end
|
69
|
+
|
70
|
+
# @since 2.0.0
|
71
|
+
# @api private
|
72
|
+
def each(&blk)
|
73
|
+
@stack.each(&blk)
|
74
|
+
end
|
75
|
+
|
76
|
+
# @since 2.0.0
|
77
|
+
# @api private
|
78
|
+
def mapped(builder, prefix, &blk)
|
79
|
+
if prefix == ROOT_PREFIX
|
80
|
+
builder.instance_eval(&blk)
|
81
|
+
else
|
82
|
+
builder.map(prefix, &blk)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|