hanami-view 2.0.0.alpha6 → 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 +13 -0
- data/lib/hanami/view/application_configuration.rb +2 -2
- data/lib/hanami/view/application_context.rb +41 -0
- data/lib/hanami/view/errors.rb +13 -0
- data/lib/hanami/view/version.rb +1 -1
- data/lib/hanami/view.rb +4 -3
- metadata +2 -2
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,19 @@
|
|
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
|
+
|
4
17
|
## v2.0.0.alpha6 - 2022-02-10
|
5
18
|
### Added
|
6
19
|
- [Luca Guidi] Official support for Ruby: MRI 3.0 and 3.1
|
@@ -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,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "hanami/view/errors"
|
4
|
+
|
3
5
|
module Hanami
|
4
6
|
class View
|
5
7
|
class ApplicationContext < Module
|
@@ -20,11 +22,15 @@ module Hanami
|
|
20
22
|
|
21
23
|
def define_initialize
|
22
24
|
inflector = application.inflector
|
25
|
+
settings = application[:settings] if application.key?(:settings)
|
23
26
|
routes = application[:routes_helper] if application.key?(:routes_helper)
|
27
|
+
assets = application[:assets] if application.key?(:assets)
|
24
28
|
|
25
29
|
define_method :initialize do |**options|
|
26
30
|
@inflector = options[:inflector] || inflector
|
31
|
+
@settings = options[:settings] || settings
|
27
32
|
@routes = options[:routes] || routes
|
33
|
+
@assets = options[:assets] || assets
|
28
34
|
super(**options)
|
29
35
|
end
|
30
36
|
end
|
@@ -32,6 +38,36 @@ module Hanami
|
|
32
38
|
module InstanceMethods
|
33
39
|
attr_reader :inflector
|
34
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
|
35
71
|
|
36
72
|
def request
|
37
73
|
_options.fetch(:request)
|
@@ -45,6 +81,11 @@ module Hanami
|
|
45
81
|
response.flash
|
46
82
|
end
|
47
83
|
|
84
|
+
def assets
|
85
|
+
@assets or
|
86
|
+
raise Hanami::View::MissingProviderError.new("hanami-assets")
|
87
|
+
end
|
88
|
+
|
48
89
|
private
|
49
90
|
|
50
91
|
# TODO: create `Request#flash` so we no longer need the `response`
|
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: 2022-
|
12
|
+
date: 2022-03-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|