hanami-view 1.3.3 → 2.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -10
  3. data/LICENSE +20 -0
  4. data/README.md +20 -862
  5. data/hanami-view.gemspec +26 -16
  6. data/lib/hanami-view.rb +3 -1
  7. data/lib/hanami/view.rb +208 -223
  8. data/lib/hanami/view/application_configuration.rb +77 -0
  9. data/lib/hanami/view/application_context.rb +35 -0
  10. data/lib/hanami/view/application_view.rb +89 -0
  11. data/lib/hanami/view/context.rb +97 -0
  12. data/lib/hanami/view/context_helpers/content_helpers.rb +26 -0
  13. data/lib/hanami/view/decorated_attributes.rb +82 -0
  14. data/lib/hanami/view/errors.rb +19 -56
  15. data/lib/hanami/view/exposure.rb +126 -0
  16. data/lib/hanami/view/exposures.rb +74 -0
  17. data/lib/hanami/view/part.rb +217 -0
  18. data/lib/hanami/view/part_builder.rb +140 -0
  19. data/lib/hanami/view/path.rb +68 -0
  20. data/lib/hanami/view/render_environment.rb +62 -0
  21. data/lib/hanami/view/render_environment_missing.rb +44 -0
  22. data/lib/hanami/view/rendered.rb +55 -0
  23. data/lib/hanami/view/renderer.rb +79 -0
  24. data/lib/hanami/view/scope.rb +189 -0
  25. data/lib/hanami/view/scope_builder.rb +98 -0
  26. data/lib/hanami/view/standalone_view.rb +396 -0
  27. data/lib/hanami/view/tilt.rb +78 -0
  28. data/lib/hanami/view/tilt/erb.rb +26 -0
  29. data/lib/hanami/view/tilt/erbse.rb +21 -0
  30. data/lib/hanami/view/tilt/haml.rb +26 -0
  31. data/lib/hanami/view/version.rb +5 -5
  32. metadata +114 -70
  33. data/LICENSE.md +0 -22
  34. data/lib/hanami/layout.rb +0 -190
  35. data/lib/hanami/presenter.rb +0 -98
  36. data/lib/hanami/view/configuration.rb +0 -504
  37. data/lib/hanami/view/dsl.rb +0 -347
  38. data/lib/hanami/view/escape.rb +0 -225
  39. data/lib/hanami/view/inheritable.rb +0 -54
  40. data/lib/hanami/view/rendering.rb +0 -294
  41. data/lib/hanami/view/rendering/layout_finder.rb +0 -128
  42. data/lib/hanami/view/rendering/layout_registry.rb +0 -69
  43. data/lib/hanami/view/rendering/layout_scope.rb +0 -281
  44. data/lib/hanami/view/rendering/null_layout.rb +0 -52
  45. data/lib/hanami/view/rendering/null_local.rb +0 -82
  46. data/lib/hanami/view/rendering/null_template.rb +0 -83
  47. data/lib/hanami/view/rendering/null_view.rb +0 -26
  48. data/lib/hanami/view/rendering/options.rb +0 -24
  49. data/lib/hanami/view/rendering/partial.rb +0 -31
  50. data/lib/hanami/view/rendering/partial_file.rb +0 -29
  51. data/lib/hanami/view/rendering/partial_finder.rb +0 -75
  52. data/lib/hanami/view/rendering/partial_templates_finder.rb +0 -73
  53. data/lib/hanami/view/rendering/registry.rb +0 -134
  54. data/lib/hanami/view/rendering/scope.rb +0 -108
  55. data/lib/hanami/view/rendering/subscope.rb +0 -56
  56. data/lib/hanami/view/rendering/template.rb +0 -69
  57. data/lib/hanami/view/rendering/template_finder.rb +0 -55
  58. data/lib/hanami/view/rendering/template_name.rb +0 -50
  59. data/lib/hanami/view/rendering/templates_finder.rb +0 -144
  60. data/lib/hanami/view/rendering/view_finder.rb +0 -37
  61. data/lib/hanami/view/template.rb +0 -57
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/core/cache"
4
+ require "tilt"
5
+
6
+ module Hanami
7
+ class View
8
+ # @api private
9
+ module Tilt
10
+ extend Dry::Core::Cache
11
+
12
+ class << self
13
+ def [](path, mapping, **options)
14
+ ext = File.extname(path).sub(/^./, "").to_sym
15
+ activate_adapter ext
16
+
17
+ with_mapping(mapping).new(path, **options)
18
+ end
19
+
20
+ def default_mapping
21
+ ::Tilt.default_mapping
22
+ end
23
+
24
+ def register_adapter(ext, adapter)
25
+ adapters[ext] = adapter
26
+ end
27
+
28
+ def deregister_adapter(ext)
29
+ adapters.delete(ext)
30
+ end
31
+
32
+ private
33
+
34
+ def adapters
35
+ @adapters ||= {}
36
+ end
37
+
38
+ def activate_adapter(ext)
39
+ fetch_or_store(:adapter, ext) {
40
+ adapter = adapters[ext]
41
+ return unless adapter
42
+
43
+ *requires, error_message = adapter.requirements
44
+
45
+ begin
46
+ requires.each(&method(:require))
47
+ rescue LoadError => e
48
+ raise e, "#{e.message}\n\n#{error_message}"
49
+ end
50
+
51
+ adapter.activate
52
+ }
53
+ end
54
+
55
+ def with_mapping(mapping)
56
+ fetch_or_store(:mapping, mapping) {
57
+ if mapping.any?
58
+ build_mapping(mapping)
59
+ else
60
+ default_mapping
61
+ end
62
+ }
63
+ end
64
+
65
+ def build_mapping(mapping)
66
+ default_mapping.dup.tap do |new_mapping|
67
+ mapping.each do |extension, template_class|
68
+ new_mapping.register template_class, extension
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ require_relative "tilt/erb"
78
+ require_relative "tilt/haml"
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ class View
5
+ module Tilt
6
+ module ERB
7
+ def self.requirements
8
+ ["hanami/view/tilt/erbse", <<~ERROR]
9
+ hanami-view requires erbse for full compatibility when rendering .erb templates (e.g. implicitly capturing block content when yielding)
10
+
11
+ To ignore this and use another engine for .erb templates, deregister this adapter before calling your views:
12
+
13
+ Hanami::View::Tilt.deregister_adapter(:erb)
14
+ ERROR
15
+ end
16
+
17
+ def self.activate
18
+ Tilt.default_mapping.register ErbseTemplate, "erb"
19
+ self
20
+ end
21
+ end
22
+
23
+ register_adapter :erb, ERB
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tilt/template"
4
+ require "erbse"
5
+
6
+ module Hanami
7
+ class View
8
+ module Tilt
9
+ # Tilt template class copied from cells-erb gem
10
+ class ErbseTemplate < ::Tilt::Template
11
+ def prepare
12
+ @template = ::Erbse::Engine.new
13
+ end
14
+
15
+ def precompiled_template(_locals)
16
+ @template.call(data)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ class View
5
+ module Tilt
6
+ module Haml
7
+ def self.requirements
8
+ ["hamlit/block", <<~ERROR]
9
+ hanami-view requires hamlit-block for full compatibility when rendering .haml templates (e.g. implicitly capturing block content when yielding)
10
+
11
+ To ignore this and use another engine for .haml templates, dereigster this adapter before calling your views:
12
+
13
+ Hanami::View::Tilt.deregister_adatper(:haml)
14
+ ERROR
15
+ end
16
+
17
+ def self.activate
18
+ # Requiring hamlit/block will register the engine with Tilt
19
+ self
20
+ end
21
+ end
22
+
23
+ register_adapter :haml, Haml
24
+ end
25
+ end
26
+ end
@@ -1,8 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hanami
2
- module View
3
- # Defines the version
4
- #
5
- # @since 0.1.0
6
- VERSION = '1.3.3'.freeze
4
+ class View
5
+ # @api private
6
+ VERSION = "2.0.0.alpha2"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,145 +1,188 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-view
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 2.0.0.alpha2
5
5
  platform: ruby
