hanami-view 2.0.0.alpha3 → 2.0.0.alpha7
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 +24 -0
- data/README.md +1 -1
- data/hanami-view.gemspec +2 -1
- data/lib/hanami/view/application_configuration.rb +2 -2
- data/lib/hanami/view/application_context.rb +81 -18
- data/lib/hanami/view/context.rb +3 -2
- data/lib/hanami/view/errors.rb +13 -0
- data/lib/hanami/view/version.rb +1 -1
- data/lib/hanami/view.rb +4 -3
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f1426ce046073c71aeffe9a171b0b0343704686bb92b75046526858ca82f9e8
|
4
|
+
data.tar.gz: 14a7f4078a42e3abd63e5411da1a2fa4b19fdfeaf405184c9c1f11bda7e78210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a0f2cca15e556ee2c93396f730c6b68d3a7799ec0c2cbebc574b5c73c0315d2192c89ad8d85ad1b273d03b80132b3acf2348befab3c7f22fff28b1ef7e82667
|
7
|
+
data.tar.gz: 5032a5b1c0891a369bf518cf12d0baad00dcfb688ac41625dd61818b635b8ef6dea498a574c9558249a0beb2cd905553b253bb5a0a8b82245030664d0f7bd629
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,30 @@
|
|
1
1
|
# Hanami::View
|
2
2
|
View layer for Hanami
|
3
3
|
|
4
|
+
## v2.0.0.alpha7 - 2022-03-08
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- [Luca Guidi] Automatically inject the app's `settings` and `assets` components (if present) into instances of `Hanami::View::ApplicationContext`
|
8
|
+
- [Luca Guidi] Temporarily added to `Hanami::View::ApplicationContext` the `#content_for`, `#current_path` `#csrf_token` helpers, ported from the hanami-2-application-template. Some of those helpers will be moved to `hanami-helpers` gem in a later release.
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
- [Sean Collins] For views within an Hanami application, changed default location for templates from "web/templates" to "templates"
|
12
|
+
- [Luca Guidi] For views within an Hanami application, the default `part_namespace` is now `"view/parts"` (previously `"views/parts"`)
|
13
|
+
|
14
|
+
## Fixed
|
15
|
+
- [Luca Guidi] Application-level configuration is now applied to `Hanami::View` subclasses, no matter how deep their inheritance chain (e.g. app base view -> slice base view -> slice view)
|
16
|
+
|
17
|
+
## v2.0.0.alpha6 - 2022-02-10
|
18
|
+
### Added
|
19
|
+
- [Luca Guidi] Official support for Ruby: MRI 3.0 and 3.1
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
- [Luca Guidi] Drop support for Ruby: MRI 2.3, 2.4, 2.5, 2.6, and 2.7.
|
23
|
+
|
24
|
+
## v2.0.0.alpha5 - 2022-01-12
|
25
|
+
### Added
|
26
|
+
- [Marc Busqué] Automatically provide access to Hanami application routes helper as `routes` in default application view context (`Hanami::View::ApplicationContext`)
|
27
|
+
|
4
28
|
## v2.0.0.alpha3 - 2021-11-09
|
5
29
|
### Added
|
6
30
|
- [Pablo Vicente] Raise `LayoutNotFoundError` exception with friendlier, more specific error message when layouts cannot be found
|
data/README.md
CHANGED
data/hanami-view.gemspec
CHANGED
@@ -18,13 +18,14 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.bindir = 'bin'
|
19
19
|
spec.executables = []
|
20
20
|
spec.require_paths = ['lib']
|
21
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
21
22
|
|
22
23
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
23
24
|
spec.metadata['changelog_uri'] = 'https://github.com/hanami/view/blob/main/CHANGELOG.md'
|
24
25
|
spec.metadata['source_code_uri'] = 'https://github.com/hanami/view'
|
25
26
|
spec.metadata['bug_tracker_uri'] = 'https://github.com/hanami/view/issues'
|
26
27
|
|
27
|
-
spec.required_ruby_version = ">=
|
28
|
+
spec.required_ruby_version = ">= 3.0"
|
28
29
|
|
29
30
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
30
31
|
spec.add_runtime_dependency "dry-configurable", "~> 0.13", ">= 0.13.0"
|
@@ -8,7 +8,7 @@ module Hanami
|
|
8
8
|
class ApplicationConfiguration
|
9
9
|
include Dry::Configurable
|
10
10
|
|
11
|
-
setting :parts_path, default: "
|
11
|
+
setting :parts_path, default: "view/parts"
|
12
12
|
|
13
13
|
def initialize(*)
|
14
14
|
super
|
@@ -41,7 +41,7 @@ module Hanami
|
|
41
41
|
attr_reader :base_config
|
42
42
|
|
43
43
|
def configure_defaults
|
44
|
-
self.paths = ["
|
44
|
+
self.paths = ["templates"]
|
45
45
|
self.template_inference_base = "views"
|
46
46
|
self.layout = "application"
|
47
47
|
end
|
@@ -1,34 +1,97 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "hanami/view/errors"
|
4
|
+
|
3
5
|
module Hanami
|
4
6
|
class View
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
super
|
9
|
-
end
|
7
|
+
class ApplicationContext < Module
|
8
|
+
attr_reader :provider
|
9
|
+
attr_reader :application
|
10
10
|
|
11
|
-
def
|
12
|
-
@
|
11
|
+
def initialize(provider)
|
12
|
+
@provider = provider
|
13
|
+
@application = provider.respond_to?(:application) ? provider.application : Hanami.application
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
-
|
16
|
+
def included(context_class)
|
17
|
+
define_initialize
|
18
|
+
context_class.include(InstanceMethods)
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
private
|
22
|
+
|
23
|
+
def define_initialize
|
24
|
+
inflector = application.inflector
|
25
|
+
settings = application[:settings] if application.key?(:settings)
|
26
|
+
routes = application[:routes_helper] if application.key?(:routes_helper)
|
27
|
+
assets = application[:assets] if application.key?(:assets)
|
22
28
|
|
23
|
-
|
24
|
-
|
29
|
+
define_method :initialize do |**options|
|
30
|
+
@inflector = options[:inflector] || inflector
|
31
|
+
@settings = options[:settings] || settings
|
32
|
+
@routes = options[:routes] || routes
|
33
|
+
@assets = options[:assets] || assets
|
34
|
+
super(**options)
|
35
|
+
end
|
25
36
|
end
|
26
37
|
|
27
|
-
|
38
|
+
module InstanceMethods
|
39
|
+
attr_reader :inflector
|
40
|
+
attr_reader :routes
|
41
|
+
attr_reader :settings
|
42
|
+
|
43
|
+
def initialize(**args)
|
44
|
+
defaults = {content: {}}
|
45
|
+
|
46
|
+
super(**defaults.merge(args))
|
47
|
+
end
|
48
|
+
|
49
|
+
def content_for(key, value = nil, &block)
|
50
|
+
content = _options[:content]
|
51
|
+
output = nil
|
52
|
+
|
53
|
+
if block
|
54
|
+
content[key] = yield
|
55
|
+
elsif value
|
56
|
+
content[key] = value
|
57
|
+
else
|
58
|
+
output = content[key]
|
59
|
+
end
|
60
|
+
|
61
|
+
output
|
62
|
+
end
|
63
|
+
|
64
|
+
def current_path
|
65
|
+
request.fullpath
|
66
|
+
end
|
67
|
+
|
68
|
+
def csrf_token
|
69
|
+
request.session[Hanami::Action::CSRFProtection::CSRF_TOKEN]
|
70
|
+
end
|
71
|
+
|
72
|
+
def request
|
73
|
+
_options.fetch(:request)
|
74
|
+
end
|
75
|
+
|
76
|
+
def session
|
77
|
+
request.session
|
78
|
+
end
|
79
|
+
|
80
|
+
def flash
|
81
|
+
response.flash
|
82
|
+
end
|
83
|
+
|
84
|
+
def assets
|
85
|
+
@assets or
|
86
|
+
raise Hanami::View::MissingProviderError.new("hanami-assets")
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
28
90
|
|
29
|
-
|
30
|
-
|
31
|
-
|
91
|
+
# TODO: create `Request#flash` so we no longer need the `response`
|
92
|
+
def response
|
93
|
+
_options.fetch(:response)
|
94
|
+
end
|
32
95
|
end
|
33
96
|
end
|
34
97
|
end
|
data/lib/hanami/view/context.rb
CHANGED
@@ -23,8 +23,9 @@ module Hanami
|
|
23
23
|
super
|
24
24
|
|
25
25
|
# When inheriting within an Hanami app, add application context behavior
|
26
|
-
|
27
|
-
|
26
|
+
provider = application_provider(subclass)
|
27
|
+
if provider
|
28
|
+
subclass.include ApplicationContext.new(provider)
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
data/lib/hanami/view/errors.rb
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
module Hanami
|
4
4
|
class View
|
5
|
+
# @since 2.0.0
|
6
|
+
# @api public
|
7
|
+
class Error < StandardError
|
8
|
+
end
|
9
|
+
|
5
10
|
# Error raised when critical settings are not configured
|
6
11
|
#
|
7
12
|
# @api private
|
@@ -40,5 +45,13 @@ module Hanami
|
|
40
45
|
super(msg)
|
41
46
|
end
|
42
47
|
end
|
48
|
+
|
49
|
+
# @since 2.0.0
|
50
|
+
# @api public
|
51
|
+
class MissingProviderError < Error
|
52
|
+
def initialize(provider)
|
53
|
+
super("#{provider.inspect} is missing")
|
54
|
+
end
|
55
|
+
end
|
43
56
|
end
|
44
57
|
end
|
data/lib/hanami/view/version.rb
CHANGED
data/lib/hanami/view.rb
CHANGED
@@ -235,9 +235,10 @@ module Hanami
|
|
235
235
|
def self.inherited(subclass)
|
236
236
|
super
|
237
237
|
|
238
|
-
#
|
239
|
-
# the
|
240
|
-
|
238
|
+
# When inheriting within an Hanami app, and the application provider has
|
239
|
+
# changed from the superclass, (re-)configure the action for the provider,
|
240
|
+
# i.e. for the slice and/or the application itself
|
241
|
+
if (provider = application_provider(subclass)) && provider != application_provider(subclass.superclass)
|
241
242
|
subclass.include ApplicationView.new(provider)
|
242
243
|
end
|
243
244
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.alpha7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Riley
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-03-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|
@@ -184,6 +184,7 @@ homepage: https://dry-rb.org/gems/hanami-view
|
|
184
184
|
licenses:
|
185
185
|
- MIT
|
186
186
|
metadata:
|
187
|
+
rubygems_mfa_required: 'true'
|
187
188
|
allowed_push_host: https://rubygems.org
|
188
189
|
changelog_uri: https://github.com/hanami/view/blob/main/CHANGELOG.md
|
189
190
|
source_code_uri: https://github.com/hanami/view
|
@@ -196,14 +197,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
197
|
requirements:
|
197
198
|
- - ">="
|
198
199
|
- !ruby/object:Gem::Version
|
199
|
-
version:
|
200
|
+
version: '3.0'
|
200
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
202
|
requirements:
|
202
203
|
- - ">"
|
203
204
|
- !ruby/object:Gem::Version
|
204
205
|
version: 1.3.1
|
205
206
|
requirements: []
|
206
|
-
rubygems_version: 3.
|
207
|
+
rubygems_version: 3.3.3
|
207
208
|
signing_key:
|
208
209
|
specification_version: 4
|
209
210
|
summary: A complete, standalone view rendering system that gives you everything you
|