hanami-view 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52f2330d18d5d01dad4e71e60e5e0d2994f0c9d1
4
- data.tar.gz: b196bfb91c3dc4ec9cfa8c9aef685aec2d2d6573
3
+ metadata.gz: f3f3b5a91fabf790905218d179350b9ca5b09ea5
4
+ data.tar.gz: 90708fec73255ef891fa0210527ea32bf49c82a5
5
5
  SHA512:
6
- metadata.gz: 95798a89b29c1e0b5fb5d5def1d21f5af74f33f3e0794af05aae36215d54f4211f61c820ded675223cfe23c1c0eb5d91840c85af343de3c885f762a8db7600fa
7
- data.tar.gz: 107858f14f6918b489c1dee2e2e0f3c5e8d9e368fcf4d46678356a1c05a9dd14dc9e0759549eea8656b37041357351b6ea3324f9229e7748ff4247be2db95b99
6
+ metadata.gz: e414c7c8df49dfa4e33ff5e694baa9408ac8336aff315f631044ed8f86300dfbad8fdf066bed6e8227ba96d77c2e6e46cf20600d0cc7480e56ed83e55429f1f3
7
+ data.tar.gz: b21512ad851b40cd8dca788ff9c93ae98f40eec8a1087ee855e2c8858324543f45d3c403872b061f1c772f1a42d10332830f66f43607c3a2da7fec83b111f0b9
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Hanami::View
2
2
  View layer for Hanami
3
3
 
4
+ ## v1.0.1 - 2017-08-04
5
+ ### Added
6
+ - [Luca Guidi] Compatibility with `haml` 5.0
7
+
4
8
  ## v1.0.0 - 2017-04-06
5
9
 
6
10
  ## v1.0.0.rc1 - 2017-03-31
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', '~> 1.5'
26
- spec.add_development_dependency 'minitest', '~> 5'
27
- spec.add_development_dependency 'rake', '~> 11'
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
@@ -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 of the :format
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 it's template.
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
- if @scope.respond_to?(m)
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
- @view.respond_to?(m) ||
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
- if @view.respond_to?(m)
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]
@@ -3,6 +3,6 @@ module Hanami
3
3
  # Defines the version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '1.0.0'.freeze
6
+ VERSION = '1.0.1'.freeze
7
7
  end
8
8
  end
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.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-06 00:00:00.000000000 Z
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: minitest
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