hanami-view 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +7 -0
- data/lib/hanami/view/rendering.rb +1 -0
- data/lib/hanami/view/rendering/layout_scope.rb +12 -7
- data/lib/hanami/view/rendering/null_template.rb +1 -1
- data/lib/hanami/view/rendering/options.rb +25 -0
- data/lib/hanami/view/rendering/partial_finder.rb +0 -6
- data/lib/hanami/view/rendering/scope.rb +9 -1
- data/lib/hanami/view/rendering/subscope.rb +56 -0
- data/lib/hanami/view/rendering/template.rb +1 -1
- data/lib/hanami/view/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 975282c7d30e5a6826be9afccdebf3f8265f9407eb872849316141ffa6c1ef07
|
4
|
+
data.tar.gz: b8136cee7472c868d96ab6082a66410b53ef32b1f35bedcfd293c3fe1af12f3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8cc401697f3e7cfcdb8f2b37d9ec8cdfdbb3413a274dd7e5e3eb471ebb2a1ca630bae7eab8fce3dd6c429fc922fff35983b6e158ff6069d279257de1c80eb39
|
7
|
+
data.tar.gz: 623f66b95073220a3a21d9569973cc749618345d4703917e3decae0b245ff8f8f232c4110cfc6bc6a4895bee63a964b282835cd7de0c8136f7bd4208b1983473
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# Hanami::View
|
2
2
|
View layer for Hanami
|
3
3
|
|
4
|
+
## v1.1.1 - 2018-02-27
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Official support for Ruby: MRI 2.5
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- [Alfonso Uceda] Ensure that `exposures` are properly overwritten for partials when `locals:` option is used
|
10
|
+
|
4
11
|
## v1.1.0 - 2017-10-25
|
5
12
|
|
6
13
|
## v1.1.0.rc1 - 2017-10-16
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'hanami/view/rendering/null_local'
|
2
|
+
require 'hanami/view/rendering/options'
|
2
3
|
require 'hanami/utils/escape'
|
3
4
|
|
4
5
|
module Hanami
|
@@ -125,7 +126,7 @@ module Hanami
|
|
125
126
|
#
|
126
127
|
# @since 0.1.0
|
127
128
|
def locals
|
128
|
-
@locals || @scope.locals
|
129
|
+
Utils::Hash.deep_dup(@locals || @scope.locals)
|
129
130
|
end
|
130
131
|
|
131
132
|
# It tries to invoke a method for the view or a local for the given key.
|
@@ -206,6 +207,7 @@ module Hanami
|
|
206
207
|
end
|
207
208
|
|
208
209
|
protected
|
210
|
+
|
209
211
|
# Forward all the missing methods to the view scope or to the layout.
|
210
212
|
#
|
211
213
|
# @api private
|
@@ -228,9 +230,11 @@ module Hanami
|
|
228
230
|
# that we want to be frozen in the future
|
229
231
|
#
|
230
232
|
# See https://github.com/hanami/view/issues/130#issuecomment-319326236
|
231
|
-
if @scope.respond_to?(m, true)
|
233
|
+
if @scope.respond_to?(m, true) && @scope.locals.has_key?(m) && layout.respond_to?(m, true)
|
234
|
+
layout.__send__(m, *args, &blk)
|
235
|
+
elsif @scope.respond_to?(m, true)
|
232
236
|
@scope.__send__(m, *args, &blk)
|
233
|
-
elsif layout.respond_to?(m)
|
237
|
+
elsif layout.respond_to?(m, true)
|
234
238
|
layout.__send__(m, *args, &blk)
|
235
239
|
else
|
236
240
|
::Hanami::View::Escape.html(super)
|
@@ -249,13 +253,14 @@ module Hanami
|
|
249
253
|
end
|
250
254
|
|
251
255
|
private
|
256
|
+
|
252
257
|
# @api private
|
253
258
|
def _options(options)
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
opts[:locals].merge!(options.fetch(:locals){ ::Hash.new })
|
259
|
+
current_locals = locals.reject do |key, _|
|
260
|
+
@scope.respond_to?(key, true) &&
|
261
|
+
(layout.respond_to?(key, true) || @scope.view.respond_to?(:name, true))
|
258
262
|
end
|
263
|
+
Options.build(options, current_locals, format)
|
259
264
|
end
|
260
265
|
|
261
266
|
# @since 0.4.2
|
@@ -7,7 +7,7 @@ module Hanami
|
|
7
7
|
#
|
8
8
|
# A common scenario is for non-html requests.
|
9
9
|
# Usually we have a template for the application layout
|
10
|
-
# (eg `templates/application.html.erb`), but we don't use to have the
|
10
|
+
# (eg `templates/application.html.erb`), but we don't use to have the
|
11
11
|
# template for JSON requests (eg `templates/application.json.erb`).
|
12
12
|
# Because most of the times, we only return the output of the view.
|
13
13
|
#
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hanami/utils/hash"
|
4
|
+
|
5
|
+
module Hanami
|
6
|
+
module View
|
7
|
+
module Rendering
|
8
|
+
# Rendering options
|
9
|
+
#
|
10
|
+
# @since 1.1.1
|
11
|
+
# @api private
|
12
|
+
class Options
|
13
|
+
# @since 1.1.1
|
14
|
+
# @api private
|
15
|
+
def self.build(options, locals, format)
|
16
|
+
Utils::Hash.deep_dup(options).tap do |opts|
|
17
|
+
opts[:format] = format
|
18
|
+
opts[:locals] = locals
|
19
|
+
opts[:locals].merge!(options.fetch(:locals) { ::Hash.new }).merge!(format: format)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -47,12 +47,6 @@ module Hanami
|
|
47
47
|
[view_template_dir, template_name].join(separator)
|
48
48
|
end
|
49
49
|
|
50
|
-
# @since 0.4.3
|
51
|
-
# @api private
|
52
|
-
def partial_template_under_view_path
|
53
|
-
_find(view_template_dir).first
|
54
|
-
end
|
55
|
-
|
56
50
|
# @since 0.4.3
|
57
51
|
# @api private
|
58
52
|
def view_template_dir
|
@@ -6,7 +6,7 @@ require 'hanami/view/rendering/partial'
|
|
6
6
|
module Hanami
|
7
7
|
module View
|
8
8
|
module Rendering
|
9
|
-
# Rendering scope
|
9
|
+
# Rendering view scope
|
10
10
|
#
|
11
11
|
# @since 0.1.0
|
12
12
|
#
|
@@ -66,6 +66,7 @@ module Hanami
|
|
66
66
|
end
|
67
67
|
|
68
68
|
protected
|
69
|
+
|
69
70
|
# @api private
|
70
71
|
def method_missing(m, *args, &block)
|
71
72
|
::Hanami::View::Escape.html(
|
@@ -85,6 +86,13 @@ module Hanami
|
|
85
86
|
|
86
87
|
private
|
87
88
|
|
89
|
+
# @since 1.1.1
|
90
|
+
# @api private
|
91
|
+
def _options(options)
|
92
|
+
current_locals = locals.reject { |key, _| @view.respond_to?(key) }
|
93
|
+
Options.build(options, current_locals, format)
|
94
|
+
end
|
95
|
+
|
88
96
|
# @since 0.4.2
|
89
97
|
# @api private
|
90
98
|
def layout
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hanami/view/rendering/scope"
|
4
|
+
require "hanami/view/rendering/options"
|
5
|
+
|
6
|
+
module Hanami
|
7
|
+
module View
|
8
|
+
module Rendering
|
9
|
+
# Rendering subscope
|
10
|
+
#
|
11
|
+
# @since 1.1.1
|
12
|
+
# @api private
|
13
|
+
#
|
14
|
+
# @see Hanami::View::Rendering::Scope
|
15
|
+
class Subscope < Scope
|
16
|
+
# Implements "respond to" logic
|
17
|
+
#
|
18
|
+
# @return [TrueClass,FalseClass]
|
19
|
+
#
|
20
|
+
# @since 1.1.1
|
21
|
+
# @api private
|
22
|
+
#
|
23
|
+
# @see http://ruby-doc.org/core/Object.html#method-i-respond_to_missing-3F
|
24
|
+
def respond_to_missing?(m, _include_all)
|
25
|
+
@locals.key?(m)
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
# @since 1.1.1
|
31
|
+
# @api private
|
32
|
+
def method_missing(m, *args, &block)
|
33
|
+
::Hanami::View::Escape.html(
|
34
|
+
# FIXME: this isn't compatible with Hanami 2.0, as it extends a view
|
35
|
+
# that we want to be frozen in the future
|
36
|
+
#
|
37
|
+
# See https://github.com/hanami/view/issues/130#issuecomment-319326236
|
38
|
+
if @locals.key?(m)
|
39
|
+
@locals[m]
|
40
|
+
else
|
41
|
+
super
|
42
|
+
end
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# @since 1.1.1
|
49
|
+
# @api private
|
50
|
+
def _options(options)
|
51
|
+
Options.build(options, locals, format)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/hanami/view/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -113,12 +113,14 @@ files:
|
|
113
113
|
- lib/hanami/view/rendering/null_layout.rb
|
114
114
|
- lib/hanami/view/rendering/null_local.rb
|
115
115
|
- lib/hanami/view/rendering/null_template.rb
|
116
|
+
- lib/hanami/view/rendering/options.rb
|
116
117
|
- lib/hanami/view/rendering/partial.rb
|
117
118
|
- lib/hanami/view/rendering/partial_file.rb
|
118
119
|
- lib/hanami/view/rendering/partial_finder.rb
|
119
120
|
- lib/hanami/view/rendering/partial_templates_finder.rb
|
120
121
|
- lib/hanami/view/rendering/registry.rb
|
121
122
|
- lib/hanami/view/rendering/scope.rb
|
123
|
+
- lib/hanami/view/rendering/subscope.rb
|
122
124
|
- lib/hanami/view/rendering/template.rb
|
123
125
|
- lib/hanami/view/rendering/template_finder.rb
|
124
126
|
- lib/hanami/view/rendering/template_name.rb
|
@@ -146,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
148
|
version: '0'
|
147
149
|
requirements: []
|
148
150
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.
|
151
|
+
rubygems_version: 2.7.5
|
150
152
|
signing_key:
|
151
153
|
specification_version: 4
|
152
154
|
summary: View layer for Hanami, with a separation between views and templates
|