hanami-view 2.0.0.alpha3 → 2.0.0.alpha5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6b6dc01adb32ad3baabc7a15012119e8814de8ec999c4b5da2009204c3b047c
4
- data.tar.gz: 8ef681f6101b085dec6e03f6de0815dfa55d8cbd91e960bf0144e4a46da5cce9
3
+ metadata.gz: ec11d28fb1ab17f2de3bfa384fce768648a6975f6f5261795b239069733a5df2
4
+ data.tar.gz: 6f631fa7bdd6528d406534f074ec7df1823e46a4ae692a0c4b83e6c8ba30efbf
5
5
  SHA512:
6
- metadata.gz: b5704c147558d2a0e3e86d59f3b665ee65265a9398584b1d3478970551d9a022551ea04420444622c2c4967ab3406d29ea9dab7c13462207364ea985aa4af723
7
- data.tar.gz: 5909511de76e1daf91a375c5947103040c2ec40208ea52882771204249cc2d4aef23d2ceaa8dac24cc960dbba978f3e4c6c08fac52118673b9c22580571f10fb
6
+ metadata.gz: 6ca038a05ffb5361ca9e61820af0487498f3a6dee0842f33f5f51577127e36fd6f97eea13df0984a64cb66d093a0c331a943736856589062310f1b0c2d40eada
7
+ data.tar.gz: 3468190981d001cbb87618779abae17ce19700cb7855ac70db09db5895f23cea4056ea580aa967b7a59f1168d6801fc93129184aa4afcfb871682e1386feb0ed
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Hanami::View
2
2
  View layer for Hanami
3
3
 
4
+ ## v2.0.0.alpha5 - 2022-01-12
5
+ ### Added
6
+ - [Marc Busqué] Automatically provide access to Hanami application routes helper as `routes` in default application view context (`Hanami::View::ApplicationContext`)
7
+
4
8
  ## v2.0.0.alpha3 - 2021-11-09
5
9
  ### Added
6
10
  - [Pablo Vicente] Raise `LayoutNotFoundError` exception with friendlier, more specific error message when layouts cannot be found
@@ -2,33 +2,55 @@
2
2
 
3
3
  module Hanami
4
4
  class View
5
- module ApplicationContext
6
- def initialize(inflector: Hanami.application.inflector, **options)
7
- @inflector = inflector
8
- super
9
- end
5
+ class ApplicationContext < Module
6
+ attr_reader :provider
7
+ attr_reader :application
10
8
 
11
- def inflector
12
- @inflector
9
+ def initialize(provider)
10
+ @provider = provider
11
+ @application = provider.respond_to?(:application) ? provider.application : Hanami.application
13
12
  end
14
13
 
15
- def request
16
- _options.fetch(:request)
14
+ def included(context_class)
15
+ define_initialize
16
+ context_class.include(InstanceMethods)
17
17
  end
18
18
 
19
- def session
20
- request.session
21
- end
19
+ private
22
20
 
23
- def flash
24
- response.flash
21
+ def define_initialize
22
+ inflector = application.inflector
23
+ routes = application[:routes_helper] if application.key?(:routes_helper)
24
+
25
+ define_method :initialize do |**options|
26
+ @inflector = options[:inflector] || inflector
27
+ @routes = options[:routes] || routes
28
+ super(**options)
29
+ end
25
30
  end
26
31
 
27
- private
32
+ module InstanceMethods
33
+ attr_reader :inflector
34
+ attr_reader :routes
35
+
36
+ def request
37
+ _options.fetch(:request)
38
+ end
39
+
40
+ def session
41
+ request.session
42
+ end
43
+
44
+ def flash
45
+ response.flash
46
+ end
47
+
48
+ private
28
49
 
29
- # TODO: create `Request#flash` so we no longer need the `response`
30
- def response
31
- _options.fetch(:response)
50
+ # TODO: create `Request#flash` so we no longer need the `response`
51
+ def response
52
+ _options.fetch(:response)
53
+ end
32
54
  end
33
55
  end
34
56
  end
@@ -23,8 +23,9 @@ module Hanami
23
23
  super
24
24
 
25
25
  # When inheriting within an Hanami app, add application context behavior
26
- if application_provider(subclass)
27
- subclass.include ApplicationContext
26
+ provider = application_provider(subclass)
27
+ if provider
28
+ subclass.include ApplicationContext.new(provider)
28
29
  end
29
30
  end
30
31
 
@@ -3,6 +3,6 @@
3
3
  module Hanami
4
4
  class View
5
5
  # @api private
6
- VERSION = "2.0.0.alpha3"
6
+ VERSION = "2.0.0.alpha5"
7
7
  end
8
8
  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.alpha3
4
+ version: 2.0.0.alpha5
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: 2021-11-09 00:00:00.000000000 Z
12
+ date: 2022-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby