hanami-view 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/hanami-view.gemspec +3 -3
- data/lib/hanami/view/errors.rb +17 -2
- data/lib/hanami/view/rendering/layout_scope.rb +16 -1
- data/lib/hanami/view/rendering/scope.rb +10 -2
- data/lib/hanami/view/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3f3b5a91fabf790905218d179350b9ca5b09ea5
|
4
|
+
data.tar.gz: 90708fec73255ef891fa0210527ea32bf49c82a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e414c7c8df49dfa4e33ff5e694baa9408ac8336aff315f631044ed8f86300dfbad8fdf066bed6e8227ba96d77c2e6e46cf20600d0cc7480e56ed83e55429f1f3
|
7
|
+
data.tar.gz: b21512ad851b40cd8dca788ff9c93ae98f40eec8a1087ee855e2c8858324543f45d3c403872b061f1c772f1a42d10332830f66f43607c3a2da7fec83b111f0b9
|
data/CHANGELOG.md
CHANGED
data/hanami-view.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_runtime_dependency 'tilt', '~> 2.0', '>= 2.0.1'
|
23
23
|
spec.add_runtime_dependency 'hanami-utils', '~> 1.0'
|
24
24
|
|
25
|
-
spec.add_development_dependency 'bundler',
|
26
|
-
spec.add_development_dependency '
|
27
|
-
spec.add_development_dependency 'rake',
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
27
|
+
spec.add_development_dependency 'rake', '~> 11'
|
28
28
|
end
|
data/lib/hanami/view/errors.rb
CHANGED
@@ -26,7 +26,7 @@ module Hanami
|
|
26
26
|
|
27
27
|
# Missing format error
|
28
28
|
#
|
29
|
-
# This is raised at the runtime when rendering context lacks
|
29
|
+
# This is raised at the runtime when rendering context lacks the :format
|
30
30
|
# key.
|
31
31
|
#
|
32
32
|
# @since 0.1.0
|
@@ -37,7 +37,7 @@ module Hanami
|
|
37
37
|
|
38
38
|
# Missing template layout error
|
39
39
|
#
|
40
|
-
# This is raised at the runtime when Hanami::Layout cannot find
|
40
|
+
# This is raised at the runtime when Hanami::Layout cannot find its template.
|
41
41
|
#
|
42
42
|
# @since 0.5.0
|
43
43
|
class MissingTemplateLayoutError < Error
|
@@ -47,5 +47,20 @@ module Hanami
|
|
47
47
|
super("Can't find layout template '#{ template }'")
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
# Unknown or missing render type
|
52
|
+
#
|
53
|
+
# This is raised at the runtime when Hanami::Layout doesn't recognize the render type.
|
54
|
+
#
|
55
|
+
# @since X.X.X
|
56
|
+
class UnknownOrMissingRenderTypeLayoutError < Error
|
57
|
+
# @since X.X.X
|
58
|
+
# @api private
|
59
|
+
def initialize(known_types, supplied_options)
|
60
|
+
known_types_list = known_types.map{|t| "':#{t}'"}.join(', ')
|
61
|
+
supplied_options_list = supplied_options.keys.map{|t| "':#{t}'"}.join(', ')
|
62
|
+
super("Calls to `render` in a layout must include one of #{known_types_list}. Found #{supplied_options_list}.")
|
63
|
+
end
|
64
|
+
end
|
50
65
|
end
|
51
66
|
end
|
@@ -4,6 +4,14 @@ require 'hanami/utils/escape'
|
|
4
4
|
module Hanami
|
5
5
|
module View
|
6
6
|
module Rendering
|
7
|
+
|
8
|
+
# List of render types that exactly one of must be included when calling `#render`.
|
9
|
+
# For example, when calling `<%= render something: 'my_thing', locals: {} %>`,
|
10
|
+
# 'something' must be one of the values listed here.
|
11
|
+
#
|
12
|
+
# @since X.X.X
|
13
|
+
KNOWN_RENDER_TYPES = [:partial, :template]
|
14
|
+
|
7
15
|
# Scope for layout rendering
|
8
16
|
#
|
9
17
|
# @since 0.1.0
|
@@ -87,6 +95,9 @@ module Hanami
|
|
87
95
|
# #
|
88
96
|
# # `user` will be available in the scope of the sidebar rendering
|
89
97
|
def render(options)
|
98
|
+
if !KNOWN_RENDER_TYPES.any?{|render_type| options[render_type]}
|
99
|
+
::Kernel.raise UnknownOrMissingRenderTypeLayoutError.new(KNOWN_RENDER_TYPES, options)
|
100
|
+
end
|
90
101
|
renderer(options).render
|
91
102
|
end
|
92
103
|
|
@@ -213,7 +224,11 @@ module Hanami
|
|
213
224
|
# # `article` will be looked up in the view scope first.
|
214
225
|
# # If not found, it will be searched within the layout.
|
215
226
|
def method_missing(m, *args, &blk)
|
216
|
-
|
227
|
+
# FIXME: this isn't compatible with Hanami 2.0, as it extends a view
|
228
|
+
# that we want to be frozen in the future
|
229
|
+
#
|
230
|
+
# See https://github.com/hanami/view/issues/130#issuecomment-319326236
|
231
|
+
if @scope.respond_to?(m, true)
|
217
232
|
@scope.__send__(m, *args, &blk)
|
218
233
|
elsif layout.respond_to?(m)
|
219
234
|
layout.__send__(m, *args, &blk)
|
@@ -57,7 +57,11 @@ module Hanami
|
|
57
57
|
#
|
58
58
|
# @see http://ruby-doc.org/core/Object.html#method-i-respond_to_missing-3F
|
59
59
|
def respond_to_missing?(m, include_all)
|
60
|
-
|
60
|
+
# FIXME: this isn't compatible with Hanami 2.0, as it extends a view
|
61
|
+
# that we want to be frozen in the future
|
62
|
+
#
|
63
|
+
# See https://github.com/hanami/view/issues/130#issuecomment-319326236
|
64
|
+
@view.respond_to?(m, include_all) ||
|
61
65
|
@locals.key?(m)
|
62
66
|
end
|
63
67
|
|
@@ -65,7 +69,11 @@ module Hanami
|
|
65
69
|
# @api private
|
66
70
|
def method_missing(m, *args, &block)
|
67
71
|
::Hanami::View::Escape.html(
|
68
|
-
|
72
|
+
# FIXME: this isn't compatible with Hanami 2.0, as it extends a view
|
73
|
+
# that we want to be frozen in the future
|
74
|
+
#
|
75
|
+
# See https://github.com/hanami/view/issues/130#issuecomment-319326236
|
76
|
+
if @view.respond_to?(m, true)
|
69
77
|
@view.__send__ m, *args, &block
|
70
78
|
elsif @locals.key?(m)
|
71
79
|
@locals[m]
|
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.0.
|
4
|
+
version: 1.0.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: 2017-04
|
11
|
+
date: 2017-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -59,19 +59,19 @@ dependencies:
|
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '1.5'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: rspec
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '5'
|
67
|
+
version: '3.5'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '5'
|
74
|
+
version: '3.5'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: rake
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|