6
6
  authors:
7
- - Luca Guidi
8
- autorequire:
7
+ - Tim Riley
8
+ - Piotr Solnica
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2020-01-07 00:00:00.000000000 Z
12
+ date: 2021-05-04 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
- name: tilt
15
+ name: concurrent-ruby
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
18
  - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '2.0'
20
+ version: '1.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: dry-configurable
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0.1'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: dry-core
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.5'
20
49
  - - ">="
21
50
  - !ruby/object:Gem::Version
22
- version: 2.0.1
51
+ version: '0.5'
23
52
  type: :runtime
24
53
  prerelease: false
25
54
  version_requirements: !ruby/object:Gem::Requirement
26
55
  requirements:
27
56
  - - "~>"
28
57
  - !ruby/object:Gem::Version
29
- version: '2.0'
58
+ version: '0.5'
30
59
  - - ">="
31
60
  - !ruby/object:Gem::Version
32
- version: 2.0.1
61
+ version: '0.5'
33
62
  - !ruby/object:Gem::Dependency
34
- name: hanami-utils
63
+ name: dry-inflector
35
64
  requirement: !ruby/object:Gem::Requirement
36
65
  requirements:
37
66
  - - "~>"
38
67
  - !ruby/object:Gem::Version
39
- version: '1.3'
68
+ version: '0.1'
40
69
  type: :runtime
