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,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hanami
|
|
4
|
+
module Extensions
|
|
5
|
+
module View
|
|
6
|
+
# Provides slice-specific helper methods for any view object requiring access to helpers.
|
|
7
|
+
#
|
|
8
|
+
# @api public
|
|
9
|
+
# @since 2.1.0
|
|
10
|
+
class SliceConfiguredHelpers < Module
|
|
11
|
+
attr_reader :slice
|
|
12
|
+
|
|
13
|
+
# @api private
|
|
14
|
+
# @since 2.1.0
|
|
15
|
+
def initialize(slice)
|
|
16
|
+
super()
|
|
17
|
+
@slice = slice
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @api private
|
|
21
|
+
# @since 2.1.0
|
|
22
|
+
def extended(klass)
|
|
23
|
+
include_helpers(klass)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @return [String]
|
|
27
|
+
#
|
|
28
|
+
# @api public
|
|
29
|
+
# @since 2.1.0
|
|
30
|
+
def inspect
|
|
31
|
+
"#<#{self.class.name}[#{slice.name}]>"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def include_helpers(klass)
|
|
37
|
+
if mod = helpers_module(slice.app)
|
|
38
|
+
klass.include(mod)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
if mod = helpers_module(slice)
|
|
42
|
+
klass.include(mod)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def helpers_module(slice)
|
|
47
|
+
return unless slice.namespace.const_defined?(:Views)
|
|
48
|
+
return unless slice.namespace.const_get(:Views).const_defined?(:Helpers)
|
|
49
|
+
|
|
50
|
+
slice.namespace.const_get(:Views).const_get(:Helpers)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hanami
|
|
4
|
+
module Extensions
|
|
5
|
+
module View
|
|
6
|
+
# Provides slice-specific configuration and behavior for any view part class defined within a
|
|
7
|
+
# slice's module namespace.
|
|
8
|
+
#
|
|
9
|
+
# @api public
|
|
10
|
+
# @since 2.1.0
|
|
11
|
+
class SliceConfiguredPart < Module
|
|
12
|
+
attr_reader :slice
|
|
13
|
+
|
|
14
|
+
# @api private
|
|
15
|
+
# @since 2.1.0
|
|
16
|
+
def initialize(slice)
|
|
17
|
+
super()
|
|
18
|
+
@slice = slice
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @api private
|
|
22
|
+
# @since 2.1.0
|
|
23
|
+
def extended(klass)
|
|
24
|
+
define_new
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @return [String]
|
|
28
|
+
#
|
|
29
|
+
# @api public
|
|
30
|
+
# @since 2.1.0
|
|
31
|
+
def inspect
|
|
32
|
+
"#<#{self.class.name}[#{slice.name}]>"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
# Defines a `.new` method on the part class that provides a default `rendering:` argument of
|
|
38
|
+
# a rendering coming from a view configured for the slice. This means that any part can be
|
|
39
|
+
# initialized standalone (with a `value:` only) and still have access to all the integrated
|
|
40
|
+
# view facilities from the slice, such as helpers. This is helpful when unit testing parts.
|
|
41
|
+
#
|
|
42
|
+
# @example
|
|
43
|
+
# module MyApp::Views::Parts
|
|
44
|
+
# class Post < MyApp::View::Part
|
|
45
|
+
# def title_tag
|
|
46
|
+
# helpers.h1(value.title)
|
|
47
|
+
# end
|
|
48
|
+
# end
|
|
49
|
+
# end
|
|
50
|
+
#
|
|
51
|
+
# # Useful when unit testing parts
|
|
52
|
+
# part = MyApp::Views::Parts::Post.new(value: hello_world_post)
|
|
53
|
+
# part.title_tag # => "<h1>Hello world</h1>"
|
|
54
|
+
def define_new
|
|
55
|
+
slice = self.slice
|
|
56
|
+
|
|
57
|
+
define_method(:new) do |**args|
|
|
58
|
+
return super(**args) if args.key?(:rendering)
|
|
59
|
+
|
|
60
|
+
# Call configure_for_slice explicitly, since this is an anonymous class at this point,
|
|
61
|
+
# so the slice cannot be inferred from its name.
|
|
62
|
+
slice_rendering = Class.new(Hanami::View)
|
|
63
|
+
.configure_for_slice(slice)
|
|
64
|
+
.new
|
|
65
|
+
.rendering
|
|
66
|
+
|
|
67
|
+
super(rendering: slice_rendering, **args)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hanami
|
|
4
|
+
module Extensions
|
|
5
|
+
module View
|
|
6
|
+
# Provides slice-specific configuration and behavior for any view class defined within a
|
|
7
|
+
# slice's module namespace.
|
|
8
|
+
#
|
|
9
|
+
# @api public
|
|
10
|
+
# @since 2.1.0
|
|
11
|
+
class SliceConfiguredView < Module
|
|
12
|
+
TEMPLATES_DIR = "templates"
|
|
13
|
+
VIEWS_DIR = "views"
|
|
14
|
+
PARTS_DIR = "parts"
|
|
15
|
+
SCOPES_DIR = "scopes"
|
|
16
|
+
|
|
17
|
+
attr_reader :slice
|
|
18
|
+
|
|
19
|
+
# @api private
|
|
20
|
+
# @since 2.1.0
|
|
21
|
+
def initialize(slice)
|
|
22
|
+
super()
|
|
23
|
+
@slice = slice
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @api private
|
|
27
|
+
# @since 2.1.0
|
|
28
|
+
def extended(view_class)
|
|
29
|
+
load_app_view
|
|
30
|
+
configure_view(view_class)
|
|
31
|
+
define_inherited
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @return [String]
|
|
35
|
+
#
|
|
36
|
+
# @api public
|
|
37
|
+
# @since 2.1.0
|
|
38
|
+
def inspect
|
|
39
|
+
"#<#{self.class.name}[#{slice.name}]>"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
# If the given view doesn't inherit from the app view, attempt to load it anyway, since
|
|
45
|
+
# requiring the app view is necessary for _its_ `SliceConfiguredView` hook to execute and
|
|
46
|
+
# define the app-level part and scope classes that we refer to here.
|
|
47
|
+
def load_app_view
|
|
48
|
+
return if app?
|
|
49
|
+
|
|
50
|
+
begin
|
|
51
|
+
slice.app.namespace.const_get(:View, false)
|
|
52
|
+
rescue NameError => exception
|
|
53
|
+
raise unless exception.name == :View
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
58
|
+
def configure_view(view_class)
|
|
59
|
+
view_class.settings.each do |setting|
|
|
60
|
+
next unless slice.config.views.respond_to?(setting.name)
|
|
61
|
+
|
|
62
|
+
# Configure the view from config on the slice, _unless it has already been configured by
|
|
63
|
+
# a parent slice_, and re-configuring it for this slice would make no change.
|
|
64
|
+
#
|
|
65
|
+
# In the case of most slices, its views config is likely to be the same as its parent
|
|
66
|
+
# (since each slice copies its `config` from its parent), and if we re-apply the config
|
|
67
|
+
# here, then it may possibly overwrite config customisations explicitly made in parent
|
|
68
|
+
# view classes.
|
|
69
|
+
#
|
|
70
|
+
# For example, given an app-level base view class, with custom config:
|
|
71
|
+
#
|
|
72
|
+
# module MyApp
|
|
73
|
+
# class View < Hanami::View
|
|
74
|
+
# config.layout = "custom_layout"
|
|
75
|
+
# end
|
|
76
|
+
# end
|
|
77
|
+
#
|
|
78
|
+
# And then a view in a slice inheriting from it:
|
|
79
|
+
#
|
|
80
|
+
# module MySlice
|
|
81
|
+
# module Views
|
|
82
|
+
# class SomeView < MyApp::View
|
|
83
|
+
# end
|
|
84
|
+
# end
|
|
85
|
+
# end
|
|
86
|
+
#
|
|
87
|
+
# In this case, `SliceConfiguredView` will be extended two times:
|
|
88
|
+
#
|
|
89
|
+
# 1. When `MyApp::View` is defined
|
|
90
|
+
# 2. Again when `MySlice::Views::SomeView` is defined
|
|
91
|
+
#
|
|
92
|
+
# If we blindly re-configure all view settings each time `SliceConfiguredView` is
|
|
93
|
+
# extended, then at the point of (2) above, we'd end up overwriting the custom
|
|
94
|
+
# `config.layout` explicitly configured in the `MyApp::View` base class, leaving
|
|
95
|
+
# `MySlice::Views::SomeView` with `config.layout` of `"app"` (the default as specified
|
|
96
|
+
# at `Hanami.app.config.views.layout`), and not the `"custom_layout"` value configured
|
|
97
|
+
# in its immediate superclass.
|
|
98
|
+
#
|
|
99
|
+
# This would be surprising behavior, and we want to avoid it.
|
|
100
|
+
slice_value = slice.config.views.public_send(setting.name)
|
|
101
|
+
parent_value = slice.parent.config.views.public_send(setting.name) if slice.parent
|
|
102
|
+
|
|
103
|
+
next if slice.parent && slice_value == parent_value
|
|
104
|
+
|
|
105
|
+
view_class.config.public_send(
|
|
106
|
+
:"#{setting.name}=",
|
|
107
|
+
setting.mutable? ? slice_value.dup : slice_value
|
|
108
|
+
)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
view_class.config.inflector = inflector
|
|
112
|
+
|
|
113
|
+
# Configure the paths for this view if:
|
|
114
|
+
# - We are the app, and a user hasn't provided custom `paths` (in this case, we need to
|
|
115
|
+
# set the defaults)
|
|
116
|
+
# - We are a slice, and the view's inherited `paths` is identical to the parent's config
|
|
117
|
+
# (which would result in the view in a slice erroneously trying to find templates in
|
|
118
|
+
# the app)
|
|
119
|
+
if view_class.config.paths.empty? ||
|
|
120
|
+
(slice.parent && view_class.config.paths.map(&:dir) == [templates_path(slice.parent)])
|
|
121
|
+
view_class.config.paths = templates_path(slice)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
view_class.config.template = template_name(view_class)
|
|
125
|
+
view_class.config.default_context = Extensions::View::Context.context_class(slice).new
|
|
126
|
+
|
|
127
|
+
view_class.config.part_class = part_class
|
|
128
|
+
view_class.config.scope_class = scope_class
|
|
129
|
+
|
|
130
|
+
if (part_namespace = namespace_from_path("#{VIEWS_DIR}/#{PARTS_DIR}"))
|
|
131
|
+
view_class.config.part_namespace = part_namespace
|
|
132
|
+
end
|
|
133
|
+
if (scope_namespace = namespace_from_path("#{VIEWS_DIR}/#{SCOPES_DIR}"))
|
|
134
|
+
view_class.config.scope_namespace = scope_namespace
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
138
|
+
|
|
139
|
+
def define_inherited
|
|
140
|
+
template_name = method(:template_name)
|
|
141
|
+
|
|
142
|
+
define_method(:inherited) do |subclass|
|
|
143
|
+
super(subclass)
|
|
144
|
+
subclass.config.template = template_name.(subclass)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def templates_path(slice)
|
|
149
|
+
if slice.app.equal?(slice)
|
|
150
|
+
slice.root.join(APP_DIR, TEMPLATES_DIR)
|
|
151
|
+
else
|
|
152
|
+
slice.root.join(TEMPLATES_DIR)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def namespace_from_path(path)
|
|
157
|
+
path = "#{slice.slice_name.path}/#{path}"
|
|
158
|
+
|
|
159
|
+
begin
|
|
160
|
+
require path
|
|
161
|
+
rescue LoadError => exception
|
|
162
|
+
raise exception unless exception.path == path
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
begin
|
|
166
|
+
inflector.constantize(inflector.camelize(path))
|
|
167
|
+
rescue NameError # rubocop: disable Lint/SuppressedException
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def template_name(view_class)
|
|
172
|
+
inflector
|
|
173
|
+
.underscore(view_class.name)
|
|
174
|
+
.sub(/^#{slice.slice_name.path}\//, "")
|
|
175
|
+
.sub(/^#{VIEWS_DIR}\//, "")
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def inflector
|
|
179
|
+
slice.inflector
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def part_class
|
|
183
|
+
@part_class ||=
|
|
184
|
+
if views_namespace.const_defined?(:Part)
|
|
185
|
+
views_namespace.const_get(:Part)
|
|
186
|
+
else
|
|
187
|
+
views_namespace.const_set(:Part, Class.new(part_superclass).tap { |klass|
|
|
188
|
+
# Call configure_for_slice explicitly, since this is an anonymous class at this point,
|
|
189
|
+
# so the slice cannot be inferred from its name.
|
|
190
|
+
klass.configure_for_slice(slice)
|
|
191
|
+
})
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def part_superclass
|
|
196
|
+
return Hanami::View::Part if app?
|
|
197
|
+
|
|
198
|
+
begin
|
|
199
|
+
inflector.constantize(inflector.camelize("#{slice.app.slice_name.name}/views/part"))
|
|
200
|
+
rescue NameError
|
|
201
|
+
Hanami::View::Part
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def scope_class
|
|
206
|
+
@scope_class ||=
|
|
207
|
+
if views_namespace.const_defined?(:Scope)
|
|
208
|
+
views_namespace.const_get(:Scope)
|
|
209
|
+
else
|
|
210
|
+
views_namespace.const_set(:Scope, Class.new(scope_superclass).tap { |klass|
|
|
211
|
+
# Call configure_for_slice explicitly, since this is an anonymous class at this point,
|
|
212
|
+
# so the slice cannot be inferred from its name.
|
|
213
|
+
klass.configure_for_slice(slice)
|
|
214
|
+
})
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def scope_superclass
|
|
219
|
+
return Hanami::View::Scope if app?
|
|
220
|
+
|
|
221
|
+
begin
|
|
222
|
+
inflector.constantize(inflector.camelize("#{slice.app.slice_name.name}/views/scope"))
|
|
223
|
+
rescue NameError
|
|
224
|
+
Hanami::View::Scope
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def views_namespace
|
|
229
|
+
@slice_views_namespace ||=
|
|
230
|
+
if slice.namespace.const_defined?(:Views)
|
|
231
|
+
slice.namespace.const_get(:Views)
|
|
232
|
+
else
|
|
233
|
+
slice.namespace.const_set(:Views, Module.new)
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def app?
|
|
238
|
+
slice.app == slice
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Hanami
|
|
4
|
+
module Extensions
|
|
5
|
+
module View
|
|
6
|
+
# Module including the standard library of Hanami helpers
|
|
7
|
+
#
|
|
8
|
+
# @api public
|
|
9
|
+
# @since 2.1.0
|
|
10
|
+
module StandardHelpers
|
|
11
|
+
include Hanami::View::Helpers::EscapeHelper
|
|
12
|
+
include Hanami::View::Helpers::NumberFormattingHelper
|
|
13
|
+
include Hanami::View::Helpers::TagHelper
|
|
14
|
+
include Helpers::FormHelper
|
|
15
|
+
|
|
16
|
+
if Hanami.bundled?("hanami-assets")
|
|
17
|
+
include Helpers::AssetsHelper
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
if Hanami.bundled?("i18n")
|
|
21
|
+
include Helpers::I18nHelper
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "hanami/view"
|
|
4
|
+
require_relative "view/slice_configured_view"
|
|
5
|
+
|
|
6
|
+
module Hanami
|
|
7
|
+
# @api private
|
|
8
|
+
module Extensions
|
|
9
|
+
# Integrated behavior for `Hanami::View` classes within Hanami apps.
|
|
10
|
+
#
|
|
11
|
+
# @see Hanami::View
|
|
12
|
+
#
|
|
13
|
+
# @api public
|
|
14
|
+
# @since 2.1.0
|
|
15
|
+
module View
|
|
16
|
+
# @api private
|
|
17
|
+
# @since 2.1.0
|
|
18
|
+
def self.included(view_class)
|
|
19
|
+
super
|
|
20
|
+
|
|
21
|
+
view_class.extend(Hanami::SliceConfigurable)
|
|
22
|
+
view_class.extend(ClassMethods)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @api private
|
|
26
|
+
# @since 2.1.0
|
|
27
|
+
module ClassMethods
|
|
28
|
+
# @api private
|
|
29
|
+
# @since 2.1.0
|
|
30
|
+
def configure_for_slice(slice)
|
|
31
|
+
extend SliceConfiguredView.new(slice)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
Hanami::View.include(Hanami::Extensions::View)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
if Hanami.bundled?("hanami-db")
|
|
4
|
+
require_relative "extensions/db/repo"
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
if Hanami.bundled?("hanami-action")
|
|
8
|
+
require_relative "extensions/action"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
if Hanami.bundled?("hanami-view")
|
|
12
|
+
require "hanami/view"
|
|
13
|
+
require_relative "extensions/view"
|
|
14
|
+
require_relative "extensions/view/context"
|
|
15
|
+
require_relative "extensions/view/part"
|
|
16
|
+
require_relative "extensions/view/scope"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
if Hanami.bundled?("hanami-router")
|
|
20
|
+
require_relative "extensions/router/errors"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
if Hanami.bundled?("hanami-mailer")
|
|
24
|
+
require "hanami/mailer"
|
|
25
|
+
require_relative "extensions/mailer"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
if Hanami.bundled?("dry-operation")
|
|
29
|
+
require_relative "extensions/operation"
|
|
30
|
+
end
|