piko-lite-box 0.0.1
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 +7 -0
- data/hanami-3.0.1/CHANGELOG.md +1701 -0
- data/hanami-3.0.1/LICENSE +20 -0
- data/hanami-3.0.1/README.md +89 -0
- data/hanami-3.0.1/hanami.gemspec +49 -0
- data/hanami-3.0.1/lib/hanami/app.rb +197 -0
- data/hanami-3.0.1/lib/hanami/boot.rb +5 -0
- data/hanami-3.0.1/lib/hanami/config/actions/content_security_policy.rb +140 -0
- data/hanami-3.0.1/lib/hanami/config/actions/cookies.rb +57 -0
- data/hanami-3.0.1/lib/hanami/config/actions/sessions.rb +83 -0
- data/hanami-3.0.1/lib/hanami/config/actions.rb +189 -0
- data/hanami-3.0.1/lib/hanami/config/assets.rb +84 -0
- data/hanami-3.0.1/lib/hanami/config/console.rb +79 -0
- data/hanami-3.0.1/lib/hanami/config/db.rb +35 -0
- data/hanami-3.0.1/lib/hanami/config/i18n.rb +138 -0
- data/hanami-3.0.1/lib/hanami/config/logger.rb +207 -0
- data/hanami-3.0.1/lib/hanami/config/null_config.rb +17 -0
- data/hanami-3.0.1/lib/hanami/config/router.rb +48 -0
- data/hanami-3.0.1/lib/hanami/config/views.rb +103 -0
- data/hanami-3.0.1/lib/hanami/config.rb +564 -0
- data/hanami-3.0.1/lib/hanami/constants.rb +62 -0
- data/hanami-3.0.1/lib/hanami/env.rb +52 -0
- data/hanami-3.0.1/lib/hanami/errors.rb +41 -0
- data/hanami-3.0.1/lib/hanami/extensions/action/i18n_helper.rb +64 -0
- data/hanami-3.0.1/lib/hanami/extensions/action/name_inferrer.rb +34 -0
- data/hanami-3.0.1/lib/hanami/extensions/action/slice_configured_action.rb +190 -0
- data/hanami-3.0.1/lib/hanami/extensions/action.rb +147 -0
- data/hanami-3.0.1/lib/hanami/extensions/db/repo.rb +108 -0
- data/hanami-3.0.1/lib/hanami/extensions/mailer/slice_configured_mailer.rb +134 -0
- data/hanami-3.0.1/lib/hanami/extensions/mailer.rb +28 -0
- data/hanami-3.0.1/lib/hanami/extensions/operation/slice_configured_db_operation.rb +90 -0
- data/hanami-3.0.1/lib/hanami/extensions/operation.rb +33 -0
- data/hanami-3.0.1/lib/hanami/extensions/router/errors.rb +58 -0
- data/hanami-3.0.1/lib/hanami/extensions/view/context.rb +298 -0
- data/hanami-3.0.1/lib/hanami/extensions/view/part.rb +92 -0
- data/hanami-3.0.1/lib/hanami/extensions/view/scope.rb +36 -0
- data/hanami-3.0.1/lib/hanami/extensions/view/slice_configured_context.rb +73 -0
- data/hanami-3.0.1/lib/hanami/extensions/view/slice_configured_helpers.rb +55 -0
- data/hanami-3.0.1/lib/hanami/extensions/view/slice_configured_part.rb +73 -0
- data/hanami-3.0.1/lib/hanami/extensions/view/slice_configured_view.rb +243 -0
- data/hanami-3.0.1/lib/hanami/extensions/view/standard_helpers.rb +26 -0
- data/hanami-3.0.1/lib/hanami/extensions/view.rb +38 -0
- data/hanami-3.0.1/lib/hanami/extensions.rb +30 -0
- data/hanami-3.0.1/lib/hanami/helpers/assets_helper.rb +804 -0
- data/hanami-3.0.1/lib/hanami/helpers/form_helper/form_builder.rb +1389 -0
- data/hanami-3.0.1/lib/hanami/helpers/form_helper/values.rb +75 -0
- data/hanami-3.0.1/lib/hanami/helpers/form_helper.rb +213 -0
- data/hanami-3.0.1/lib/hanami/helpers/i18n_helper.rb +241 -0
- data/hanami-3.0.1/lib/hanami/logger/rack_formatter.rb +73 -0
- data/hanami-3.0.1/lib/hanami/logger/sql_formatter.rb +80 -0
- data/hanami-3.0.1/lib/hanami/logger/sql_logger.rb +48 -0
- data/hanami-3.0.1/lib/hanami/middleware/assets.rb +21 -0
- data/hanami-3.0.1/lib/hanami/middleware/content_security_policy_nonce.rb +53 -0
- data/hanami-3.0.1/lib/hanami/middleware/public_errors_app.rb +75 -0
- data/hanami-3.0.1/lib/hanami/middleware/render_errors.rb +90 -0
- data/hanami-3.0.1/lib/hanami/port.rb +45 -0
- data/hanami-3.0.1/lib/hanami/prepare.rb +5 -0
- data/hanami-3.0.1/lib/hanami/provider/source.rb +16 -0
- data/hanami-3.0.1/lib/hanami/provider_registrar.rb +28 -0
- data/hanami-3.0.1/lib/hanami/providers/assets.rb +28 -0
- data/hanami-3.0.1/lib/hanami/providers/db/adapter.rb +75 -0
- data/hanami-3.0.1/lib/hanami/providers/db/adapters.rb +66 -0
- data/hanami-3.0.1/lib/hanami/providers/db/config.rb +44 -0
- data/hanami-3.0.1/lib/hanami/providers/db/gateway.rb +87 -0
- data/hanami-3.0.1/lib/hanami/providers/db/sql_adapter.rb +100 -0
- data/hanami-3.0.1/lib/hanami/providers/db.rb +325 -0
- data/hanami-3.0.1/lib/hanami/providers/db_logging.rb +19 -0
- data/hanami-3.0.1/lib/hanami/providers/i18n/backend.rb +373 -0
- data/hanami-3.0.1/lib/hanami/providers/i18n/locale/en.yml +57 -0
- data/hanami-3.0.1/lib/hanami/providers/i18n.rb +114 -0
- data/hanami-3.0.1/lib/hanami/providers/inflector.rb +17 -0
- data/hanami-3.0.1/lib/hanami/providers/logger.rb +41 -0
- data/hanami-3.0.1/lib/hanami/providers/mailers.rb +101 -0
- data/hanami-3.0.1/lib/hanami/providers/rack.rb +47 -0
- data/hanami-3.0.1/lib/hanami/providers/relations.rb +31 -0
- data/hanami-3.0.1/lib/hanami/providers/routes.rb +29 -0
- data/hanami-3.0.1/lib/hanami/rake_tasks.rb +54 -0
- data/hanami-3.0.1/lib/hanami/routes.rb +146 -0
- data/hanami-3.0.1/lib/hanami/settings/composite_store.rb +53 -0
- data/hanami-3.0.1/lib/hanami/settings/env_store.rb +32 -0
- data/hanami-3.0.1/lib/hanami/settings.rb +234 -0
- data/hanami-3.0.1/lib/hanami/setup.rb +6 -0
- data/hanami-3.0.1/lib/hanami/slice/router.rb +280 -0
- data/hanami-3.0.1/lib/hanami/slice/routes_helper.rb +37 -0
- data/hanami-3.0.1/lib/hanami/slice/routing/middleware/stack.rb +216 -0
- data/hanami-3.0.1/lib/hanami/slice/routing/resolver.rb +88 -0
- data/hanami-3.0.1/lib/hanami/slice/view_name_inferrer.rb +63 -0
- data/hanami-3.0.1/lib/hanami/slice.rb +1239 -0
- data/hanami-3.0.1/lib/hanami/slice_configurable.rb +72 -0
- data/hanami-3.0.1/lib/hanami/slice_name.rb +111 -0
- data/hanami-3.0.1/lib/hanami/slice_registrar.rb +215 -0
- data/hanami-3.0.1/lib/hanami/universal_logger.rb +250 -0
- data/hanami-3.0.1/lib/hanami/version.rb +45 -0
- data/hanami-3.0.1/lib/hanami/web/rack_logger.rb +126 -0
- data/hanami-3.0.1/lib/hanami/web/welcome.html.erb +584 -0
- data/hanami-3.0.1/lib/hanami/web/welcome.rb +46 -0
- data/hanami-3.0.1/lib/hanami.rb +276 -0
- data/piko-lite-box.gemspec +11 -0
- metadata +137 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry/configurable"
|
|
4
|
+
require "hanami/action"
|
|
5
|
+
|
|
6
|
+
module Hanami
|
|
7
|
+
class Config
|
|
8
|
+
# Hanami actions config
|
|
9
|
+
#
|
|
10
|
+
# This exposes all the settings from the standalone `Hanami::Action` 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.0.0
|
|
15
|
+
# @api public
|
|
16
|
+
class Actions
|
|
17
|
+
include Dry::Configurable
|
|
18
|
+
|
|
19
|
+
# @!attribute [rw] cookies
|
|
20
|
+
# Sets or returns a hash of cookie options for actions.
|
|
21
|
+
#
|
|
22
|
+
# The hash is wrapped by {Hanami::Config::Actions::Cookies}, which also provides an
|
|
23
|
+
# `enabled?` method, returning true in the case of any options provided.
|
|
24
|
+
#
|
|
25
|
+
# @example
|
|
26
|
+
# config.actions.cookies = {max_age: 300}
|
|
27
|
+
#
|
|
28
|
+
# @return [Hanami::Config::Actions::Cookies]
|
|
29
|
+
#
|
|
30
|
+
# @api public
|
|
31
|
+
# @since 2.0.0
|
|
32
|
+
setting :cookies, default: {}, constructor: -> options { Cookies.new(options) }
|
|
33
|
+
|
|
34
|
+
# @!attribute [rw] sessions
|
|
35
|
+
# Sets or returns the session store (and its options) for actions.
|
|
36
|
+
#
|
|
37
|
+
# The given values are taken as an argument list to be passed to {Config::Sessions#initialize}.
|
|
38
|
+
#
|
|
39
|
+
# The configured session store is used when setting up the app or slice
|
|
40
|
+
# {Slice::ClassMethods#router router}.
|
|
41
|
+
#
|
|
42
|
+
# @example
|
|
43
|
+
# config.actions.sessions = :cookie, {secret: "xyz"}
|
|
44
|
+
#
|
|
45
|
+
# @return [Config::Sessions]
|
|
46
|
+
#
|
|
47
|
+
# @see Config::Sessions
|
|
48
|
+
# @see Slice::ClassMethods#router
|
|
49
|
+
#
|
|
50
|
+
# @api public
|
|
51
|
+
# @since 2.0.0
|
|
52
|
+
setting :sessions, constructor: proc { |storage, *options| Sessions.new(storage, *options) }
|
|
53
|
+
|
|
54
|
+
# @!attribute [rw] csrf_protection
|
|
55
|
+
# Sets or returns whether CSRF protection should be enabled for action classes.
|
|
56
|
+
#
|
|
57
|
+
# Defaults to true if {#sessions} is enabled. You can override this by explicitly setting a
|
|
58
|
+
# true or false value.
|
|
59
|
+
#
|
|
60
|
+
# When true, this will include `Hanami::Action::CSRFProtection` in all action classes.
|
|
61
|
+
#
|
|
62
|
+
# @return [Boolean]
|
|
63
|
+
#
|
|
64
|
+
# @api public
|
|
65
|
+
# @since 2.0.0
|
|
66
|
+
setting :csrf_protection
|
|
67
|
+
|
|
68
|
+
# Returns the Content Security Policy config for actions.
|
|
69
|
+
#
|
|
70
|
+
# The resulting policy is set as a default `"Content-Security-Policy"` response header.
|
|
71
|
+
#
|
|
72
|
+
# @return [Hanami::Config::Actions::ContentSecurityPolicy]
|
|
73
|
+
#
|
|
74
|
+
# @api public
|
|
75
|
+
# @since 2.0.0
|
|
76
|
+
attr_accessor :content_security_policy
|
|
77
|
+
|
|
78
|
+
# Returns the proc to generate Content Security Policy nonce values.
|
|
79
|
+
#
|
|
80
|
+
# The current Rack request object is provided as an optional argument
|
|
81
|
+
# to the proc, enabling the generation of nonces based on session IDs.
|
|
82
|
+
#
|
|
83
|
+
# @example Independent random nonce (default)
|
|
84
|
+
# -> { SecureRandom.urlsafe_base64(16) }
|
|
85
|
+
#
|
|
86
|
+
# @example Session dependent nonce
|
|
87
|
+
# ->(request) { Digest::SHA256.base64digest(request.session[:uuid])[0, 16] }
|
|
88
|
+
#
|
|
89
|
+
# @return [Proc]
|
|
90
|
+
#
|
|
91
|
+
# @api public
|
|
92
|
+
# @since 2.3.0
|
|
93
|
+
setting :content_security_policy_nonce_generator, default: -> { SecureRandom.urlsafe_base64(16) }
|
|
94
|
+
|
|
95
|
+
# @!attribute [rw] method_override
|
|
96
|
+
# Sets or returns whether HTTP method override should be enabled for action classes.
|
|
97
|
+
#
|
|
98
|
+
# Defaults to true. You can override this by explicitly setting a
|
|
99
|
+
# true or false value.
|
|
100
|
+
#
|
|
101
|
+
# When true, this will mount `Rack::MethodOverride` in the Rack middleware stack of the App.
|
|
102
|
+
#
|
|
103
|
+
# @return [Boolean]
|
|
104
|
+
#
|
|
105
|
+
# @api public
|
|
106
|
+
# @since 2.1.0
|
|
107
|
+
setting :method_override, default: true
|
|
108
|
+
|
|
109
|
+
# @!attribute [rw] name_inference_base
|
|
110
|
+
# @api private
|
|
111
|
+
# @since 2.1.0
|
|
112
|
+
setting :name_inference_base, default: "actions"
|
|
113
|
+
|
|
114
|
+
# @!attribute [rw] view_name_inferrer
|
|
115
|
+
# @api private
|
|
116
|
+
# @since 2.1.0
|
|
117
|
+
setting :view_name_inferrer, default: Slice::ViewNameInferrer
|
|
118
|
+
|
|
119
|
+
# @!attribute [rw] view_name_inference_base
|
|
120
|
+
# @api private
|
|
121
|
+
# @since 2.1.0
|
|
122
|
+
setting :view_name_inference_base, default: "views"
|
|
123
|
+
|
|
124
|
+
# @api private
|
|
125
|
+
attr_reader :base_config
|
|
126
|
+
protected :base_config
|
|
127
|
+
|
|
128
|
+
# @api private
|
|
129
|
+
def initialize(*, **options)
|
|
130
|
+
super()
|
|
131
|
+
|
|
132
|
+
@base_config = Hanami::Action.config.dup
|
|
133
|
+
@content_security_policy = ContentSecurityPolicy.new
|
|
134
|
+
|
|
135
|
+
configure_defaults
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# @api private
|
|
139
|
+
def initialize_copy(source)
|
|
140
|
+
super
|
|
141
|
+
@base_config = source.base_config.dup
|
|
142
|
+
@content_security_policy = source.content_security_policy.dup
|
|
143
|
+
end
|
|
144
|
+
private :initialize_copy
|
|
145
|
+
|
|
146
|
+
# @api private
|
|
147
|
+
def finalize!(app_config)
|
|
148
|
+
@base_config.root_directory = app_config.root
|
|
149
|
+
|
|
150
|
+
# A nil value for `csrf_protection` means it has not been explicitly configured
|
|
151
|
+
# (neither true nor false), so we can default it to whether sessions are enabled
|
|
152
|
+
self.csrf_protection = sessions.enabled? if csrf_protection.nil?
|
|
153
|
+
|
|
154
|
+
if content_security_policy
|
|
155
|
+
default_headers["Content-Security-Policy"] = content_security_policy.to_s
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# @api public
|
|
160
|
+
# @since 2.3.0
|
|
161
|
+
def content_security_policy? = !!@content_security_policy
|
|
162
|
+
|
|
163
|
+
private
|
|
164
|
+
|
|
165
|
+
# Apply defaults for base config
|
|
166
|
+
def configure_defaults
|
|
167
|
+
self.default_headers = {
|
|
168
|
+
"X-Frame-Options" => "DENY",
|
|
169
|
+
"X-Content-Type-Options" => "nosniff",
|
|
170
|
+
"X-XSS-Protection" => "1; mode=block"
|
|
171
|
+
}
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def method_missing(name, *args, &block)
|
|
175
|
+
if config.respond_to?(name)
|
|
176
|
+
config.public_send(name, *args, &block)
|
|
177
|
+
elsif base_config.respond_to?(name)
|
|
178
|
+
base_config.public_send(name, *args, &block)
|
|
179
|
+
else
|
|
180
|
+
super
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def respond_to_missing?(name, _include_all = false)
|
|
185
|
+
config.respond_to?(name) || base_config.respond_to?(name) || super
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
@@ -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 assets 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, _include_all = false)
|
|
80
|
+
config.respond_to?(name) || base_config.respond_to?(name) || super
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry/configurable"
|
|
4
|
+
|
|
5
|
+
module Hanami
|
|
6
|
+
class Config
|
|
7
|
+
# Hanami console config
|
|
8
|
+
#
|
|
9
|
+
# @since 2.3.0
|
|
10
|
+
# @api public
|
|
11
|
+
class Console
|
|
12
|
+
include Dry::Configurable
|
|
13
|
+
|
|
14
|
+
# @!attribute [rw] engine
|
|
15
|
+
# Sets or returns the interactive console engine to be used by `hanami console`.
|
|
16
|
+
# Supported values are `:irb` (default) and `:pry`.
|
|
17
|
+
#
|
|
18
|
+
# @example
|
|
19
|
+
# config.console.engine = :pry
|
|
20
|
+
#
|
|
21
|
+
# @return [Symbol]
|
|
22
|
+
#
|
|
23
|
+
# @api public
|
|
24
|
+
# @since 2.3.0
|
|
25
|
+
setting :engine, default: :irb
|
|
26
|
+
|
|
27
|
+
# Returns the complete list of extensions to be used in the console
|
|
28
|
+
#
|
|
29
|
+
# @example
|
|
30
|
+
# config.console.include MyExtension, OtherExtension
|
|
31
|
+
# config.console.include ThirdExtension
|
|
32
|
+
#
|
|
33
|
+
# config.console.extensions
|
|
34
|
+
# # => [MyExtension, OtherExtension, ThirdExtension]
|
|
35
|
+
#
|
|
36
|
+
# @return [Array<Module>]
|
|
37
|
+
#
|
|
38
|
+
# @api public
|
|
39
|
+
# @since 2.3.0
|
|
40
|
+
def extensions = @extensions.dup.freeze
|
|
41
|
+
|
|
42
|
+
# Define a module extension to be included in the console
|
|
43
|
+
#
|
|
44
|
+
# @param mod [Module] one or more modules to be included in the console
|
|
45
|
+
# @return [void]
|
|
46
|
+
#
|
|
47
|
+
# @api public
|
|
48
|
+
# @since 2.3.0
|
|
49
|
+
def include(*mod)
|
|
50
|
+
@extensions.concat(mod).uniq!
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# @api private
|
|
54
|
+
def initialize
|
|
55
|
+
@extensions = []
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
# @api private
|
|
61
|
+
def initialize_copy(source)
|
|
62
|
+
super
|
|
63
|
+
@extensions = [*source.extensions]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def method_missing(name, *args, &block)
|
|
67
|
+
if config.respond_to?(name)
|
|
68
|
+
config.public_send(name, *args, &block)
|
|
69
|
+
else
|
|
70
|
+
super
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def respond_to_missing?(name, _include_all = false)
|
|
75
|
+
config.respond_to?(name) || super
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry/configurable"
|
|
4
|
+
|
|
5
|
+
module Hanami
|
|
6
|
+
class Config
|
|
7
|
+
# Hanami DB config
|
|
8
|
+
#
|
|
9
|
+
# @since 2.2.0
|
|
10
|
+
# @api public
|
|
11
|
+
class DB
|
|
12
|
+
include Dry::Configurable
|
|
13
|
+
|
|
14
|
+
setting :configure_from_parent, default: true
|
|
15
|
+
|
|
16
|
+
setting :import_from_parent, default: false
|
|
17
|
+
|
|
18
|
+
setting :log_level, default: :debug
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def method_missing(name, *args, &block)
|
|
23
|
+
if config.respond_to?(name)
|
|
24
|
+
config.public_send(name, *args, &block)
|
|
25
|
+
else
|
|
26
|
+
super
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def respond_to_missing?(name, _include_all = false)
|
|
31
|
+
config.respond_to?(name) || super
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry/configurable"
|
|
4
|
+
require_relative "../providers/i18n"
|
|
5
|
+
|
|
6
|
+
module Hanami
|
|
7
|
+
class Config
|
|
8
|
+
# Hanami I18n config
|
|
9
|
+
#
|
|
10
|
+
# @api public
|
|
11
|
+
# @since 3.0.0
|
|
12
|
+
class I18n
|
|
13
|
+
include Dry::Configurable
|
|
14
|
+
|
|
15
|
+
# @!attribute [rw] default_locale
|
|
16
|
+
# Sets or returns the default locale to use for translations.
|
|
17
|
+
#
|
|
18
|
+
# Defaults to `:en`.
|
|
19
|
+
#
|
|
20
|
+
# @return [Symbol]
|
|
21
|
+
#
|
|
22
|
+
# @example
|
|
23
|
+
# config.i18n.default_locale = :fr
|
|
24
|
+
#
|
|
25
|
+
# @api public
|
|
26
|
+
# @since 3.0.0
|
|
27
|
+
setting :default_locale, default: Providers::I18n::DEFAULT_LOCALE
|
|
28
|
+
|
|
29
|
+
# @!attribute [rw] available_locales
|
|
30
|
+
# Sets or returns the array of available locales for the application.
|
|
31
|
+
#
|
|
32
|
+
# When set, only these locales will be considered available, even if translation files exist
|
|
33
|
+
# for other locales. When empty or not set, all locales from loaded translation files are
|
|
34
|
+
# available.
|
|
35
|
+
#
|
|
36
|
+
# Defaults to `[]` (all loaded locales are available).
|
|
37
|
+
#
|
|
38
|
+
# @return [Array<Symbol>]
|
|
39
|
+
#
|
|
40
|
+
# @example Restrict to specific locales
|
|
41
|
+
# config.i18n.available_locales = [:en, :fr, :de]
|
|
42
|
+
#
|
|
43
|
+
# @api public
|
|
44
|
+
# @since 3.0.0
|
|
45
|
+
setting :available_locales, default: Providers::I18n::DEFAULT_AVAILABLE_LOCALES
|
|
46
|
+
|
|
47
|
+
# @!attribute [rw] load_path
|
|
48
|
+
# Sets or returns the array of file path patterns for loading per-slice translation files.
|
|
49
|
+
#
|
|
50
|
+
# Patterns can be:
|
|
51
|
+
#
|
|
52
|
+
# - Relative paths/globs (resolved against the slice's own root)
|
|
53
|
+
# - Absolute paths (used as-is)
|
|
54
|
+
#
|
|
55
|
+
# Defaults to `["config/i18n/**/*.{yml,yaml,json,rb}"]`.
|
|
56
|
+
#
|
|
57
|
+
# See {#shared_load_path} for common translations that should be loaded into every slice.
|
|
58
|
+
#
|
|
59
|
+
# @return [Array<String>]
|
|
60
|
+
#
|
|
61
|
+
# @example Append custom paths
|
|
62
|
+
# config.i18n.load_path += ["config/custom_translations/**/*.yml"]
|
|
63
|
+
#
|
|
64
|
+
# @example Replace default paths
|
|
65
|
+
# config.i18n.load_path = ["translations/**/*.yml"]
|
|
66
|
+
#
|
|
67
|
+
# @api public
|
|
68
|
+
# @since 3.0.0
|
|
69
|
+
setting :load_path, default: Providers::I18n::DEFAULT_LOAD_PATH
|
|
70
|
+
|
|
71
|
+
# @!attribute [rw] shared_load_path
|
|
72
|
+
# Sets or returns the array of file path patterns for loading translation files that
|
|
73
|
+
# should be shared across every slice in the app.
|
|
74
|
+
#
|
|
75
|
+
# Relative patterns are resolved against the **app root**, regardless of which slice is
|
|
76
|
+
# being loaded. Absolute paths are used as-is. Files matched by these patterns are loaded
|
|
77
|
+
# into every slice's i18n backend before that slice's own {#load_path} files, so
|
|
78
|
+
# slice-specific translations override shared ones on key conflicts.
|
|
79
|
+
#
|
|
80
|
+
# This is the recommended place for foundational translation data needed by every slice,
|
|
81
|
+
# such as the `date.*` and `time.*` keys used by `localize`.
|
|
82
|
+
#
|
|
83
|
+
# Defaults to `["config/i18n/shared/**/*.{yml,yaml,json,rb}"]`.
|
|
84
|
+
#
|
|
85
|
+
# @return [Array<String>]
|
|
86
|
+
#
|
|
87
|
+
# @example Disable shared translations
|
|
88
|
+
# config.i18n.shared_load_path = []
|
|
89
|
+
#
|
|
90
|
+
# @example Add another shared source
|
|
91
|
+
# config.i18n.shared_load_path += ["vendor/translations/**/*.yml"]
|
|
92
|
+
#
|
|
93
|
+
# @api public
|
|
94
|
+
# @since 3.0.0
|
|
95
|
+
setting :shared_load_path, default: Providers::I18n::DEFAULT_SHARED_LOAD_PATH
|
|
96
|
+
|
|
97
|
+
# @!attribute [rw] fallbacks
|
|
98
|
+
# Sets or returns the locale fallbacks configuration for missing translations.
|
|
99
|
+
#
|
|
100
|
+
# When enabled, the i18n backend will fall back to other locales when a translation is
|
|
101
|
+
# missing in the requested locale.
|
|
102
|
+
#
|
|
103
|
+
# This can be set to `true` to enable default fallbacks, a hash to configure explicit
|
|
104
|
+
# fallback chains per locale, or an array to set a default fallback locale for all locales.
|
|
105
|
+
#
|
|
106
|
+
# Defaults to `nil` (fallbacks disabled).
|
|
107
|
+
#
|
|
108
|
+
# @return [Boolean, Hash, Array, nil]
|
|
109
|
+
#
|
|
110
|
+
# @example Enable default fallbacks
|
|
111
|
+
# config.i18n.fallbacks = true
|
|
112
|
+
#
|
|
113
|
+
# @example Configure fallbacks with a hash
|
|
114
|
+
# config.i18n.fallbacks = {de: [:de, :en], fr: [:fr, :en]}
|
|
115
|
+
#
|
|
116
|
+
# @example Configure a default fallback locale
|
|
117
|
+
# config.i18n.fallbacks = [:en]
|
|
118
|
+
#
|
|
119
|
+
# @api public
|
|
120
|
+
# @since 3.0.0
|
|
121
|
+
setting :fallbacks
|
|
122
|
+
|
|
123
|
+
private
|
|
124
|
+
|
|
125
|
+
def method_missing(name, *args, &block)
|
|
126
|
+
if config.respond_to?(name)
|
|
127
|
+
config.public_send(name, *args, &block)
|
|
128
|
+
else
|
|
129
|
+
super
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def respond_to_missing?(name, _include_all = false)
|
|
134
|
+
config.respond_to?(name) || super
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|