hanami 2.3.2 → 3.0.0.rc1
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 +55 -19
- data/LICENSE +20 -0
- data/README.md +18 -35
- data/hanami.gemspec +36 -37
- data/lib/hanami/config/db.rb +2 -0
- data/lib/hanami/config/i18n.rb +138 -0
- data/lib/hanami/config/logger.rb +15 -7
- data/lib/hanami/config/null_config.rb +1 -1
- data/lib/hanami/config/views.rb +17 -0
- data/lib/hanami/config.rb +66 -22
- data/lib/hanami/errors.rb +6 -0
- data/lib/hanami/extensions/action/slice_configured_action.rb +1 -1
- data/lib/hanami/extensions/action.rb +2 -2
- data/lib/hanami/extensions/mailer/slice_configured_mailer.rb +120 -0
- data/lib/hanami/extensions/mailer.rb +28 -0
- data/lib/hanami/extensions/operation/slice_configured_db_operation.rb +2 -0
- data/lib/hanami/extensions/view/context.rb +26 -4
- data/lib/hanami/extensions/view/part.rb +2 -0
- data/lib/hanami/extensions/view/slice_configured_context.rb +7 -0
- data/lib/hanami/extensions/view/slice_configured_part.rb +2 -0
- data/lib/hanami/extensions/view/slice_configured_view.rb +8 -8
- data/lib/hanami/extensions/view/standard_helpers.rb +4 -0
- data/lib/hanami/extensions.rb +6 -1
- data/lib/hanami/helpers/assets_helper.rb +0 -4
- data/lib/hanami/helpers/form_helper.rb +1 -1
- data/lib/hanami/helpers/i18n_helper.rb +176 -0
- data/lib/hanami/logger/rack_formatter.rb +73 -0
- data/lib/hanami/logger/sql_formatter.rb +80 -0
- data/lib/hanami/logger/sql_logger.rb +48 -0
- data/lib/hanami/middleware/render_errors.rb +2 -2
- data/lib/hanami/providers/db.rb +7 -2
- data/lib/hanami/providers/db_logging.rb +4 -7
- data/lib/hanami/providers/i18n/backend.rb +369 -0
- data/lib/hanami/providers/i18n/locale/en.yml +57 -0
- data/lib/hanami/providers/i18n.rb +114 -0
- data/lib/hanami/providers/mailers.rb +101 -0
- data/lib/hanami/routes.rb +1 -0
- data/lib/hanami/settings/composite_store.rb +53 -0
- data/lib/hanami/settings.rb +4 -4
- data/lib/hanami/slice/router.rb +15 -10
- data/lib/hanami/slice.rb +71 -11
- data/lib/hanami/slice_registrar.rb +2 -2
- data/lib/hanami/universal_logger.rb +250 -0
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami/web/rack_logger.rb +2 -80
- data/lib/hanami/web/welcome.html.erb +443 -58
- data/lib/hanami.rb +4 -2
- metadata +28 -276
- data/CODE_OF_CONDUCT.md +0 -74
- data/FEATURES.md +0 -269
- data/LICENSE.md +0 -22
- data/spec/integration/action/cookies_spec.rb +0 -58
- data/spec/integration/action/csrf_protection_spec.rb +0 -54
- data/spec/integration/action/format_config_spec.rb +0 -129
- data/spec/integration/action/routes_spec.rb +0 -71
- data/spec/integration/action/sessions_spec.rb +0 -50
- data/spec/integration/action/slice_configuration_spec.rb +0 -284
- data/spec/integration/action/view_rendering/automatic_rendering_spec.rb +0 -247
- data/spec/integration/action/view_rendering/paired_view_inference_spec.rb +0 -115
- data/spec/integration/action/view_rendering/view_context_spec.rb +0 -221
- data/spec/integration/action/view_rendering_spec.rb +0 -89
- data/spec/integration/assets/assets_spec.rb +0 -155
- data/spec/integration/assets/cross_slice_assets_helpers_spec.rb +0 -129
- data/spec/integration/assets/serve_static_assets_spec.rb +0 -152
- data/spec/integration/code_loading/loading_from_app_spec.rb +0 -152
- data/spec/integration/code_loading/loading_from_lib_spec.rb +0 -242
- data/spec/integration/code_loading/loading_from_slice_spec.rb +0 -165
- data/spec/integration/container/application_routes_helper_spec.rb +0 -48
- data/spec/integration/container/auto_injection_spec.rb +0 -53
- data/spec/integration/container/auto_registration_spec.rb +0 -86
- data/spec/integration/container/autoloader_spec.rb +0 -82
- data/spec/integration/container/imports_spec.rb +0 -253
- data/spec/integration/container/prepare_container_spec.rb +0 -125
- data/spec/integration/container/provider_environment_spec.rb +0 -52
- data/spec/integration/container/provider_lifecycle_spec.rb +0 -61
- data/spec/integration/container/shutdown_spec.rb +0 -91
- data/spec/integration/container/standard_providers/rack_provider_spec.rb +0 -44
- data/spec/integration/container/standard_providers_spec.rb +0 -124
- data/spec/integration/db/auto_registration_spec.rb +0 -39
- data/spec/integration/db/commands_spec.rb +0 -80
- data/spec/integration/db/db_inflector_spec.rb +0 -57
- data/spec/integration/db/db_slices_spec.rb +0 -398
- data/spec/integration/db/db_spec.rb +0 -245
- data/spec/integration/db/gateways_spec.rb +0 -361
- data/spec/integration/db/logging_spec.rb +0 -301
- data/spec/integration/db/mappers_spec.rb +0 -84
- data/spec/integration/db/provider_config_spec.rb +0 -88
- data/spec/integration/db/provider_spec.rb +0 -35
- data/spec/integration/db/relations_spec.rb +0 -60
- data/spec/integration/db/repo_spec.rb +0 -300
- data/spec/integration/db/slices_importing_from_parent.rb +0 -130
- data/spec/integration/dotenv_loading_spec.rb +0 -138
- data/spec/integration/logging/exception_logging_spec.rb +0 -120
- data/spec/integration/logging/notifications_spec.rb +0 -68
- data/spec/integration/logging/request_logging_spec.rb +0 -202
- data/spec/integration/operations/extension_spec.rb +0 -122
- data/spec/integration/rack_app/body_parser_spec.rb +0 -108
- data/spec/integration/rack_app/method_override_spec.rb +0 -97
- data/spec/integration/rack_app/middleware_spec.rb +0 -720
- data/spec/integration/rack_app/non_booted_rack_app_spec.rb +0 -104
- data/spec/integration/rack_app/rack_app_spec.rb +0 -442
- data/spec/integration/rake_tasks_spec.rb +0 -107
- data/spec/integration/router/resource_routes_spec.rb +0 -281
- data/spec/integration/settings/access_in_slice_class_body_spec.rb +0 -83
- data/spec/integration/settings/access_to_constants_spec.rb +0 -46
- data/spec/integration/settings/loading_from_env_spec.rb +0 -188
- data/spec/integration/settings/settings_component_loading_spec.rb +0 -113
- data/spec/integration/settings/slice_registration_spec.rb +0 -145
- data/spec/integration/settings/using_types_spec.rb +0 -80
- data/spec/integration/setup_spec.rb +0 -165
- data/spec/integration/slices/external_slice_spec.rb +0 -91
- data/spec/integration/slices/slice_configuration_spec.rb +0 -42
- data/spec/integration/slices/slice_loading_spec.rb +0 -171
- data/spec/integration/slices/slice_registrations_spec.rb +0 -80
- data/spec/integration/slices/slice_routing_spec.rb +0 -219
- data/spec/integration/slices_spec.rb +0 -471
- data/spec/integration/view/config/default_context_spec.rb +0 -149
- data/spec/integration/view/config/inflector_spec.rb +0 -57
- data/spec/integration/view/config/part_class_spec.rb +0 -147
- data/spec/integration/view/config/part_namespace_spec.rb +0 -103
- data/spec/integration/view/config/paths_spec.rb +0 -119
- data/spec/integration/view/config/scope_class_spec.rb +0 -147
- data/spec/integration/view/config/scope_namespace_spec.rb +0 -103
- data/spec/integration/view/config/template_spec.rb +0 -38
- data/spec/integration/view/context/assets_spec.rb +0 -79
- data/spec/integration/view/context/inflector_spec.rb +0 -40
- data/spec/integration/view/context/request_spec.rb +0 -57
- data/spec/integration/view/context/routes_spec.rb +0 -84
- data/spec/integration/view/helpers/form_helper_spec.rb +0 -174
- data/spec/integration/view/helpers/part_helpers_spec.rb +0 -124
- data/spec/integration/view/helpers/scope_helpers_spec.rb +0 -84
- data/spec/integration/view/helpers/user_defined_helpers/part_helpers_spec.rb +0 -162
- data/spec/integration/view/helpers/user_defined_helpers/scope_helpers_spec.rb +0 -119
- data/spec/integration/view/parts/default_rendering_spec.rb +0 -138
- data/spec/integration/view/slice_configuration_spec.rb +0 -289
- data/spec/integration/view/views_spec.rb +0 -103
- data/spec/integration/web/content_security_policy_nonce_spec.rb +0 -251
- data/spec/integration/web/render_detailed_errors_spec.rb +0 -107
- data/spec/integration/web/render_errors_spec.rb +0 -242
- data/spec/integration/web/welcome_view_spec.rb +0 -84
- data/spec/spec_helper.rb +0 -28
- data/spec/support/app_integration.rb +0 -157
- data/spec/support/coverage.rb +0 -1
- data/spec/support/matchers.rb +0 -32
- data/spec/support/rspec.rb +0 -27
- data/spec/unit/hanami/config/actions/content_security_policy_spec.rb +0 -96
- data/spec/unit/hanami/config/actions/cookies_spec.rb +0 -46
- data/spec/unit/hanami/config/actions/csrf_protection_spec.rb +0 -58
- data/spec/unit/hanami/config/actions/default_values_spec.rb +0 -43
- data/spec/unit/hanami/config/actions/sessions_spec.rb +0 -48
- data/spec/unit/hanami/config/actions_spec.rb +0 -52
- data/spec/unit/hanami/config/base_url_spec.rb +0 -25
- data/spec/unit/hanami/config/console_spec.rb +0 -22
- data/spec/unit/hanami/config/db_spec.rb +0 -38
- data/spec/unit/hanami/config/inflector_spec.rb +0 -35
- data/spec/unit/hanami/config/logger_spec.rb +0 -195
- data/spec/unit/hanami/config/render_detailed_errors_spec.rb +0 -25
- data/spec/unit/hanami/config/render_errors_spec.rb +0 -25
- data/spec/unit/hanami/config/router_spec.rb +0 -44
- data/spec/unit/hanami/config/slices_spec.rb +0 -34
- data/spec/unit/hanami/config/views_spec.rb +0 -80
- data/spec/unit/hanami/env_spec.rb +0 -37
- data/spec/unit/hanami/extensions/view/context_spec.rb +0 -59
- data/spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb +0 -120
- data/spec/unit/hanami/helpers/assets_helper/audio_tag_spec.rb +0 -132
- data/spec/unit/hanami/helpers/assets_helper/favicon_tag_spec.rb +0 -87
- data/spec/unit/hanami/helpers/assets_helper/image_tag_spec.rb +0 -92
- data/spec/unit/hanami/helpers/assets_helper/javascript_tag_spec.rb +0 -143
- data/spec/unit/hanami/helpers/assets_helper/stylesheet_tag_spec.rb +0 -126
- data/spec/unit/hanami/helpers/assets_helper/video_tag_spec.rb +0 -136
- data/spec/unit/hanami/helpers/form_helper_spec.rb +0 -2857
- data/spec/unit/hanami/port_spec.rb +0 -117
- data/spec/unit/hanami/providers/db/config/default_config_spec.rb +0 -100
- data/spec/unit/hanami/providers/db/config/gateway_spec.rb +0 -73
- data/spec/unit/hanami/providers/db/config_spec.rb +0 -143
- data/spec/unit/hanami/router/errors/not_allowed_error_spec.rb +0 -27
- data/spec/unit/hanami/router/errors/not_found_error_spec.rb +0 -22
- data/spec/unit/hanami/settings/env_store_spec.rb +0 -52
- data/spec/unit/hanami/settings_spec.rb +0 -111
- data/spec/unit/hanami/slice_configurable_spec.rb +0 -141
- data/spec/unit/hanami/slice_name_spec.rb +0 -47
- data/spec/unit/hanami/slice_spec.rb +0 -99
- data/spec/unit/hanami/web/rack_logger_spec.rb +0 -99
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "ostruct"
|
|
4
|
-
|
|
5
|
-
# rubocop:disable Style/OpenStructUse
|
|
6
|
-
|
|
7
|
-
RSpec.describe "App view / Helpers / User-defined helpers / Scope helpers", :app_integration do
|
|
8
|
-
before do
|
|
9
|
-
with_directory(make_tmp_directory) do
|
|
10
|
-
write "config/app.rb", <<~RUBY
|
|
11
|
-
module TestApp
|
|
12
|
-
class App < Hanami::App
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
RUBY
|
|
16
|
-
|
|
17
|
-
write "app/view.rb", <<~RUBY
|
|
18
|
-
# auto_register: false
|
|
19
|
-
|
|
20
|
-
require "hanami/view"
|
|
21
|
-
|
|
22
|
-
module TestApp
|
|
23
|
-
class View < Hanami::View
|
|
24
|
-
config.layout = nil
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
RUBY
|
|
28
|
-
|
|
29
|
-
write "app/views/helpers.rb", <<~'RUBY'
|
|
30
|
-
# auto_register: false
|
|
31
|
-
|
|
32
|
-
module TestApp
|
|
33
|
-
module Views
|
|
34
|
-
module Helpers
|
|
35
|
-
def exclaim_from_app(str)
|
|
36
|
-
tag.h1("#{str}! (app #{_context.inflector.pluralize('helper')})")
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
RUBY
|
|
42
|
-
|
|
43
|
-
before_prepare if respond_to?(:before_prepare)
|
|
44
|
-
require "hanami/prepare"
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe "app view and parts" do
|
|
49
|
-
def before_prepare
|
|
50
|
-
write "app/views/posts/show.rb", <<~RUBY
|
|
51
|
-
module TestApp
|
|
52
|
-
module Views
|
|
53
|
-
module Posts
|
|
54
|
-
class Show < TestApp::View
|
|
55
|
-
expose :post
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
RUBY
|
|
61
|
-
|
|
62
|
-
write "app/views/parts/post.rb", <<~RUBY
|
|
63
|
-
module TestApp
|
|
64
|
-
module Views
|
|
65
|
-
module Parts
|
|
66
|
-
class Post < TestApp::Views::Part
|
|
67
|
-
def title
|
|
68
|
-
helpers.exclaim_from_app(value.title)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
RUBY
|
|
75
|
-
|
|
76
|
-
write "app/templates/posts/show.html.erb", <<~ERB
|
|
77
|
-
<%= post.title %>
|
|
78
|
-
ERB
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "makes user-defined helpers available in parts via a `helpers` object" do
|
|
82
|
-
post = OpenStruct.new(title: "Hello world")
|
|
83
|
-
output = TestApp::App["views.posts.show"].call(post: post).to_s.strip
|
|
84
|
-
|
|
85
|
-
expect(output).to eq "<h1>Hello world! (app helpers)</h1>"
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
describe "slice view and parts" do
|
|
90
|
-
def before_prepare
|
|
91
|
-
write "slices/main/view.rb", <<~RUBY
|
|
92
|
-
module Main
|
|
93
|
-
class View < TestApp::View
|
|
94
|
-
# FIXME: base slice views should override paths from the base app view
|
|
95
|
-
config.paths = [File.join(File.expand_path(__dir__), "templates")]
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
RUBY
|
|
99
|
-
|
|
100
|
-
write "slices/main/views/helpers.rb", <<~'RUBY'
|
|
101
|
-
# auto_register: false
|
|
102
|
-
|
|
103
|
-
module Main
|
|
104
|
-
module Views
|
|
105
|
-
module Helpers
|
|
106
|
-
def exclaim_from_slice(str)
|
|
107
|
-
tag.h1("#{str}! (slice #{_context.inflector.pluralize('helper')})")
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
RUBY
|
|
113
|
-
|
|
114
|
-
write "slices/main/views/posts/show.rb", <<~RUBY
|
|
115
|
-
module Main
|
|
116
|
-
module Views
|
|
117
|
-
module Posts
|
|
118
|
-
class Show < Main::View
|
|
119
|
-
expose :post
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
RUBY
|
|
125
|
-
|
|
126
|
-
write "slices/main/views/parts/post.rb", <<~RUBY
|
|
127
|
-
module Main
|
|
128
|
-
module Views
|
|
129
|
-
module Parts
|
|
130
|
-
class Post < Main::Views::Part
|
|
131
|
-
def title
|
|
132
|
-
helpers.exclaim_from_slice(value.title)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def title_from_app
|
|
136
|
-
helpers.exclaim_from_app(value.title)
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
RUBY
|
|
143
|
-
|
|
144
|
-
write "slices/main/templates/posts/show.html.erb", <<~ERB
|
|
145
|
-
<%= post.title %>
|
|
146
|
-
<%= post.title_from_app %>
|
|
147
|
-
ERB
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
it "makes user-defined helpers (from app as well as slice) available in parts via a `helpers` object" do
|
|
151
|
-
post = OpenStruct.new(title: "Hello world")
|
|
152
|
-
output = Main::Slice["views.posts.show"].call(post: post).to_s
|
|
153
|
-
|
|
154
|
-
expect(output).to eq <<~HTML
|
|
155
|
-
<h1>Hello world! (slice helpers)</h1>
|
|
156
|
-
<h1>Hello world! (app helpers)</h1>
|
|
157
|
-
HTML
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
# rubocop:enable Style/OpenStructUse
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "App view / Helpers / User-defined helpers / Scope helpers", :app_integration do
|
|
4
|
-
before do
|
|
5
|
-
with_directory(make_tmp_directory) do
|
|
6
|
-
write "config/app.rb", <<~RUBY
|
|
7
|
-
module TestApp
|
|
8
|
-
class App < Hanami::App
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
RUBY
|
|
12
|
-
|
|
13
|
-
write "app/view.rb", <<~RUBY
|
|
14
|
-
# auto_register: false
|
|
15
|
-
|
|
16
|
-
require "hanami/view"
|
|
17
|
-
|
|
18
|
-
module TestApp
|
|
19
|
-
class View < Hanami::View
|
|
20
|
-
config.layout = nil
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
RUBY
|
|
24
|
-
|
|
25
|
-
write "app/views/helpers.rb", <<~'RUBY'
|
|
26
|
-
# auto_register: false
|
|
27
|
-
|
|
28
|
-
module TestApp
|
|
29
|
-
module Views
|
|
30
|
-
module Helpers
|
|
31
|
-
def exclaim_from_app(str)
|
|
32
|
-
tag.h1("#{str}! (app helper)")
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
RUBY
|
|
38
|
-
|
|
39
|
-
before_prepare if respond_to?(:before_prepare)
|
|
40
|
-
require "hanami/prepare"
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
describe "app view" do
|
|
45
|
-
def before_prepare
|
|
46
|
-
write "app/views/posts/show.rb", <<~RUBY
|
|
47
|
-
module TestApp
|
|
48
|
-
module Views
|
|
49
|
-
module Posts
|
|
50
|
-
class Show < TestApp::View
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
RUBY
|
|
56
|
-
|
|
57
|
-
write "app/templates/posts/show.html.erb", <<~ERB
|
|
58
|
-
<%= exclaim_from_app("Hello world") %>
|
|
59
|
-
ERB
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "makes user-defined helpers available in templates" do
|
|
63
|
-
output = TestApp::App["views.posts.show"].call.to_s.strip
|
|
64
|
-
expect(output).to eq "<h1>Hello world! (app helper)</h1>"
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
describe "slice view" do
|
|
69
|
-
def before_prepare
|
|
70
|
-
write "slices/main/view.rb", <<~RUBY
|
|
71
|
-
module Main
|
|
72
|
-
class View < TestApp::View
|
|
73
|
-
# FIXME: base slice views should override paths from the base app view
|
|
74
|
-
config.paths = [File.join(File.expand_path(__dir__), "templates")]
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
RUBY
|
|
78
|
-
|
|
79
|
-
write "slices/main/views/helpers.rb", <<~'RUBY'
|
|
80
|
-
# auto_register: false
|
|
81
|
-
|
|
82
|
-
module Main
|
|
83
|
-
module Views
|
|
84
|
-
module Helpers
|
|
85
|
-
def exclaim_from_slice(str)
|
|
86
|
-
tag.h1("#{str}! (slice helper)")
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
RUBY
|
|
92
|
-
|
|
93
|
-
write "slices/main/views/posts/show.rb", <<~RUBY
|
|
94
|
-
module Main
|
|
95
|
-
module Views
|
|
96
|
-
module Posts
|
|
97
|
-
class Show < Main::View
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
RUBY
|
|
103
|
-
|
|
104
|
-
write "slices/main/templates/posts/show.html.erb", <<~ERB
|
|
105
|
-
<%= exclaim_from_slice("Hello world") %>
|
|
106
|
-
<%= exclaim_from_app("Hello world") %>
|
|
107
|
-
ERB
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it "makes user-defined helpers (from app as well as slice) available in templates" do
|
|
111
|
-
output = Main::Slice["views.posts.show"].call.to_s
|
|
112
|
-
|
|
113
|
-
expect(output).to eq <<~HTML
|
|
114
|
-
<h1>Hello world! (slice helper)</h1>
|
|
115
|
-
<h1>Hello world! (app helper)</h1>
|
|
116
|
-
HTML
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
end
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "App view / Parts / Default rendering", :app_integration do
|
|
4
|
-
before do
|
|
5
|
-
with_directory(make_tmp_directory) do
|
|
6
|
-
write "config/app.rb", <<~RUBY
|
|
7
|
-
module TestApp
|
|
8
|
-
class App < Hanami::App
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
RUBY
|
|
12
|
-
|
|
13
|
-
write "app/view.rb", <<~RUBY
|
|
14
|
-
# auto_register: false
|
|
15
|
-
|
|
16
|
-
require "hanami/view"
|
|
17
|
-
|
|
18
|
-
module TestApp
|
|
19
|
-
class View < Hanami::View
|
|
20
|
-
config.layout = nil
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
RUBY
|
|
24
|
-
|
|
25
|
-
write "app/views/part.rb", <<~RUBY
|
|
26
|
-
# auto_register: false
|
|
27
|
-
|
|
28
|
-
module TestApp
|
|
29
|
-
module Views
|
|
30
|
-
class Part < Hanami::View::Part
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
RUBY
|
|
35
|
-
|
|
36
|
-
before_prepare if respond_to?(:before_prepare)
|
|
37
|
-
require "hanami/prepare"
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe "app part" do
|
|
42
|
-
def before_prepare
|
|
43
|
-
write "app/views/helpers.rb", <<~RUBY
|
|
44
|
-
# auto_register: false
|
|
45
|
-
|
|
46
|
-
module TestApp
|
|
47
|
-
module Views
|
|
48
|
-
module Helpers
|
|
49
|
-
def app_screaming_snake_case(str)
|
|
50
|
-
_context.inflector
|
|
51
|
-
.underscore(str)
|
|
52
|
-
.gsub(/\s+/, "_")
|
|
53
|
-
.upcase + "!"
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
RUBY
|
|
59
|
-
write "app/views/parts/post.rb", <<~RUBY
|
|
60
|
-
# auto_register: false
|
|
61
|
-
|
|
62
|
-
module TestApp
|
|
63
|
-
module Views
|
|
64
|
-
module Parts
|
|
65
|
-
class Post < TestApp::Views::Part
|
|
66
|
-
def title_tag
|
|
67
|
-
helpers.tag.h1(helpers.app_screaming_snake_case(value.title))
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
RUBY
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it "provides a default rendering from the app" do
|
|
77
|
-
post = Struct.new(:title).new("Hello world")
|
|
78
|
-
part = TestApp::Views::Parts::Post.new(value: post)
|
|
79
|
-
|
|
80
|
-
expect(part.title_tag).to eq "<h1>HELLO_WORLD!</h1>"
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
describe "slice part" do
|
|
85
|
-
def before_prepare
|
|
86
|
-
write "slices/main/views/helpers.rb", <<~RUBY
|
|
87
|
-
# auto_register: false
|
|
88
|
-
|
|
89
|
-
module Main
|
|
90
|
-
module Views
|
|
91
|
-
module Helpers
|
|
92
|
-
def slice_screaming_snake_case(str)
|
|
93
|
-
_context.inflector
|
|
94
|
-
.underscore(str)
|
|
95
|
-
.gsub(/\s+/, "_")
|
|
96
|
-
.upcase + "!"
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
RUBY
|
|
102
|
-
|
|
103
|
-
write "slices/main/views/part.rb", <<~RUBY
|
|
104
|
-
# auto_register: false
|
|
105
|
-
|
|
106
|
-
module Main
|
|
107
|
-
module Views
|
|
108
|
-
class Part < TestApp::View::Part
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
RUBY
|
|
113
|
-
|
|
114
|
-
write "slices/main/views/parts/post.rb", <<~RUBY
|
|
115
|
-
# auto_register: false
|
|
116
|
-
|
|
117
|
-
module Main
|
|
118
|
-
module Views
|
|
119
|
-
module Parts
|
|
120
|
-
class Post < Main::Views::Part
|
|
121
|
-
def title_tag
|
|
122
|
-
helpers.tag.h1(helpers.slice_screaming_snake_case(value.title))
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
RUBY
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it "provides a default rendering from the app" do
|
|
132
|
-
post = Struct.new(:title).new("Hello world")
|
|
133
|
-
part = Main::Views::Parts::Post.new(value: post)
|
|
134
|
-
|
|
135
|
-
expect(part.title_tag).to eq "<h1>HELLO_WORLD!</h1>"
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe "App view / Slice configuration", :app_integration do
|
|
4
|
-
before do
|
|
5
|
-
with_directory(@dir = make_tmp_directory) do
|
|
6
|
-
write "config/app.rb", <<~RUBY
|
|
7
|
-
require "hanami"
|
|
8
|
-
|
|
9
|
-
module TestApp
|
|
10
|
-
class App < Hanami::App
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
RUBY
|
|
14
|
-
|
|
15
|
-
write "app/view.rb", <<~RUBY
|
|
16
|
-
require "hanami/view"
|
|
17
|
-
|
|
18
|
-
module TestApp
|
|
19
|
-
class View < Hanami::View
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
RUBY
|
|
23
|
-
|
|
24
|
-
require "hanami/setup"
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def prepare_app
|
|
29
|
-
with_directory(@dir) { require "hanami/prepare" }
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe "inheriting from app-level base class" do
|
|
33
|
-
describe "app-level base class" do
|
|
34
|
-
it "applies default views config from the app", :aggregate_failures do
|
|
35
|
-
prepare_app
|
|
36
|
-
|
|
37
|
-
expect(TestApp::View.config.layouts_dir).to eq "layouts"
|
|
38
|
-
expect(TestApp::View.config.layout).to eq "app"
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "applies views config from the app" do
|
|
42
|
-
Hanami.app.config.views.layout = "app_layout"
|
|
43
|
-
|
|
44
|
-
prepare_app
|
|
45
|
-
|
|
46
|
-
expect(TestApp::View.config.layout).to eq "app_layout"
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "does not override config in the base class" do
|
|
50
|
-
Hanami.app.config.views.layout = "app_layout"
|
|
51
|
-
|
|
52
|
-
prepare_app
|
|
53
|
-
|
|
54
|
-
TestApp::View.config.layout = "custom_layout"
|
|
55
|
-
|
|
56
|
-
expect(TestApp::View.config.layout).to eq "custom_layout"
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
describe "subclass in app" do
|
|
61
|
-
before do
|
|
62
|
-
with_directory(@dir) do
|
|
63
|
-
write "app/views/articles/index.rb", <<~RUBY
|
|
64
|
-
module TestApp
|
|
65
|
-
module Views
|
|
66
|
-
module Articles
|
|
67
|
-
class Index < TestApp::View
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
RUBY
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it "applies default views config from the app", :aggregate_failures do
|
|
77
|
-
prepare_app
|
|
78
|
-
|
|
79
|
-
expect(TestApp::Views::Articles::Index.config.layouts_dir).to eq "layouts"
|
|
80
|
-
expect(TestApp::Views::Articles::Index.config.layout).to eq "app"
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "applies views config from the app" do
|
|
84
|
-
Hanami.app.config.views.layout = "app_layout"
|
|
85
|
-
|
|
86
|
-
prepare_app
|
|
87
|
-
|
|
88
|
-
expect(TestApp::Views::Articles::Index.config.layout).to eq "app_layout"
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it "applies config from the base class" do
|
|
92
|
-
prepare_app
|
|
93
|
-
|
|
94
|
-
TestApp::View.config.layout = "base_class_layout"
|
|
95
|
-
|
|
96
|
-
expect(TestApp::Views::Articles::Index.config.layout).to eq "base_class_layout"
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
describe "subclass in slice" do
|
|
101
|
-
before do
|
|
102
|
-
with_directory(@dir) do
|
|
103
|
-
write "slices/admin/views/articles/index.rb", <<~RUBY
|
|
104
|
-
module Admin
|
|
105
|
-
module Views
|
|
106
|
-
module Articles
|
|
107
|
-
class Index < TestApp::View
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
RUBY
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it "applies default views config from the app", :aggregate_failures do
|
|
117
|
-
prepare_app
|
|
118
|
-
|
|
119
|
-
expect(Admin::Views::Articles::Index.config.layouts_dir).to eq "layouts"
|
|
120
|
-
expect(Admin::Views::Articles::Index.config.layout).to eq "app"
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
it "applies views config from the app" do
|
|
124
|
-
Hanami.app.config.views.layout = "app_layout"
|
|
125
|
-
|
|
126
|
-
prepare_app
|
|
127
|
-
|
|
128
|
-
expect(Admin::Views::Articles::Index.config.layout).to eq "app_layout"
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it "applies config from the base class" do
|
|
132
|
-
prepare_app
|
|
133
|
-
|
|
134
|
-
TestApp::View.config.layout = "base_class_layout"
|
|
135
|
-
|
|
136
|
-
expect(Admin::Views::Articles::Index.config.layout).to eq "base_class_layout"
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
describe "inheriting from a slice-level base class, in turn inheriting from an app-level base class" do
|
|
142
|
-
before do
|
|
143
|
-
with_directory(@dir) do
|
|
144
|
-
write "slices/admin/view.rb", <<~RUBY
|
|
145
|
-
module Admin
|
|
146
|
-
class View < TestApp::View
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
RUBY
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
describe "slice-level base class" do
|
|
154
|
-
it "applies default views config from the app", :aggregate_failures do
|
|
155
|
-
prepare_app
|
|
156
|
-
|
|
157
|
-
expect(Admin::View.config.layouts_dir).to eq "layouts"
|
|
158
|
-
expect(Admin::View.config.layout).to eq "app"
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
it "applies views config from the app" do
|
|
162
|
-
Hanami.app.config.views.layout = "app_layout"
|
|
163
|
-
|
|
164
|
-
prepare_app
|
|
165
|
-
|
|
166
|
-
expect(Admin::View.config.layout).to eq "app_layout"
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
it "applies config from the app base class" do
|
|
170
|
-
prepare_app
|
|
171
|
-
|
|
172
|
-
TestApp::View.config.layout = "app_base_class_layout"
|
|
173
|
-
|
|
174
|
-
expect(Admin::View.config.layout).to eq "app_base_class_layout"
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
context "slice views config present" do
|
|
178
|
-
before do
|
|
179
|
-
with_directory(@dir) do
|
|
180
|
-
write "config/slices/admin.rb", <<~RUBY
|
|
181
|
-
module Admin
|
|
182
|
-
class Slice < Hanami::Slice
|
|
183
|
-
config.views.layout = "slice_layout"
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
RUBY
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
it "applies views config from the slice" do
|
|
191
|
-
prepare_app
|
|
192
|
-
|
|
193
|
-
expect(Admin::View.config.layout).to eq "slice_layout"
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
it "prefers views config from the slice over config from the app-level base class" do
|
|
197
|
-
prepare_app
|
|
198
|
-
|
|
199
|
-
TestApp::View.config.layout = "app_base_class_layout"
|
|
200
|
-
|
|
201
|
-
expect(Admin::View.config.layout).to eq "slice_layout"
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
it "prefers config from the base class over views config from the slice" do
|
|
205
|
-
prepare_app
|
|
206
|
-
|
|
207
|
-
TestApp::View.config.layout = "app_base_class_layout"
|
|
208
|
-
Admin::View.config.layout = "slice_base_class_layout"
|
|
209
|
-
|
|
210
|
-
expect(Admin::View.config.layout).to eq "slice_base_class_layout"
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
describe "subclass in slice" do
|
|
216
|
-
before do
|
|
217
|
-
with_directory(@dir) do
|
|
218
|
-
write "slices/admin/views/articles/index.rb", <<~RUBY
|
|
219
|
-
module Admin
|
|
220
|
-
module Views
|
|
221
|
-
module Articles
|
|
222
|
-
class Index < Admin::View
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
end
|
|
227
|
-
RUBY
|
|
228
|
-
end
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
it "applies default views config from the app", :aggregate_failures do
|
|
232
|
-
prepare_app
|
|
233
|
-
|
|
234
|
-
expect(Admin::Views::Articles::Index.config.layouts_dir).to eq "layouts"
|
|
235
|
-
expect(Admin::Views::Articles::Index.config.layout).to eq "app"
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
it "applies views config from the app" do
|
|
239
|
-
Hanami.app.config.views.layout = "app_layout"
|
|
240
|
-
|
|
241
|
-
prepare_app
|
|
242
|
-
|
|
243
|
-
expect(Admin::Views::Articles::Index.config.layout).to eq "app_layout"
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
it "applies views config from the slice" do
|
|
247
|
-
with_directory(@dir) do
|
|
248
|
-
write "config/slices/admin.rb", <<~RUBY
|
|
249
|
-
module Admin
|
|
250
|
-
class Slice < Hanami::Slice
|
|
251
|
-
config.views.layout = "slice_layout"
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
RUBY
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
prepare_app
|
|
258
|
-
|
|
259
|
-
expect(Admin::Views::Articles::Index.config.layout).to eq "slice_layout"
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
it "applies config from the slice base class" do
|
|
263
|
-
prepare_app
|
|
264
|
-
|
|
265
|
-
Admin::View.config.layout = "slice_base_class_layout"
|
|
266
|
-
|
|
267
|
-
expect(Admin::Views::Articles::Index.config.layout).to eq "slice_base_class_layout"
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
it "prefers config from the slice base class over views config from the slice" do
|
|
271
|
-
with_directory(@dir) do
|
|
272
|
-
write "config/slices/admin.rb", <<~RUBY
|
|
273
|
-
module Admin
|
|
274
|
-
class Slice < Hanami::Slice
|
|
275
|
-
config.views.layout = "slice_layout"
|
|
276
|
-
end
|
|
277
|
-
end
|
|
278
|
-
RUBY
|
|
279
|
-
end
|
|
280
|
-
|
|
281
|
-
prepare_app
|
|
282
|
-
|
|
283
|
-
Admin::View.config.layout = "slice_base_class_layout"
|
|
284
|
-
|
|
285
|
-
expect(Admin::Views::Articles::Index.config.layout).to eq "slice_base_class_layout"
|
|
286
|
-
end
|
|
287
|
-
end
|
|
288
|
-
end
|
|
289
|
-
end
|