hanami-view 1.0.0.beta1 → 1.0.0.beta2
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/LICENSE.md +1 -1
- data/README.md +1 -1
- data/lib/hanami/layout.rb +1 -0
- data/lib/hanami/view/configuration.rb +7 -0
- data/lib/hanami/view/errors.rb +4 -0
- data/lib/hanami/view/escape.rb +0 -2
- data/lib/hanami/view/rendering/layout_registry.rb +6 -0
- data/lib/hanami/view/rendering/layout_scope.rb +3 -50
- data/lib/hanami/view/rendering/null_local.rb +4 -0
- data/lib/hanami/view/rendering/partial.rb +2 -0
- data/lib/hanami/view/rendering/partial_file.rb +11 -1
- data/lib/hanami/view/rendering/partial_finder.rb +3 -0
- data/lib/hanami/view/rendering/partial_templates_finder.rb +4 -1
- data/lib/hanami/view/rendering/registry.rb +6 -0
- data/lib/hanami/view/rendering/scope.rb +1 -0
- data/lib/hanami/view/rendering/template.rb +2 -0
- data/lib/hanami/view/rendering/template_finder.rb +2 -0
- data/lib/hanami/view/rendering/template_name.rb +13 -0
- data/lib/hanami/view/rendering.rb +3 -0
- data/lib/hanami/view/version.rb +1 -1
- data/lib/hanami/view.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b09fc59502d563ea4210c73bc5909553a2f5cb03
|
4
|
+
data.tar.gz: f9a822d9f11356243c2d4ed6d67dc5d2edbf60a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '00858c90d06b8eddf6c5d497b3dd5f03df9edb8fb620248d300b26017b94eafc49eb2866d34241204ba72e8abd30096700dc8884f338202fc680665848e70603'
|
7
|
+
data.tar.gz: e6602693088e2fbc2f1a54cae40278266bc542d65992d6e3b02c7830d744b1634d8142f5a5376265e6509264f1280ddb20f83f4ce046c386dd704184b1fa523a
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Hanami::View
|
2
2
|
View layer for Hanami
|
3
3
|
|
4
|
+
## v1.0.0.beta2 - 2017-03-17
|
5
|
+
### Changed
|
6
|
+
- [Luca Guidi] Remove deprecated `Hanami::View::Rendering::LayoutScope#content`
|
7
|
+
|
4
8
|
## v1.0.0.beta1 - 2017-02-14
|
5
9
|
### Added
|
6
10
|
- [Luca Guidi] Official support for Ruby: MRI 2.4
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -866,6 +866,6 @@ __Hanami::View__ uses [Semantic Versioning 2.0.0](http://semver.org)
|
|
866
866
|
|
867
867
|
## Copyright
|
868
868
|
|
869
|
-
Copyright 2014-
|
869
|
+
Copyright 2014-2017 Luca Guidi – Released under MIT License
|
870
870
|
|
871
871
|
This project was formerly known as Lotus (`lotus-view`).
|
data/lib/hanami/layout.rb
CHANGED
@@ -483,14 +483,21 @@ module Hanami
|
|
483
483
|
end
|
484
484
|
end
|
485
485
|
|
486
|
+
# @api private
|
486
487
|
alias_method :unload!, :reset!
|
487
488
|
|
488
489
|
protected
|
490
|
+
# @api private
|
489
491
|
attr_writer :namespace
|
492
|
+
# @api private
|
490
493
|
attr_writer :root
|
494
|
+
# @api private
|
491
495
|
attr_writer :load_paths
|
496
|
+
# @api private
|
492
497
|
attr_writer :layout
|
498
|
+
# @api private
|
493
499
|
attr_writer :default_encoding
|
500
|
+
# @api private
|
494
501
|
attr_writer :modules
|
495
502
|
end
|
496
503
|
end
|
data/lib/hanami/view/errors.rb
CHANGED
@@ -17,6 +17,8 @@ module Hanami
|
|
17
17
|
#
|
18
18
|
# @since 0.1.0
|
19
19
|
class MissingTemplateError < Error
|
20
|
+
# @since 0.1.0
|
21
|
+
# @api private
|
20
22
|
def initialize(template, format)
|
21
23
|
super("Can't find template '#{ template }' for '#{ format }' format.")
|
22
24
|
end
|
@@ -39,6 +41,8 @@ module Hanami
|
|
39
41
|
#
|
40
42
|
# @since 0.5.0
|
41
43
|
class MissingTemplateLayoutError < Error
|
44
|
+
# @since 0.5.0
|
45
|
+
# @api private
|
42
46
|
def initialize(template)
|
43
47
|
super("Can't find layout template '#{ template }'")
|
44
48
|
end
|
data/lib/hanami/view/escape.rb
CHANGED
@@ -18,7 +18,6 @@ module Hanami
|
|
18
18
|
# @return [Hanami::Utils::Escape::SafeString] the string marked as safe
|
19
19
|
#
|
20
20
|
# @since 0.4.0
|
21
|
-
# @api public
|
22
21
|
#
|
23
22
|
# @example View usage
|
24
23
|
# require 'hanami/view'
|
@@ -72,7 +71,6 @@ module Hanami
|
|
72
71
|
# autoescape
|
73
72
|
#
|
74
73
|
# @since 0.4.0
|
75
|
-
# @api public
|
76
74
|
#
|
77
75
|
# @see Hanami::View::Escape::Presenter
|
78
76
|
#
|
@@ -43,6 +43,8 @@ module Hanami
|
|
43
43
|
end
|
44
44
|
|
45
45
|
protected
|
46
|
+
# @api private
|
47
|
+
# @since 0.1.0
|
46
48
|
def prepare!
|
47
49
|
templates.each do |template|
|
48
50
|
@registry.merge! template.format => template
|
@@ -50,10 +52,14 @@ module Hanami
|
|
50
52
|
@registry.any? or raise MissingTemplateLayoutError.new(@view)
|
51
53
|
end
|
52
54
|
|
55
|
+
# @api private
|
56
|
+
# @since 0.1.0
|
53
57
|
def templates
|
54
58
|
TemplatesFinder.new(@view).find
|
55
59
|
end
|
56
60
|
|
61
|
+
# @api private
|
62
|
+
# @since 0.1.0
|
57
63
|
def format(context)
|
58
64
|
context.fetch(:format) { raise MissingFormatError }
|
59
65
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'hanami/view/rendering/null_local'
|
2
2
|
require 'hanami/utils/escape'
|
3
|
-
require 'hanami/utils/deprecation'
|
4
3
|
|
5
4
|
module Hanami
|
6
5
|
module View
|
@@ -118,55 +117,6 @@ module Hanami
|
|
118
117
|
@locals || @scope.locals
|
119
118
|
end
|
120
119
|
|
121
|
-
# Returns a content for the given key, by trying to invoke on the current
|
122
|
-
# scope, a method with the same name.
|
123
|
-
#
|
124
|
-
# The scope is made of locals and concrete methods from view and layout.
|
125
|
-
#
|
126
|
-
# @param key [Symbol] a method to invoke within current scope
|
127
|
-
# @return [String,NilClass] returning content if scope respond to the
|
128
|
-
# requested method
|
129
|
-
#
|
130
|
-
# @deprecated Use {#local} instead
|
131
|
-
# @since 0.4.1
|
132
|
-
#
|
133
|
-
# @example
|
134
|
-
# # Given the following layout template
|
135
|
-
#
|
136
|
-
# <!doctype HTML>
|
137
|
-
# <html>
|
138
|
-
# <!-- ... -->
|
139
|
-
# <body>
|
140
|
-
# <!-- ... -->
|
141
|
-
# <%= content :footer %>
|
142
|
-
# </body>
|
143
|
-
# </html>
|
144
|
-
#
|
145
|
-
# # Case 1:
|
146
|
-
# # Products::Index doesn't respond to #footer, content will return nil
|
147
|
-
# #
|
148
|
-
# # Case 2:
|
149
|
-
# # Products::Show responds to #footer, content will send back
|
150
|
-
# # #footer returning value
|
151
|
-
#
|
152
|
-
# module Products
|
153
|
-
# class Index
|
154
|
-
# include Hanami::View
|
155
|
-
# end
|
156
|
-
#
|
157
|
-
# class Show
|
158
|
-
# include Hanami::View
|
159
|
-
#
|
160
|
-
# def footer
|
161
|
-
# "contents for footer"
|
162
|
-
# end
|
163
|
-
# end
|
164
|
-
# end
|
165
|
-
def content(key)
|
166
|
-
Utils::Deprecation.new("#content is deprecated, please use #local")
|
167
|
-
__send__(key) if respond_to?(key)
|
168
|
-
end
|
169
|
-
|
170
120
|
# It tries to invoke a method for the view or a local for the given key.
|
171
121
|
# If the lookup fails, it returns a null object.
|
172
122
|
#
|
@@ -224,6 +174,7 @@ module Hanami
|
|
224
174
|
# @return [TrueClass,FalseClass]
|
225
175
|
#
|
226
176
|
# @since 0.3.0
|
177
|
+
# @api private
|
227
178
|
#
|
228
179
|
# @see http://ruby-doc.org/core/Object.html#method-i-respond_to-3F
|
229
180
|
def respond_to?(m, include_all = false)
|
@@ -271,6 +222,7 @@ module Hanami
|
|
271
222
|
end
|
272
223
|
end
|
273
224
|
|
225
|
+
# @api private
|
274
226
|
def renderer(options)
|
275
227
|
if options[:partial]
|
276
228
|
Rendering::Partial
|
@@ -280,6 +232,7 @@ module Hanami
|
|
280
232
|
end
|
281
233
|
|
282
234
|
private
|
235
|
+
# @api private
|
283
236
|
def _options(options)
|
284
237
|
options.dup.tap do |opts|
|
285
238
|
opts.merge!(format: format)
|
@@ -20,21 +20,25 @@ module Hanami
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# @since 0.7.0
|
23
|
+
# @api private
|
23
24
|
def all?
|
24
25
|
false
|
25
26
|
end
|
26
27
|
|
27
28
|
# @since 0.7.0
|
29
|
+
# @api private
|
28
30
|
def any?
|
29
31
|
false
|
30
32
|
end
|
31
33
|
|
32
34
|
# @since 0.7.0
|
35
|
+
# @api private
|
33
36
|
def empty?
|
34
37
|
true
|
35
38
|
end
|
36
39
|
|
37
40
|
# @since 0.7.0
|
41
|
+
# @api private
|
38
42
|
def nil?
|
39
43
|
true
|
40
44
|
end
|
@@ -4,7 +4,17 @@ module Hanami
|
|
4
4
|
# @since 0.7.0
|
5
5
|
# @api private
|
6
6
|
class PartialFile
|
7
|
-
|
7
|
+
# @since 0.7.0
|
8
|
+
# @api private
|
9
|
+
attr_reader :key
|
10
|
+
|
11
|
+
# @since 0.7.0
|
12
|
+
# @api private
|
13
|
+
attr_reader :format
|
14
|
+
|
15
|
+
# @since 0.7.0
|
16
|
+
# @api private
|
17
|
+
attr_reader :template
|
8
18
|
|
9
19
|
# @since 0.7.0
|
10
20
|
# @api private
|
@@ -60,15 +60,18 @@ module Hanami
|
|
60
60
|
all.join(separator)
|
61
61
|
end
|
62
62
|
|
63
|
+
# @api private
|
63
64
|
def template_name
|
64
65
|
*all, last = partial_name.split(separator)
|
65
66
|
all.push( last.prepend(prefix) ).join(separator)
|
66
67
|
end
|
67
68
|
|
69
|
+
# @api private
|
68
70
|
def partial_name
|
69
71
|
@options[:partial]
|
70
72
|
end
|
71
73
|
|
74
|
+
# @api private
|
72
75
|
def prefix
|
73
76
|
PREFIX
|
74
77
|
end
|
@@ -21,6 +21,8 @@ module Hanami
|
|
21
21
|
# @since 0.7.0
|
22
22
|
PARTIAL_PARTS_SEPARATOR = '.'.freeze
|
23
23
|
|
24
|
+
# @api private
|
25
|
+
# @since 0.7.0
|
24
26
|
attr_reader :configuration
|
25
27
|
|
26
28
|
# Initializes a new PartialTemplatesFinder
|
@@ -28,6 +30,7 @@ module Hanami
|
|
28
30
|
# @param configuration [Configuration] the configuration object
|
29
31
|
#
|
30
32
|
# @since 0.7.0
|
33
|
+
# @api private
|
31
34
|
def initialize(configuration)
|
32
35
|
@configuration = configuration
|
33
36
|
end
|
@@ -37,6 +40,7 @@ module Hanami
|
|
37
40
|
# @return [Array] array of PartialFinder objects
|
38
41
|
#
|
39
42
|
# @since 0.7.0
|
43
|
+
# @api private
|
40
44
|
def find
|
41
45
|
_find_partials(configuration.root).map do |template|
|
42
46
|
partial_path, partial_base_name = Pathname(template).relative_path_from(configuration.root).split
|
@@ -67,4 +71,3 @@ module Hanami
|
|
67
71
|
end
|
68
72
|
end
|
69
73
|
end
|
70
|
-
|
@@ -94,31 +94,37 @@ module Hanami
|
|
94
94
|
end
|
95
95
|
|
96
96
|
private
|
97
|
+
# @api private
|
97
98
|
def prepare!
|
98
99
|
prepare_views!
|
99
100
|
prepare_templates!
|
100
101
|
end
|
101
102
|
|
103
|
+
# @api private
|
102
104
|
def prepare_views!
|
103
105
|
views.each do |view|
|
104
106
|
@registry.merge! view.format || DEFAULT_FORMAT => [ view, template_for(view) ]
|
105
107
|
end
|
106
108
|
end
|
107
109
|
|
110
|
+
# @api private
|
108
111
|
def prepare_templates!
|
109
112
|
templates.each do |template|
|
110
113
|
@registry.merge! template.format => [ view_for(template), template ]
|
111
114
|
end
|
112
115
|
end
|
113
116
|
|
117
|
+
# @api private
|
114
118
|
def views
|
115
119
|
@view.subclasses + [ @view ]
|
116
120
|
end
|
117
121
|
|
122
|
+
# @api private
|
118
123
|
def view_for(template)
|
119
124
|
ViewFinder.new(@view).find(template)
|
120
125
|
end
|
121
126
|
|
127
|
+
# @api private
|
122
128
|
def template_for(view)
|
123
129
|
templates.find {|template| template.format == view.format }
|
124
130
|
end
|
@@ -4,30 +4,43 @@ module Hanami
|
|
4
4
|
module View
|
5
5
|
module Rendering
|
6
6
|
# @since 0.2.0
|
7
|
+
# @api private
|
7
8
|
class TemplateName
|
9
|
+
# @since 0.2.0
|
10
|
+
# @api private
|
8
11
|
NAMESPACE_SEPARATOR = '::'.freeze
|
9
12
|
|
13
|
+
# @since 0.2.0
|
14
|
+
# @api private
|
10
15
|
def initialize(name, namespace)
|
11
16
|
@name = name
|
12
17
|
compile!(namespace)
|
13
18
|
end
|
14
19
|
|
20
|
+
# @since 0.2.0
|
21
|
+
# @api private
|
15
22
|
def to_s
|
16
23
|
@name
|
17
24
|
end
|
18
25
|
|
19
26
|
private
|
27
|
+
# @since 0.2.0
|
28
|
+
# @api private
|
20
29
|
def compile!(namespace)
|
21
30
|
tokens(namespace) {|token| replace!(token) }
|
22
31
|
@name = Utils::String.new(@name).underscore
|
23
32
|
end
|
24
33
|
|
34
|
+
# @since 0.2.0
|
35
|
+
# @api private
|
25
36
|
def tokens(namespace)
|
26
37
|
namespace.to_s.split(NAMESPACE_SEPARATOR).each do |token|
|
27
38
|
yield token
|
28
39
|
end
|
29
40
|
end
|
30
41
|
|
42
|
+
# @since 0.2.0
|
43
|
+
# @api private
|
31
44
|
def replace!(token)
|
32
45
|
@name.gsub!(%r{\A#{ token }#{ NAMESPACE_SEPARATOR }}, '')
|
33
46
|
end
|
@@ -10,6 +10,8 @@ module Hanami
|
|
10
10
|
#
|
11
11
|
# @see Hanami::View::Rendering::InstanceMethods
|
12
12
|
module Rendering
|
13
|
+
# @since 0.1.0
|
14
|
+
# @api private
|
13
15
|
def self.extended(base)
|
14
16
|
base.class_eval do
|
15
17
|
include InstanceMethods
|
@@ -281,6 +283,7 @@ module Hanami
|
|
281
283
|
@registry ||= Registry.new(self)
|
282
284
|
end
|
283
285
|
|
286
|
+
# @api private
|
284
287
|
def load_registry!
|
285
288
|
@registry = nil
|
286
289
|
registry.freeze
|
data/lib/hanami/view/version.rb
CHANGED
data/lib/hanami/view.rb
CHANGED
@@ -11,6 +11,9 @@ require 'hanami/view/errors'
|
|
11
11
|
require 'hanami/layout'
|
12
12
|
require 'hanami/presenter'
|
13
13
|
|
14
|
+
# Hanami
|
15
|
+
#
|
16
|
+
# @since 0.1.0
|
14
17
|
module Hanami
|
15
18
|
# View
|
16
19
|
#
|
@@ -103,7 +106,7 @@ module Hanami
|
|
103
106
|
#
|
104
107
|
# @return [Module] a copy of Hanami::View
|
105
108
|
#
|
106
|
-
#
|
109
|
+
# @since 0.2.0
|
107
110
|
#
|
108
111
|
# @see Hanami::View#dupe
|
109
112
|
# @see Hanami::View::Configuration
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-03-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: tilt
|