41
70
  prerelease: false
42
71
  version_requirements: !ruby/object:Gem::Requirement
43
72
  requirements:
44
73
  - - "~>"
45
74
  - !ruby/object:Gem::Version
46
- version: '1.3'
75
+ version: '0.1'
47
76
  - !ruby/object:Gem::Dependency
48
- name: bundler
77
+ name: tilt
49
78
  requirement: !ruby/object:Gem::Requirement
50
79
  requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.0.6
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '2.0'
51
93
  - - ">="
52
94
  - !ruby/object:Gem::Version
53
- version: '1.6'
54
- - - "<"
95
+ version: 2.0.6
96
+ - !ruby/object:Gem::Dependency
97
+ name: bundler
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
55
101
  - !ruby/object:Gem::Version
56
- version: '3'
102
+ version: '0'
57
103
  type: :development
58
104
  prerelease: false
59
105
  version_requirements: !ruby/object:Gem::Requirement
60
106
  requirements:
61
107
  - - ">="
62
108
  - !ruby/object:Gem::Version
63
- version: '1.6'
64
- - - "<"
65
- - !ruby/object:Gem::Version
66
- version: '3'
109
+ version: '0'
67
110
  - !ruby/object:Gem::Dependency
68
- name: rspec
111
+ name: rake
69
112
  requirement: !ruby/object:Gem::Requirement
70
113
  requirements:
71
- - - "~>"
114
+ - - ">="
72
115
  - !ruby/object:Gem::Version
73
- version: '3.7'
116
+ version: '0'
74
117
  type: :development
75
118
  prerelease: false
76
119
  version_requirements: !ruby/object:Gem::Requirement
77
120
  requirements:
78
- - - "~>"
121
+ - - ">="
79
122
  - !ruby/object:Gem::Version
80
- version: '3.7'
123
+ version: '0'
81
124
  - !ruby/object:Gem::Dependency
82
- name: rake
125
+ name: rspec
83
126
  requirement: !ruby/object:Gem::Requirement
84
127
  requirements:
85
- - - "~>"
128
+ - - ">="
86
129
  - !ruby/object:Gem::Version
87
- version: '13'
130
+ version: '0'
88
131
  type: :development
89
132
  prerelease: false
90
133
  version_requirements: !ruby/object:Gem::Requirement
91
134
  requirements:
92
- - - "~>"
135
+ - - ">="
93
136
  - !ruby/object:Gem::Version
94
- version: '13'
95
- description: View layer for Hanami
137
+ version: '0'
138
+ description: A complete, standalone view rendering system that gives you everything
139
+ you need to write well-factored view code
96
140
  email:
97
- - me@lucaguidi.com
141
+ - tim@icelab.com.au
142
+ - piotr.solnica@gmail.com
98
143
  executables: []
99
144
  extensions: []
100
145
  extra_rdoc_files: []
101
146
  files:
102
147
  - CHANGELOG.md
103
- - LICENSE.md
148
+ - LICENSE
104
149
  - README.md
105
150
  - hanami-view.gemspec
106
151
  - lib/hanami-view.rb
107
- - lib/hanami/layout.rb
108
- - lib/hanami/presenter.rb
109
152
  - lib/hanami/view.rb
