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,80 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "hanami/config"
|
|
4
|
-
require "saharspec/matchers/dont"
|
|
5
|
-
|
|
6
|
-
RSpec.describe Hanami::Config, "#views" do
|
|
7
|
-
let(:config) { described_class.new(app_name: app_name, env: :development) }
|
|
8
|
-
let(:app_name) { "MyApp::app" }
|
|
9
|
-
|
|
10
|
-
subject(:views) { config.views }
|
|
11
|
-
|
|
12
|
-
context "hanami-view is bundled" do
|
|
13
|
-
it "exposes Hanami::Views's app config" do
|
|
14
|
-
is_expected.to be_an_instance_of(Hanami::Config::Views)
|
|
15
|
-
|
|
16
|
-
is_expected.to respond_to(:finalize!)
|
|
17
|
-
is_expected.to respond_to(:layouts_dir)
|
|
18
|
-
is_expected.to respond_to(:layouts_dir=)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "includes base view config" do
|
|
22
|
-
expect(views).to respond_to(:paths)
|
|
23
|
-
expect(views).to respond_to(:paths=)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "does not include the inflector setting" do
|
|
27
|
-
expect(views).not_to respond_to(:inflector)
|
|
28
|
-
expect(views).not_to respond_to(:inflector=)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "preserves default values from the base view config" do
|
|
32
|
-
expect(views.layouts_dir).to eq Hanami::View.config.layouts_dir
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "allows settings to be configured independently of the base view config" do
|
|
36
|
-
expect { views.layouts_dir = "custom_layouts" }
|
|
37
|
-
.to change { views.layouts_dir }.to("custom_layouts")
|
|
38
|
-
.and(dont.change { Hanami::View.config.layouts_dir })
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe "specialised default values" do
|
|
42
|
-
describe "layout" do
|
|
43
|
-
it 'is "app"' do
|
|
44
|
-
expect(views.layout).to eq "app"
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe "finalized config" do
|
|
50
|
-
before do
|
|
51
|
-
views.finalize!
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "is frozen" do
|
|
55
|
-
expect(views).to be_frozen
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "does not allow changes to base view settings" do
|
|
59
|
-
expect { views.paths = [] }.to raise_error(Dry::Configurable::FrozenConfigError)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
context "hanami-view is not bundled" do
|
|
65
|
-
before do
|
|
66
|
-
allow(Hanami).to receive(:bundled?).and_call_original
|
|
67
|
-
expect(Hanami).to receive(:bundled?).with("hanami-view").and_return(false)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "does not expose any settings" do
|
|
71
|
-
is_expected.to be_an_instance_of(Hanami::Config::NullConfig)
|
|
72
|
-
is_expected.not_to respond_to(:layouts_dir)
|
|
73
|
-
is_expected.not_to respond_to(:layouts_dir=)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it "can be finalized" do
|
|
77
|
-
is_expected.to respond_to(:finalize!)
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Hanami, ".env" do
|
|
4
|
-
subject { described_class.env(e: env) }
|
|
5
|
-
|
|
6
|
-
context "HANAMI_ENV, APP_ENV and RACK_ENV in ENV" do
|
|
7
|
-
let(:env) { { "HANAMI_ENV" => "test", "APP_ENV" => "development", "RACK_ENV" => "production" } }
|
|
8
|
-
|
|
9
|
-
it "is the value of HANAMI_ENV" do
|
|
10
|
-
is_expected.to eq(:test)
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
context "APP_ENV and RACK_ENV in ENV" do
|
|
15
|
-
let(:env) { {"APP_ENV" => "development", "RACK_ENV" => "production" } }
|
|
16
|
-
|
|
17
|
-
it "is the value of APP_ENV" do
|
|
18
|
-
is_expected.to eq(:development)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
context "RACK_ENV in ENV" do
|
|
23
|
-
let(:env) { { "RACK_ENV" => "production" } }
|
|
24
|
-
|
|
25
|
-
it "is the value of RACK_ENV" do
|
|
26
|
-
is_expected.to eq(:production)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
context "no ENV vars set" do
|
|
31
|
-
let(:env) { {} }
|
|
32
|
-
|
|
33
|
-
it "defaults to \"development\"" do
|
|
34
|
-
is_expected.to eq(:development)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
require "hanami/view"
|
|
2
|
-
require "hanami/view/context"
|
|
3
|
-
require "hanami/extensions/view/context"
|
|
4
|
-
|
|
5
|
-
RSpec.describe(Hanami::View::Context) do
|
|
6
|
-
subject(:context) { described_class.new(**args) }
|
|
7
|
-
let(:args) { {} }
|
|
8
|
-
|
|
9
|
-
describe "#assets" do
|
|
10
|
-
context "assets given" do
|
|
11
|
-
let(:args) { {assets: assets} }
|
|
12
|
-
let(:assets) { double(:assets) }
|
|
13
|
-
|
|
14
|
-
it "returns the assets" do
|
|
15
|
-
expect(context.assets).to be assets
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
context "no assets given" do
|
|
20
|
-
it "raises a Hanami::ComponentLoadError" do
|
|
21
|
-
expect { context.assets }.to raise_error Hanami::ComponentLoadError
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe "#request" do
|
|
27
|
-
context "request given" do
|
|
28
|
-
let(:args) { {request: request} }
|
|
29
|
-
let(:request) { double(:request) }
|
|
30
|
-
|
|
31
|
-
it "returns the request" do
|
|
32
|
-
expect(context.request).to be request
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context "no request given" do
|
|
37
|
-
it "raises a Hanami::ComponentLoadError" do
|
|
38
|
-
expect { context.request }.to raise_error Hanami::ComponentLoadError
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe "#routes" do
|
|
44
|
-
context "routes given" do
|
|
45
|
-
let(:args) { {routes: routes} }
|
|
46
|
-
let(:routes) { double(:routes) }
|
|
47
|
-
|
|
48
|
-
it "returns the routes" do
|
|
49
|
-
expect(context.routes).to be routes
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context "no routes given" do
|
|
54
|
-
it "raises a Hanami::ComponentLoadError" do
|
|
55
|
-
expect { context.routes }.to raise_error Hanami::ComponentLoadError
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Hanami::Helpers::AssetsHelper, "#asset_url", :app_integration do
|
|
4
|
-
subject(:obj) {
|
|
5
|
-
helpers = described_class
|
|
6
|
-
Class.new {
|
|
7
|
-
include helpers
|
|
8
|
-
|
|
9
|
-
attr_reader :_context
|
|
10
|
-
|
|
11
|
-
def initialize(context)
|
|
12
|
-
@_context = context
|
|
13
|
-
end
|
|
14
|
-
}.new(context)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
def asset_url(...)
|
|
18
|
-
subject.asset_url(...)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
let(:context) { TestApp::Views::Context.new }
|
|
22
|
-
let(:root) { make_tmp_directory }
|
|
23
|
-
|
|
24
|
-
before do
|
|
25
|
-
with_directory(root) do
|
|
26
|
-
write "config/app.rb", <<~RUBY
|
|
27
|
-
module TestApp
|
|
28
|
-
class App < Hanami::App
|
|
29
|
-
config.logger.stream = StringIO.new
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
RUBY
|
|
33
|
-
|
|
34
|
-
write "app/views/context.rb", <<~RUBY
|
|
35
|
-
# auto_register: false
|
|
36
|
-
|
|
37
|
-
require "hanami/view/context"
|
|
38
|
-
|
|
39
|
-
module TestApp
|
|
40
|
-
module Views
|
|
41
|
-
class Context < Hanami::View::Context
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
RUBY
|
|
46
|
-
|
|
47
|
-
write "app/assets/js/app.ts", <<~JS
|
|
48
|
-
import "../css/app.css";
|
|
49
|
-
|
|
50
|
-
console.log("Hello from index.ts");
|
|
51
|
-
JS
|
|
52
|
-
|
|
53
|
-
write "app/assets/css/app.css", <<~CSS
|
|
54
|
-
.btn {
|
|
55
|
-
background: #f00;
|
|
56
|
-
}
|
|
57
|
-
CSS
|
|
58
|
-
|
|
59
|
-
stub_assets("app.js")
|
|
60
|
-
|
|
61
|
-
require "hanami/setup"
|
|
62
|
-
before_prepare if respond_to?(:before_prepare)
|
|
63
|
-
require "hanami/prepare"
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
context "when configurated relative path only" do
|
|
68
|
-
context "without manifest" do
|
|
69
|
-
it "returns the relative URL to the asset" do
|
|
70
|
-
expect(asset_url("app.js")).to eq("/assets/app.js")
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "returns absolute URL if the argument is an absolute URL" do
|
|
74
|
-
result = asset_url("http://assets.hanamirb.org/assets/application.css")
|
|
75
|
-
expect(result).to eq("http://assets.hanamirb.org/assets/application.css")
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
context "with manifest" do
|
|
80
|
-
before { compile_assets! }
|
|
81
|
-
|
|
82
|
-
it "returns the relative URL to the asset" do
|
|
83
|
-
expect(asset_url("app.js")).to match(%r{/assets/app-[A-Z0-9]{8}\.js})
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
context "when configured with base url" do
|
|
89
|
-
let(:base_url) { "https://hanami.test" }
|
|
90
|
-
|
|
91
|
-
def before_prepare
|
|
92
|
-
Hanami.app.config.assets.base_url = base_url
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
context "without manifest" do
|
|
96
|
-
it "returns the absolute URL to the asset" do
|
|
97
|
-
expect(asset_url("app.js")).to eq("#{base_url}/assets/app.js")
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
context "with manifest" do
|
|
102
|
-
before { compile_assets! }
|
|
103
|
-
|
|
104
|
-
it "returns the relative path to the asset" do
|
|
105
|
-
expect(asset_url("app.js")).to match(%r{#{base_url}/assets/app-[A-Z0-9]{8}.js})
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
context "given an asset object" do
|
|
111
|
-
it "returns the URL for the asset" do
|
|
112
|
-
asset = Hanami::Assets::Asset.new(
|
|
113
|
-
path: "/foo/bar.js",
|
|
114
|
-
base_url: Hanami.app.config.assets.base_url
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
expect(asset_url(asset)).to eq "/foo/bar.js"
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
end
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Hanami::Helpers::AssetsHelper, "#audio", :app_integration do
|
|
4
|
-
subject(:obj) {
|
|
5
|
-
helpers = described_class
|
|
6
|
-
Class.new {
|
|
7
|
-
include helpers
|
|
8
|
-
|
|
9
|
-
attr_reader :_context
|
|
10
|
-
|
|
11
|
-
def initialize(context)
|
|
12
|
-
@_context = context
|
|
13
|
-
end
|
|
14
|
-
}.new(context)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
def audio_tag(...)
|
|
18
|
-
subject.audio_tag(...)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
let(:context) { TestApp::Views::Context.new }
|
|
22
|
-
let(:root) { make_tmp_directory }
|
|
23
|
-
|
|
24
|
-
before do
|
|
25
|
-
with_directory(root) do
|
|
26
|
-
write "config/app.rb", <<~RUBY
|
|
27
|
-
module TestApp
|
|
28
|
-
class App < Hanami::App
|
|
29
|
-
config.logger.stream = StringIO.new
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
RUBY
|
|
33
|
-
|
|
34
|
-
write "app/views/context.rb", <<~RUBY
|
|
35
|
-
# auto_register: false
|
|
36
|
-
|
|
37
|
-
require "hanami/view/context"
|
|
38
|
-
|
|
39
|
-
module TestApp
|
|
40
|
-
module Views
|
|
41
|
-
class Context < Hanami::View::Context
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
RUBY
|
|
46
|
-
|
|
47
|
-
stub_assets("song.ogg", "song.pt-BR.vtt")
|
|
48
|
-
|
|
49
|
-
require "hanami/setup"
|
|
50
|
-
before_prepare if respond_to?(:before_prepare)
|
|
51
|
-
require "hanami/prepare"
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "returns an instance of HtmlBuilder" do
|
|
56
|
-
actual = audio_tag("song.ogg")
|
|
57
|
-
expect(actual).to be_instance_of(::Hanami::View::HTML::SafeString)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "renders <audio> tag" do
|
|
61
|
-
actual = audio_tag("song.ogg").to_s
|
|
62
|
-
expect(actual).to eq(%(<audio src="/assets/song.ogg"></audio>))
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "renders with html attributes" do
|
|
66
|
-
actual = audio_tag("song.ogg", autoplay: true, controls: true).to_s
|
|
67
|
-
expect(actual).to eq(%(<audio autoplay="autoplay" controls="controls" src="/assets/song.ogg"></audio>))
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "renders with fallback content" do
|
|
71
|
-
actual = audio_tag("song.ogg") do
|
|
72
|
-
"Your browser does not support the audio tag"
|
|
73
|
-
end.to_s
|
|
74
|
-
|
|
75
|
-
expect(actual).to eq(%(<audio src="/assets/song.ogg">Your browser does not support the audio tag</audio>))
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "renders with tracks" do
|
|
79
|
-
actual = audio_tag("song.ogg") do
|
|
80
|
-
tag.track kind: "captions", src: subject.asset_url("song.pt-BR.vtt"), srclang: "pt-BR", label: "Portuguese"
|
|
81
|
-
end.to_s
|
|
82
|
-
|
|
83
|
-
expect(actual).to eq(%(<audio src="/assets/song.ogg"><track kind="captions" src="/assets/song.pt-BR.vtt" srclang="pt-BR" label="Portuguese"></audio>))
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
xit "renders with sources" do
|
|
87
|
-
actual = audio do
|
|
88
|
-
tag.text "Your browser does not support the audio tag"
|
|
89
|
-
tag.source src: subject.asset_url("song.ogg"), type: "audio/ogg"
|
|
90
|
-
tag.source src: subject.asset_url("song.wav"), type: "audio/wav"
|
|
91
|
-
end.to_s
|
|
92
|
-
|
|
93
|
-
expect(actual).to eq(%(<audio>Your browser does not support the audio tag<source src="/assets/song.ogg" type="audio/ogg"><source src="/assets/song.wav" type="audio/wav"></audio>))
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it "raises an exception when no arguments" do
|
|
97
|
-
expect do
|
|
98
|
-
audio_tag
|
|
99
|
-
end.to raise_error(
|
|
100
|
-
ArgumentError,
|
|
101
|
-
"You should provide a source via `src` option or with a `source` HTML tag"
|
|
102
|
-
)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "raises an exception when no src and no block" do
|
|
106
|
-
expect do
|
|
107
|
-
audio_tag(controls: true)
|
|
108
|
-
end.to raise_error(
|
|
109
|
-
ArgumentError,
|
|
110
|
-
"You should provide a source via `src` option or with a `source` HTML tag"
|
|
111
|
-
)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
describe "cdn mode" do
|
|
115
|
-
let(:base_url) { "https://hanami.test" }
|
|
116
|
-
|
|
117
|
-
def before_prepare
|
|
118
|
-
Hanami.app.config.assets.base_url = base_url
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
it "returns absolute url for src attribute" do
|
|
122
|
-
actual = audio_tag("song.ogg").to_s
|
|
123
|
-
expect(actual).to eq(%(<audio src="#{base_url}/assets/song.ogg"></audio>))
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
private
|
|
128
|
-
|
|
129
|
-
def tag(...)
|
|
130
|
-
subject.__send__(:tag, ...)
|
|
131
|
-
end
|
|
132
|
-
end
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Hanami::Helpers::AssetsHelper, "#favicon", :app_integration do
|
|
4
|
-
subject(:obj) {
|
|
5
|
-
helpers = described_class
|
|
6
|
-
Class.new {
|
|
7
|
-
include helpers
|
|
8
|
-
|
|
9
|
-
attr_reader :_context
|
|
10
|
-
|
|
11
|
-
def initialize(context)
|
|
12
|
-
@_context = context
|
|
13
|
-
end
|
|
14
|
-
}.new(context)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
def favicon_tag(...)
|
|
18
|
-
obj.instance_eval { favicon_tag(...) }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
let(:root) { make_tmp_directory }
|
|
22
|
-
let(:context) { TestApp::Views::Context.new }
|
|
23
|
-
|
|
24
|
-
before do
|
|
25
|
-
with_directory(root) do
|
|
26
|
-
write "config/app.rb", <<~RUBY
|
|
27
|
-
module TestApp
|
|
28
|
-
class App < Hanami::App
|
|
29
|
-
config.logger.stream = StringIO.new
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
RUBY
|
|
33
|
-
|
|
34
|
-
write "app/views/context.rb", <<~RUBY
|
|
35
|
-
# auto_register: false
|
|
36
|
-
|
|
37
|
-
require "hanami/view/context"
|
|
38
|
-
|
|
39
|
-
module TestApp
|
|
40
|
-
module Views
|
|
41
|
-
class Context < Hanami::View::Context
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
RUBY
|
|
46
|
-
|
|
47
|
-
stub_assets("favicon.ico", "favicon.png")
|
|
48
|
-
|
|
49
|
-
require "hanami/setup"
|
|
50
|
-
before_prepare if respond_to?(:before_prepare)
|
|
51
|
-
require "hanami/prepare"
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "returns an instance of SafeString" do
|
|
56
|
-
actual = favicon_tag
|
|
57
|
-
expect(actual).to be_instance_of(::Hanami::View::HTML::SafeString)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "renders <link> tag" do
|
|
61
|
-
actual = favicon_tag.to_s
|
|
62
|
-
expect(actual).to eq(%(<link href="/assets/favicon.ico" rel="shortcut icon" type="image/x-icon">))
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "renders with HTML attributes" do
|
|
66
|
-
actual = favicon_tag("favicon.png", rel: "icon", type: "image/png").to_s
|
|
67
|
-
expect(actual).to eq(%(<link href="/assets/favicon.png" rel="icon" type="image/png">))
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "ignores href passed as an option" do
|
|
71
|
-
actual = favicon_tag("favicon.png", href: "wrong").to_s
|
|
72
|
-
expect(actual).to eq(%(<link href="/assets/favicon.png" rel="shortcut icon" type="image/x-icon">))
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
describe "cdn mode" do
|
|
76
|
-
let(:base_url) { "https://hanami.test" }
|
|
77
|
-
|
|
78
|
-
def before_prepare
|
|
79
|
-
Hanami.app.config.assets.base_url = "https://hanami.test"
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it "returns absolute url for href attribute" do
|
|
83
|
-
actual = favicon_tag.to_s
|
|
84
|
-
expect(actual).to eq(%(<link href="#{base_url}/assets/favicon.ico" rel="shortcut icon" type="image/x-icon">))
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Hanami::Helpers::AssetsHelper, "#image", :app_integration do
|
|
4
|
-
subject(:obj) {
|
|
5
|
-
helpers = described_class
|
|
6
|
-
Class.new {
|
|
7
|
-
include helpers
|
|
8
|
-
|
|
9
|
-
attr_reader :_context
|
|
10
|
-
|
|
11
|
-
def initialize(context)
|
|
12
|
-
@_context = context
|
|
13
|
-
end
|
|
14
|
-
}.new(context)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
def image_tag(...)
|
|
18
|
-
subject.image_tag(...)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
let(:root) { make_tmp_directory }
|
|
22
|
-
let(:context) { TestApp::Views::Context.new }
|
|
23
|
-
|
|
24
|
-
before do
|
|
25
|
-
with_directory(root) do
|
|
26
|
-
write "config/app.rb", <<~RUBY
|
|
27
|
-
module TestApp
|
|
28
|
-
class App < Hanami::App
|
|
29
|
-
config.logger.stream = StringIO.new
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
RUBY
|
|
33
|
-
|
|
34
|
-
write "app/views/context.rb", <<~RUBY
|
|
35
|
-
# auto_register: false
|
|
36
|
-
|
|
37
|
-
require "hanami/view/context"
|
|
38
|
-
|
|
39
|
-
module TestApp
|
|
40
|
-
module Views
|
|
41
|
-
class Context < Hanami::View::Context
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
RUBY
|
|
46
|
-
|
|
47
|
-
stub_assets("application.jpg")
|
|
48
|
-
|
|
49
|
-
require "hanami/setup"
|
|
50
|
-
before_prepare if respond_to?(:before_prepare)
|
|
51
|
-
require "hanami/prepare"
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "returns an instance of HtmlBuilder" do
|
|
56
|
-
actual = image_tag("application.jpg")
|
|
57
|
-
expect(actual).to be_instance_of(::Hanami::View::HTML::SafeString)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "renders an <img> tag" do
|
|
61
|
-
actual = image_tag("application.jpg").to_s
|
|
62
|
-
expect(actual).to eq(%(<img src="/assets/application.jpg" alt="Application">))
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "custom alt" do
|
|
66
|
-
actual = image_tag("application.jpg", alt: "My Alt").to_s
|
|
67
|
-
expect(actual).to eq(%(<img src="/assets/application.jpg" alt="My Alt">))
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "custom data attribute" do
|
|
71
|
-
actual = image_tag("application.jpg", "data-user-id" => 5).to_s
|
|
72
|
-
expect(actual).to eq(%(<img src="/assets/application.jpg" alt="Application" data-user-id="5">))
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "ignores src passed as an option" do
|
|
76
|
-
actual = image_tag("application.jpg", src: "wrong").to_s
|
|
77
|
-
expect(actual).to eq(%(<img src="/assets/application.jpg" alt="Application">))
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
describe "cdn mode" do
|
|
81
|
-
let(:base_url) { "https://hanami.test" }
|
|
82
|
-
|
|
83
|
-
def before_prepare
|
|
84
|
-
Hanami.app.config.assets.base_url = "https://hanami.test"
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "returns absolute url for src attribute" do
|
|
88
|
-
actual = image_tag("application.jpg").to_s
|
|
89
|
-
expect(actual).to eq(%(<img src="#{base_url}/assets/application.jpg" alt="Application">))
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|