hanami-view 0.6.1 → 0.7.0
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 +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +21 -5
- data/hanami-view.gemspec +3 -3
- data/lib/hanami/layout.rb +9 -1
- data/lib/hanami/presenter.rb +2 -30
- data/lib/hanami/view/configuration.rb +3 -3
- data/lib/hanami/view/dsl.rb +2 -1
- data/lib/hanami/view/escape.rb +50 -3
- data/lib/hanami/view/rendering.rb +26 -1
- data/lib/hanami/view/rendering/layout_scope.rb +60 -1
- data/lib/hanami/view/rendering/null_local.rb +74 -0
- data/lib/hanami/view/rendering/partial_file.rb +2 -2
- data/lib/hanami/view/rendering/partial_finder.rb +1 -1
- data/lib/hanami/view/rendering/partial_templates_finder.rb +6 -6
- data/lib/hanami/view/rendering/scope.rb +4 -1
- data/lib/hanami/view/rendering/templates_finder.rb +16 -1
- data/lib/hanami/view/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6a48a9095b6dda0e7238dd8f80aedb4b0aaa8df
|
4
|
+
data.tar.gz: b36841002e5ed8e5145a1dbd23adb32b0612fecf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57e9f5bc86fa2416826ae4a705ae0367d70b635f62ab1382e085f04cc3273d184212e45810aad3b53a5dcd82c1381f040e552ea97f06f48b6e6c6acd8b18e84a
|
7
|
+
data.tar.gz: b8973574e56dfe4380d55bca46db9542b7bd559f2bd2e5591c8cb1a79b6b3dceb778ebb9f0d72c0b0a92f8ad1090392af421b40ae1536acb87a3152395b634d7
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
# Hanami::View
|
2
2
|
View layer for Hanami
|
3
3
|
|
4
|
+
## v0.7.0 - 2016-07-22
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Introduced `#local` for views, layouts and templates. It allows to safely access locals without raising errors in case the referenced local is missing.
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- [nessur] Find the correct partial in case of deeply nested templates.
|
10
|
+
- [Marcello Rocha] Ensure `Hanami::Presenter` to respect method visibility of wrapped object.
|
11
|
+
- [Luca Guidi] Ensure to use new registry when loading the framework
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
– [Luca Guidi] Drop support for Ruby 2.0 and 2.1. Official support for JRuby 9.0.5.0+.
|
15
|
+
– [Luca Guidi] Deprecate `#content` in favor of `#local`.
|
16
|
+
|
4
17
|
## v0.6.1 - 2016-02-05
|
5
18
|
### Changed
|
6
19
|
- [Steve Hook] Preload partial templates in order to boost performances for partials rendering (2x faster)
|
data/README.md
CHANGED
@@ -472,10 +472,12 @@ As per convention, layout templates are located under `Hanami::View.root` or `Ap
|
|
472
472
|
|
473
473
|
### Optional Content
|
474
474
|
|
475
|
-
|
475
|
+
#### Optional View Methods
|
476
|
+
|
477
|
+
If we want to render optional contents such as sidebar links or page specific javascripts, we can use `#local`
|
476
478
|
It accepts a key that represents a method that should be available within the rendering context.
|
477
479
|
That context is made of the locals, and the methods that view and layout respond to.
|
478
|
-
If the context can't dispatch that method, it returns `
|
480
|
+
If the context can't dispatch that method, it returns returns a null object (`Hanami::View::Rendering::NullLocal`).
|
479
481
|
|
480
482
|
Given the following layout template.
|
481
483
|
|
@@ -485,14 +487,14 @@ Given the following layout template.
|
|
485
487
|
<!-- ... -->
|
486
488
|
<body>
|
487
489
|
<!-- ... -->
|
488
|
-
<%=
|
490
|
+
<%= local :footer %>
|
489
491
|
</body>
|
490
492
|
</html>
|
491
493
|
```
|
492
494
|
|
493
495
|
We have two views, one responds to `#footer` (`Products::Show`) and the other doesn't (`Products::Index`).
|
494
|
-
When the first is rendered, `
|
495
|
-
In the other case, `
|
496
|
+
When the first is rendered, `local` gives back the returning value of `#footer`.
|
497
|
+
In the other case, `local` returns a null object (`Hanami::View::Rendering::NullLocal`).
|
496
498
|
|
497
499
|
```ruby
|
498
500
|
module Products
|
@@ -510,6 +512,20 @@ module Products
|
|
510
512
|
end
|
511
513
|
```
|
512
514
|
|
515
|
+
#### Optional Locals
|
516
|
+
|
517
|
+
If we want to show announcements to our customers, but we want only load them from the database if there is something to show.
|
518
|
+
This is an optional local.
|
519
|
+
|
520
|
+
```erb
|
521
|
+
<% if local(:announcement).show? %>
|
522
|
+
<h2><%= announcement.message %></h2>
|
523
|
+
<% end %>
|
524
|
+
```
|
525
|
+
|
526
|
+
The first line is safely evaluated in all the cases: if announcement is present or not.
|
527
|
+
In case we enter the `if` statement, we're sure we can safely reference that object.
|
528
|
+
|
513
529
|
### Presenters
|
514
530
|
|
515
531
|
The goal of a presenter is to wrap and reuse presentational logic for an object.
|
data/hanami-view.gemspec
CHANGED
@@ -17,12 +17,12 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = []
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
|
-
spec.required_ruby_version = '>= 2.
|
20
|
+
spec.required_ruby_version = '>= 2.2.0'
|
21
21
|
|
22
22
|
spec.add_runtime_dependency 'tilt', '~> 2.0', '>= 2.0.1'
|
23
|
-
spec.add_runtime_dependency 'hanami-utils', '~> 0.
|
23
|
+
spec.add_runtime_dependency 'hanami-utils', '~> 0.8'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
26
26
|
spec.add_development_dependency 'minitest', '~> 5'
|
27
|
-
spec.add_development_dependency 'rake', '~>
|
27
|
+
spec.add_development_dependency 'rake', '~> 11'
|
28
28
|
end
|
data/lib/hanami/layout.rb
CHANGED
@@ -93,6 +93,7 @@ module Hanami
|
|
93
93
|
end
|
94
94
|
|
95
95
|
protected
|
96
|
+
|
96
97
|
# Loading mechanism hook.
|
97
98
|
#
|
98
99
|
# @api private
|
@@ -100,9 +101,16 @@ module Hanami
|
|
100
101
|
#
|
101
102
|
# @see Hanami::View.load!
|
102
103
|
def load!
|
103
|
-
|
104
|
+
load_registry!
|
104
105
|
configuration.freeze
|
105
106
|
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def load_registry!
|
111
|
+
@registry = nil
|
112
|
+
registry.freeze
|
113
|
+
end
|
106
114
|
end
|
107
115
|
|
108
116
|
# Initialize a layout
|
data/lib/hanami/presenter.rb
CHANGED
@@ -90,37 +90,9 @@ module Hanami
|
|
90
90
|
#
|
91
91
|
# @see Hanami::View::Escape
|
92
92
|
def self.included(base)
|
93
|
-
base.
|
94
|
-
|
95
|
-
|
96
|
-
# Initialize the presenter
|
97
|
-
#
|
98
|
-
# @param object [Object] the object to present
|
99
|
-
#
|
100
|
-
# @since 0.1.0
|
101
|
-
def initialize(object)
|
102
|
-
@object = object
|
103
|
-
end
|
104
|
-
|
105
|
-
protected
|
106
|
-
# Override Ruby's method_missing
|
107
|
-
#
|
108
|
-
# @api private
|
109
|
-
# @since 0.1.0
|
110
|
-
def method_missing(m, *args, &blk)
|
111
|
-
if @object.respond_to?(m)
|
112
|
-
::Hanami::View::Escape.html(@object.__send__(m, *args, &blk))
|
113
|
-
else
|
114
|
-
super
|
93
|
+
base.class_eval do
|
94
|
+
include ::Hanami::View::Escape::Presentable
|
115
95
|
end
|
116
96
|
end
|
117
|
-
|
118
|
-
# Override Ruby's respond_to_missing? in order to support proper delegation
|
119
|
-
#
|
120
|
-
# @api private
|
121
|
-
# @since 0.3.0
|
122
|
-
def respond_to_missing?(m, include_private = false)
|
123
|
-
@object.respond_to?(m, include_private)
|
124
|
-
end
|
125
97
|
end
|
126
98
|
end
|
@@ -427,7 +427,7 @@ module Hanami
|
|
427
427
|
# Load partials for each partial template file found under the
|
428
428
|
# given load paths
|
429
429
|
#
|
430
|
-
# @since
|
430
|
+
# @since 0.7.0
|
431
431
|
# @api private
|
432
432
|
def load_partials!
|
433
433
|
Hanami::View::Rendering::PartialTemplatesFinder.new(self).find.each do |partial|
|
@@ -438,7 +438,7 @@ module Hanami
|
|
438
438
|
# Load partials for each partial template file found under the
|
439
439
|
# given load paths
|
440
440
|
#
|
441
|
-
# @since
|
441
|
+
# @since 0.7.0
|
442
442
|
# @api private
|
443
443
|
def find_partial(relative_partial_path, template_name, format)
|
444
444
|
partials_for_view = partials.has_key?(relative_partial_path) ? partials[relative_partial_path] : partials[template_name]
|
@@ -447,7 +447,7 @@ module Hanami
|
|
447
447
|
|
448
448
|
# Add a partial to the registry
|
449
449
|
#
|
450
|
-
# @since
|
450
|
+
# @since 0.7.0
|
451
451
|
# @api private
|
452
452
|
def add_partial(partial)
|
453
453
|
@partials[partial.key][partial.format.to_sym] = partial.template
|
data/lib/hanami/view/dsl.rb
CHANGED
@@ -76,7 +76,7 @@ module Hanami
|
|
76
76
|
# Articles::JsonShow.format # => :json
|
77
77
|
def format(value = nil)
|
78
78
|
if value.nil?
|
79
|
-
@format
|
79
|
+
@format ||= nil
|
80
80
|
else
|
81
81
|
@format = value
|
82
82
|
end
|
@@ -314,6 +314,7 @@ module Hanami
|
|
314
314
|
# Articles::Show.layout # => Hanami::View::Rendering::NullLayout
|
315
315
|
def layout(value = nil)
|
316
316
|
if value.nil?
|
317
|
+
@layout ||= nil
|
317
318
|
@_layout ||= Rendering::LayoutFinder.find(@layout || configuration.layout, configuration.namespace)
|
318
319
|
elsif !value
|
319
320
|
@layout = Hanami::View::Rendering::NullLayout
|
data/lib/hanami/view/escape.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'hanami/utils/escape'
|
2
|
-
require 'hanami/presenter'
|
3
2
|
|
4
3
|
module Hanami
|
5
4
|
module View
|
@@ -9,6 +8,7 @@ module Hanami
|
|
9
8
|
module Escape
|
10
9
|
module InstanceMethods
|
11
10
|
private
|
11
|
+
|
12
12
|
# Mark the given string as safe to render.
|
13
13
|
#
|
14
14
|
# !!! ATTENTION !!! This may open your application to XSS attacks.
|
@@ -119,6 +119,49 @@ module Hanami
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
+
module Presentable
|
123
|
+
# Inject escape logic into the given class.
|
124
|
+
#
|
125
|
+
# @since 0.7.0
|
126
|
+
# @api private
|
127
|
+
#
|
128
|
+
# @see Hanami::View::Escape
|
129
|
+
def self.included(base)
|
130
|
+
base.extend ::Hanami::View::Escape
|
131
|
+
end
|
132
|
+
|
133
|
+
# Initialize the presenter
|
134
|
+
#
|
135
|
+
# @param object [Object] the object to present
|
136
|
+
#
|
137
|
+
# @since 0.7.0
|
138
|
+
def initialize(object)
|
139
|
+
@object = object
|
140
|
+
end
|
141
|
+
|
142
|
+
protected
|
143
|
+
|
144
|
+
# Override Ruby's method_missing
|
145
|
+
#
|
146
|
+
# @api private
|
147
|
+
# @since 0.7.0
|
148
|
+
def method_missing(m, *args, &blk)
|
149
|
+
if @object.respond_to?(m)
|
150
|
+
::Hanami::View::Escape.html(@object.__send__(m, *args, &blk))
|
151
|
+
else
|
152
|
+
super
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# Override Ruby's respond_to_missing? in order to support proper delegation
|
157
|
+
#
|
158
|
+
# @api private
|
159
|
+
# @since 0.3.0
|
160
|
+
def respond_to_missing?(m, include_private = false)
|
161
|
+
@object.respond_to?(m, include_private)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
122
165
|
# Auto escape presenter
|
123
166
|
#
|
124
167
|
# @since 0.4.0
|
@@ -126,7 +169,7 @@ module Hanami
|
|
126
169
|
#
|
127
170
|
# @see Hanami::View::Escape::InstanceMethods#_escape
|
128
171
|
class Presenter
|
129
|
-
include
|
172
|
+
include Presentable
|
130
173
|
end
|
131
174
|
|
132
175
|
# Escape the given input if it's a string, otherwise return the oject as it is.
|
@@ -165,10 +208,14 @@ module Hanami
|
|
165
208
|
# @since 0.4.0
|
166
209
|
# @api private
|
167
210
|
def method_added(method_name)
|
211
|
+
visibility = :public
|
212
|
+
visibility = :private if private_method_defined? method_name
|
213
|
+
visibility = :protected if protected_method_defined? method_name
|
214
|
+
|
168
215
|
unless autoescape_methods[method_name]
|
169
216
|
prepend Module.new {
|
170
217
|
module_eval %{
|
171
|
-
def #{ method_name }(*args, &blk); ::Hanami::View::Escape.html super; end
|
218
|
+
#{ visibility } def #{ method_name }(*args, &blk); ::Hanami::View::Escape.html super; end
|
172
219
|
}
|
173
220
|
}
|
174
221
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'hanami/view/rendering/registry'
|
2
2
|
require 'hanami/view/rendering/scope'
|
3
|
+
require 'hanami/view/rendering/null_local'
|
3
4
|
|
4
5
|
module Hanami
|
5
6
|
module View
|
@@ -104,6 +105,25 @@ module Hanami
|
|
104
105
|
layout.render
|
105
106
|
end
|
106
107
|
|
108
|
+
# It tries to invoke a method for the view or a local for the given key.
|
109
|
+
# If the lookup fails, it returns a null object.
|
110
|
+
#
|
111
|
+
# @return [Objeect,Hanami::View::Rendering::NullLocal] the returning value
|
112
|
+
#
|
113
|
+
# @since 0.7.0
|
114
|
+
#
|
115
|
+
# @example
|
116
|
+
# <% if local(:plan).overdue? %>
|
117
|
+
# <h2>Your plan is overdue.</h2>
|
118
|
+
# <% end %>
|
119
|
+
def local(key)
|
120
|
+
if respond_to?(key)
|
121
|
+
__send__(key)
|
122
|
+
else
|
123
|
+
locals.fetch(key) { NullLocal.new(key) }
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
107
127
|
protected
|
108
128
|
# The output of the template rendering process.
|
109
129
|
#
|
@@ -246,7 +266,7 @@ module Hanami
|
|
246
266
|
# @see Hanami::View.load!
|
247
267
|
def load!
|
248
268
|
super
|
249
|
-
|
269
|
+
load_registry!
|
250
270
|
end
|
251
271
|
|
252
272
|
private
|
@@ -260,6 +280,11 @@ module Hanami
|
|
260
280
|
def registry
|
261
281
|
@registry ||= Registry.new(self)
|
262
282
|
end
|
283
|
+
|
284
|
+
def load_registry!
|
285
|
+
@registry = nil
|
286
|
+
registry.freeze
|
287
|
+
end
|
263
288
|
end
|
264
289
|
end
|
265
290
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'hanami/view/rendering/null_local'
|
1
2
|
require 'hanami/utils/escape'
|
3
|
+
require 'hanami/utils/deprecation'
|
2
4
|
|
3
5
|
module Hanami
|
4
6
|
module View
|
@@ -16,7 +18,10 @@ module Hanami
|
|
16
18
|
# @api private
|
17
19
|
# @since 0.1.0
|
18
20
|
def initialize(layout, scope)
|
19
|
-
@layout
|
21
|
+
@layout = layout
|
22
|
+
@scope = scope
|
23
|
+
@view = nil
|
24
|
+
@locals = nil
|
20
25
|
end
|
21
26
|
|
22
27
|
# Returns the classname as string
|
@@ -122,6 +127,7 @@ module Hanami
|
|
122
127
|
# @return [String,NilClass] returning content if scope respond to the
|
123
128
|
# requested method
|
124
129
|
#
|
130
|
+
# @deprecated Use {#local} instead
|
125
131
|
# @since 0.4.1
|
126
132
|
#
|
127
133
|
# @example
|
@@ -157,9 +163,62 @@ module Hanami
|
|
157
163
|
# end
|
158
164
|
# end
|
159
165
|
def content(key)
|
166
|
+
Utils::Deprecation.new("#content is deprecated, please use #local")
|
160
167
|
__send__(key) if respond_to?(key)
|
161
168
|
end
|
162
169
|
|
170
|
+
# It tries to invoke a method for the view or a local for the given key.
|
171
|
+
# If the lookup fails, it returns a null object.
|
172
|
+
#
|
173
|
+
# @return [Objeect,Hanami::View::Rendering::NullLocal] the returning value
|
174
|
+
#
|
175
|
+
# @since 0.7.0
|
176
|
+
#
|
177
|
+
# @example Safe method navigation
|
178
|
+
# <% if local(:plan).overdue? %>
|
179
|
+
# <h2>Your plan is overdue.</h2>
|
180
|
+
# <% end %>
|
181
|
+
#
|
182
|
+
# @example Optional Contents
|
183
|
+
# # Given the following layout template
|
184
|
+
#
|
185
|
+
# <!doctype HTML>
|
186
|
+
# <html>
|
187
|
+
# <!-- ... -->
|
188
|
+
# <body>
|
189
|
+
# <!-- ... -->
|
190
|
+
# <%= local :footer %>
|
191
|
+
# </body>
|
192
|
+
# </html>
|
193
|
+
#
|
194
|
+
# # Case 1:
|
195
|
+
# # Products::Index doesn't respond to #footer, local will return nil
|
196
|
+
# #
|
197
|
+
# # Case 2:
|
198
|
+
# # Products::Show responds to #footer, local will send back
|
199
|
+
# # #footer returning value
|
200
|
+
#
|
201
|
+
# module Products
|
202
|
+
# class Index
|
203
|
+
# include Hanami::View
|
204
|
+
# end
|
205
|
+
#
|
206
|
+
# class Show
|
207
|
+
# include Hanami::View
|
208
|
+
#
|
209
|
+
# def footer
|
210
|
+
# "contents for footer"
|
211
|
+
# end
|
212
|
+
# end
|
213
|
+
# end
|
214
|
+
def local(key)
|
215
|
+
if respond_to?(key)
|
216
|
+
__send__(key)
|
217
|
+
else
|
218
|
+
locals.fetch(key) { NullLocal.new(key) }
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
163
222
|
# Implements "respond to" logic
|
164
223
|
#
|
165
224
|
# @return [TrueClass,FalseClass]
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'hanami/utils/basic_object'
|
2
|
+
|
3
|
+
module Hanami
|
4
|
+
module View
|
5
|
+
module Rendering
|
6
|
+
# Null local
|
7
|
+
#
|
8
|
+
# @since 0.7.0
|
9
|
+
#
|
10
|
+
# @see Hanami::View::Rendering#local
|
11
|
+
class NullLocal < Utils::BasicObject
|
12
|
+
# @since 0.7.0
|
13
|
+
# @api private
|
14
|
+
TO_STR = "".freeze
|
15
|
+
|
16
|
+
# @since 0.7.0
|
17
|
+
# @api private
|
18
|
+
def initialize(local)
|
19
|
+
@local = local
|
20
|
+
end
|
21
|
+
|
22
|
+
# @since 0.7.0
|
23
|
+
def all?
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
# @since 0.7.0
|
28
|
+
def any?
|
29
|
+
false
|
30
|
+
end
|
31
|
+
|
32
|
+
# @since 0.7.0
|
33
|
+
def empty?
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
# @since 0.7.0
|
38
|
+
def nil?
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
# @since 0.7.0
|
43
|
+
# @api private
|
44
|
+
def to_str
|
45
|
+
TO_STR
|
46
|
+
end
|
47
|
+
|
48
|
+
# @since 0.7.0
|
49
|
+
# @api private
|
50
|
+
def method_missing(m, *)
|
51
|
+
if m.match(/\?\z/)
|
52
|
+
false
|
53
|
+
else
|
54
|
+
self.class.new("#{ @local }.#{ m }")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# @since 0.7.0
|
61
|
+
# @api private
|
62
|
+
def respond_to_missing?(method_name, include_all)
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
# @since 0.7.0
|
67
|
+
# @api private
|
68
|
+
def __inspect
|
69
|
+
" :#{ @local }"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Hanami
|
2
2
|
module View
|
3
3
|
module Rendering
|
4
|
-
# @since
|
4
|
+
# @since 0.7.0
|
5
5
|
# @api private
|
6
6
|
class PartialFile
|
7
7
|
attr_reader :key, :format, :template
|
8
8
|
|
9
|
-
# @since
|
9
|
+
# @since 0.7.0
|
10
10
|
# @api private
|
11
11
|
def initialize(key, format, template)
|
12
12
|
@key = key
|
@@ -7,18 +7,18 @@ module Hanami
|
|
7
7
|
# Find partial templates in the file system
|
8
8
|
#
|
9
9
|
# @api private
|
10
|
-
# @since
|
10
|
+
# @since 0.7.0
|
11
11
|
#
|
12
12
|
# @see View::Template
|
13
13
|
class PartialTemplatesFinder
|
14
14
|
# Search pattern for partial file names
|
15
15
|
#
|
16
16
|
# @api private
|
17
|
-
# @since
|
17
|
+
# @since 0.7.0
|
18
18
|
PARTIAL_PATTERN = '_*'.freeze
|
19
19
|
|
20
20
|
# @api private
|
21
|
-
# @since
|
21
|
+
# @since 0.7.0
|
22
22
|
PARTIAL_PARTS_SEPARATOR = '.'.freeze
|
23
23
|
|
24
24
|
attr_reader :configuration
|
@@ -27,7 +27,7 @@ module Hanami
|
|
27
27
|
#
|
28
28
|
# @param configuration [Configuration] the configuration object
|
29
29
|
#
|
30
|
-
# @since
|
30
|
+
# @since 0.7.0
|
31
31
|
def initialize(configuration)
|
32
32
|
@configuration = configuration
|
33
33
|
end
|
@@ -36,7 +36,7 @@ module Hanami
|
|
36
36
|
#
|
37
37
|
# @return [Array] array of PartialFinder objects
|
38
38
|
#
|
39
|
-
# @since
|
39
|
+
# @since 0.7.0
|
40
40
|
def find
|
41
41
|
_find_partials(configuration.root).map do |template|
|
42
42
|
partial_path, partial_base_name = Pathname(template).relative_path_from(configuration.root).split
|
@@ -58,7 +58,7 @@ module Hanami
|
|
58
58
|
#
|
59
59
|
# @return [Array] an array of strings for each matching partial template file found
|
60
60
|
#
|
61
|
-
# @since
|
61
|
+
# @since 0.7.0
|
62
62
|
# @api private
|
63
63
|
def _find_partials(path)
|
64
64
|
Dir.glob("#{ [path, TemplatesFinder::RECURSIVE, PARTIAL_PATTERN].join(::File::SEPARATOR) }.#{TemplatesFinder::FORMAT}.#{TemplatesFinder::ENGINES}")
|
@@ -78,8 +78,23 @@ module Hanami
|
|
78
78
|
|
79
79
|
# @api private
|
80
80
|
# @since 0.4.3
|
81
|
+
#
|
82
|
+
# Searches first for files at `../templates/articles/index.*.*`
|
83
|
+
# If none are found, falls back to recursive search in `../templates/**/articles/index.*.*`
|
84
|
+
#
|
81
85
|
def _find(lookup = search_path)
|
82
|
-
|
86
|
+
base_path = templates_path(root, template_name)
|
87
|
+
if base_path.none?
|
88
|
+
templates_path(root, lookup, template_name)
|
89
|
+
else
|
90
|
+
base_path
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# @api private
|
95
|
+
# @since 0.7.0
|
96
|
+
def templates_path(*parts)
|
97
|
+
Dir.glob("#{ parts.join(separator) }.#{ format }.#{ engines }")
|
83
98
|
end
|
84
99
|
|
85
100
|
# @api private
|
data/lib/hanami/view/version.rb
CHANGED
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: 0.
|
4
|
+
version: 0.7.0
|
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: 2016-
|
13
|
+
date: 2016-07-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: tilt
|
@@ -38,14 +38,14 @@ dependencies:
|
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '0.
|
41
|
+
version: '0.8'
|
42
42
|
type: :runtime
|
43
43
|
prerelease: false
|
44
44
|
version_requirements: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '0.
|
48
|
+
version: '0.8'
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: bundler
|
51
51
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,14 +80,14 @@ dependencies:
|
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
83
|
+
version: '11'
|
84
84
|
type: :development
|
85
85
|
prerelease: false
|
86
86
|
version_requirements: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
88
|
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: '
|
90
|
+
version: '11'
|
91
91
|
description: View layer for Hanami
|
92
92
|
email:
|
93
93
|
- me@lucaguidi.com
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/hanami/view/rendering/layout_registry.rb
|
116
116
|
- lib/hanami/view/rendering/layout_scope.rb
|
117
117
|
- lib/hanami/view/rendering/null_layout.rb
|
118
|
+
- lib/hanami/view/rendering/null_local.rb
|
118
119
|
- lib/hanami/view/rendering/null_template.rb
|
119
120
|
- lib/hanami/view/rendering/partial.rb
|
120
121
|
- lib/hanami/view/rendering/partial_file.rb
|
@@ -141,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
142
|
requirements:
|
142
143
|
- - ">="
|
143
144
|
- !ruby/object:Gem::Version
|
144
|
-
version: 2.
|
145
|
+
version: 2.2.0
|
145
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
147
|
requirements:
|
147
148
|
- - ">="
|
@@ -149,9 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
150
|
version: '0'
|
150
151
|
requirements: []
|
151
152
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.6.4
|
153
154
|
signing_key:
|
154
155
|
specification_version: 4
|
155
156
|
summary: View layer for Hanami, with a separation between views and templates
|
156
157
|
test_files: []
|
157
|
-
has_rdoc:
|