110
- - lib/hanami/view/configuration.rb
111
- - lib/hanami/view/dsl.rb
153
+ - lib/hanami/view/application_configuration.rb
154
+ - lib/hanami/view/application_context.rb
155
+ - lib/hanami/view/application_view.rb
156
+ - lib/hanami/view/context.rb
157
+ - lib/hanami/view/context_helpers/content_helpers.rb
158
+ - lib/hanami/view/decorated_attributes.rb
112
159
  - lib/hanami/view/errors.rb
113
- - lib/hanami/view/escape.rb
114
- - lib/hanami/view/inheritable.rb
115
- - lib/hanami/view/rendering.rb
116
- - lib/hanami/view/rendering/layout_finder.rb
117
- - lib/hanami/view/rendering/layout_registry.rb
118
- - lib/hanami/view/rendering/layout_scope.rb
119
- - lib/hanami/view/rendering/null_layout.rb
120
- - lib/hanami/view/rendering/null_local.rb
121
- - lib/hanami/view/rendering/null_template.rb
122
- - lib/hanami/view/rendering/null_view.rb
123
- - lib/hanami/view/rendering/options.rb
124
- - lib/hanami/view/rendering/partial.rb
125
- - lib/hanami/view/rendering/partial_file.rb
126
- - lib/hanami/view/rendering/partial_finder.rb
127
- - lib/hanami/view/rendering/partial_templates_finder.rb
128
- - lib/hanami/view/rendering/registry.rb
129
- - lib/hanami/view/rendering/scope.rb
130
- - lib/hanami/view/rendering/subscope.rb
131
- - lib/hanami/view/rendering/template.rb
132
- - lib/hanami/view/rendering/template_finder.rb
133
- - lib/hanami/view/rendering/template_name.rb
134
- - lib/hanami/view/rendering/templates_finder.rb
135
- - lib/hanami/view/rendering/view_finder.rb
136
- - lib/hanami/view/template.rb
160
+ - lib/hanami/view/exposure.rb
161
+ - lib/hanami/view/exposures.rb
162
+ - lib/hanami/view/part.rb
163
+ - lib/hanami/view/part_builder.rb
164
+ - lib/hanami/view/path.rb
165
+ - lib/hanami/view/render_environment.rb
166
+ - lib/hanami/view/render_environment_missing.rb
167
+ - lib/hanami/view/rendered.rb
168
+ - lib/hanami/view/renderer.rb
169
+ - lib/hanami/view/scope.rb
170
+ - lib/hanami/view/scope_builder.rb
171
+ - lib/hanami/view/standalone_view.rb
172
+ - lib/hanami/view/tilt.rb
173
+ - lib/hanami/view/tilt/erb.rb
174
+ - lib/hanami/view/tilt/erbse.rb
175
+ - lib/hanami/view/tilt/haml.rb
137
176
  - lib/hanami/view/version.rb
138
- homepage: http://hanamirb.org
177
+ homepage: https://dry-rb.org/gems/hanami-view
139
178
  licenses:
140
179
  - MIT
141
- metadata: {}
142
- post_install_message:
180
+ metadata:
181
+ allowed_push_host: https://rubygems.org
182
+ changelog_uri: https://github.com/hanami/view/blob/master/CHANGELOG.md
183
+ source_code_uri: https://github.com/hanami/view
184
+ bug_tracker_uri: https://github.com/hanami/view/issues
185
+ post_install_message:
143
186
  rdoc_options: []
144
187
  require_paths:
145
188
  - lib
@@ -147,15 +190,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
190
  requirements:
148
191
  - - ">="
149
192
  - !ruby/object:Gem::Version
150
- version: 2.3.0
193
+ version: 2.4.0
151
194
  required_rubygems_version: !ruby/object:Gem::Requirement
152
195
  requirements:
153
- - - ">="
196
+ - - ">"
154
197
  - !ruby/object:Gem::Version
155
- version: '0'
198
+ version: 1.3.1
156
199
  requirements: []
157
- rubygems_version: 3.1.2
158
- signing_key:
200
+ rubygems_version: 3.2.4
201
+ signing_key:
159
202
  specification_version: 4
160
- summary: View layer for Hanami, with a separation between views and templates
203
+ summary: A complete, standalone view rendering system that gives you everything you
204
+ need to write well-factored view code
161
205
  test_files: []
data/LICENSE.md DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014-2017 Luca Guidi
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.