hanami-view 1.3.0.beta1 → 2.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  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 +113 -63
  33. data/LICENSE.md +0 -22
  34. data/lib/hanami/layout.rb +0 -172
  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 -274
  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/options.rb +0 -24
  48. data/lib/hanami/view/rendering/partial.rb +0 -31
  49. data/lib/hanami/view/rendering/partial_file.rb +0 -29
  50. data/lib/hanami/view/rendering/partial_finder.rb +0 -75
  51. data/lib/hanami/view/rendering/partial_templates_finder.rb +0 -73
  52. data/lib/hanami/view/rendering/registry.rb +0 -134
  53. data/lib/hanami/view/rendering/scope.rb +0 -108
  54. data/lib/hanami/view/rendering/subscope.rb +0 -56
  55. data/lib/hanami/view/rendering/template.rb +0 -69
  56. data/lib/hanami/view/rendering/template_finder.rb +0 -55
  57. data/lib/hanami/view/rendering/template_name.rb +0 -50
  58. data/lib/hanami/view/rendering/templates_finder.rb +0 -144
  59. data/lib/hanami/view/rendering/view_finder.rb +0 -37
  60. 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.0.beta1'.freeze
4
+ class View
5
+ # @api private
6
+ VERSION = "2.0.0.alpha2"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,138 +1,188 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-view
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0.beta1
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: 2018-08-08 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.beta
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.beta
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:
51
80
  - - "~>"
52
81
  - !ruby/object:Gem::Version
53
- version: '1.5'
54
- type: :development
82
+ version: '2.0'
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.0.6
86
+ type: :runtime
55
87
  prerelease: false
56
88
  version_requirements: !ruby/object:Gem::Requirement
57
89
  requirements:
58
90
  - - "~>"
59
91
  - !ruby/object:Gem::Version
60
- version: '1.5'
92
+ version: '2.0'
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 2.0.6
61
96
  - !ruby/object:Gem::Dependency
62
- name: rspec
97
+ name: bundler
63
98
  requirement: !ruby/object:Gem::Requirement
64
99
  requirements:
65
- - - "~>"
100
+ - - ">="
66
101
  - !ruby/object:Gem::Version
67
- version: '3.7'
102
+ version: '0'
68
103
  type: :development
69
104
  prerelease: false
70
105
  version_requirements: !ruby/object:Gem::Requirement
71
106
  requirements:
72
- - - "~>"
107
+ - - ">="
73
108
  - !ruby/object:Gem::Version
74
- version: '3.7'
109
+ version: '0'
75
110
  - !ruby/object:Gem::Dependency
76
111
  name: rake
77
112
  requirement: !ruby/object:Gem::Requirement
78
113
  requirements:
79
- - - "~>"
114
+ - - ">="
80
115
  - !ruby/object:Gem::Version
81
- version: '12'
116
+ version: '0'
82
117
  type: :development
83
118
  prerelease: false
84
119
  version_requirements: !ruby/object:Gem::Requirement
85
120
  requirements:
86
- - - "~>"
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ - !ruby/object:Gem::Dependency
125
+ name: rspec
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
87
136
  - !ruby/object:Gem::Version
88
- version: '12'
89
- 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
90
140
  email:
91
- - me@lucaguidi.com
141
+ - tim@icelab.com.au
142
+ - piotr.solnica@gmail.com
92
143
  executables: []
93
144
  extensions: []
94
145
  extra_rdoc_files: []
95
146
  files:
96
147
  - CHANGELOG.md
97
- - LICENSE.md
148
+ - LICENSE
98
149
  - README.md
99
150
  - hanami-view.gemspec
100
151
  - lib/hanami-view.rb
101
- - lib/hanami/layout.rb
102
- - lib/hanami/presenter.rb
103
152
  - lib/hanami/view.rb
104
- - lib/hanami/view/configuration.rb
105
- - 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
106
159
  - lib/hanami/view/errors.rb
107
- - lib/hanami/view/escape.rb
108
- - lib/hanami/view/inheritable.rb
109
- - lib/hanami/view/rendering.rb
110
- - lib/hanami/view/rendering/layout_finder.rb
111
- - lib/hanami/view/rendering/layout_registry.rb
112
- - lib/hanami/view/rendering/layout_scope.rb
113
- - lib/hanami/view/rendering/null_layout.rb
114
- - lib/hanami/view/rendering/null_local.rb
115
- - lib/hanami/view/rendering/null_template.rb
116
- - lib/hanami/view/rendering/options.rb
117
- - lib/hanami/view/rendering/partial.rb
118
- - lib/hanami/view/rendering/partial_file.rb
119
- - lib/hanami/view/rendering/partial_finder.rb
120
- - lib/hanami/view/rendering/partial_templates_finder.rb
121
- - lib/hanami/view/rendering/registry.rb
122
- - lib/hanami/view/rendering/scope.rb
123
- - lib/hanami/view/rendering/subscope.rb
124
- - lib/hanami/view/rendering/template.rb
125
- - lib/hanami/view/rendering/template_finder.rb
126
- - lib/hanami/view/rendering/template_name.rb
127
- - lib/hanami/view/rendering/templates_finder.rb
128
- - lib/hanami/view/rendering/view_finder.rb
129
- - 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
130
176
  - lib/hanami/view/version.rb
131
- homepage: http://hanamirb.org
177
+ homepage: https://dry-rb.org/gems/hanami-view
132
178
  licenses:
133
179
  - MIT
134
- metadata: {}
135
- 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:
136
186
  rdoc_options: []
137
187
  require_paths:
138
188
  - lib
@@ -140,16 +190,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
190
  requirements:
141
191
  - - ">="
142
192
  - !ruby/object:Gem::Version
143
- version: 2.3.0
193
+ version: 2.4.0
144
194
  required_rubygems_version: !ruby/object:Gem::Requirement
145
195
  requirements:
146
196
  - - ">"
147
197
  - !ruby/object:Gem::Version
148
198
  version: 1.3.1
149
199
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.7.7
152
- signing_key:
200
+ rubygems_version: 3.2.4
201
+ signing_key:
153
202
  specification_version: 4
154
- 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
155
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.