dry-view 0.5.0 → 0.5.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 +4 -4
- data/CHANGELOG.md +10 -2
- data/lib/dry/view/controller.rb +8 -0
- data/lib/dry/view/exposures.rb +8 -0
- data/lib/dry/view/version.rb +1 -1
- data/spec/fixtures/templates/users_with_count_inherit.html.slim +6 -0
- data/spec/integration/exposures_spec.rb +86 -0
- data/spec/unit/exposures_spec.rb +10 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b7142689536853b1e216512d00558c4edbaafe44ee3abc2d1e51eb1ad498bc1
|
4
|
+
data.tar.gz: 6373160c6fa073a52c9fa106b6f1c8ac0b58c088bbce26e29b4b65ff587dad27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0eaccf27fc9d7f29a8b3be6e9b695341738e67d98b132630d8ec6bc462683bdcfa4613ed59c00a8d3791f93789f4a5c437ee6dd2b66c5c893d52e537a3a93f51
|
7
|
+
data.tar.gz: a6b0bb154f5056de7b1bf6ca21d78e7ad9e1453dcc64d438d7f435e6285f236e0627d55838ba020bdf68749a4a1da577b6dc1e2cacc9e8b8993ba553d99a797d
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
+
# 0.5.1 / 2018-02-20
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
- Exposures are inherited from parent view controller classes (GustavoCaso)
|
6
|
+
|
7
|
+
[Compare v0.5.0...v0.5.1](https://github.com/dry-rb/dry-view/compare/v0.5.0...v0.5.1)
|
8
|
+
|
1
9
|
# 0.5.0 / 2018-01-23
|
2
10
|
|
3
11
|
### Added
|
4
12
|
|
5
|
-
|
6
|
-
|
13
|
+
- Support for parts with decorated attributes (timriley + GustavoCaso)
|
14
|
+
- Ability to easily create another part instance via `Part#new` (GustavoCaso)
|
7
15
|
|
8
16
|
[Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-view/compare/v0.4.0...v0.5.0)
|
9
17
|
|
data/lib/dry/view/controller.rb
CHANGED
@@ -33,6 +33,14 @@ module Dry
|
|
33
33
|
attr_reader :template_path
|
34
34
|
attr_reader :exposures
|
35
35
|
|
36
|
+
# @api private
|
37
|
+
def self.inherited(klass)
|
38
|
+
super
|
39
|
+
exposures.each do |name, exposure|
|
40
|
+
klass.exposures.import(name, exposure)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
36
44
|
# @api public
|
37
45
|
def self.paths
|
38
46
|
Array(config.paths).map { |path| Dry::View::Path.new(path) }
|
data/lib/dry/view/exposures.rb
CHANGED
@@ -20,10 +20,18 @@ module Dry
|
|
20
20
|
exposures[name]
|
21
21
|
end
|
22
22
|
|
23
|
+
def each(&block)
|
24
|
+
exposures.each(&block)
|
25
|
+
end
|
26
|
+
|
23
27
|
def add(name, proc = nil, **options)
|
24
28
|
exposures[name] = Exposure.new(name, proc, options)
|
25
29
|
end
|
26
30
|
|
31
|
+
def import(name, exposure)
|
32
|
+
exposures[name] = exposure.dup
|
33
|
+
end
|
34
|
+
|
27
35
|
def bind(obj)
|
28
36
|
bound_exposures = exposures.each_with_object({}) { |(name, exposure), memo|
|
29
37
|
memo[name] = exposure.bind(obj)
|
data/lib/dry/view/version.rb
CHANGED
@@ -303,4 +303,90 @@ RSpec.describe 'exposures' do
|
|
303
303
|
expect(vc.locals(input)).to include(:users, :users_count)
|
304
304
|
expect(vc.locals(input)).not_to include(:prefix)
|
305
305
|
end
|
306
|
+
|
307
|
+
it 'inherit exposures from parent class' do
|
308
|
+
parent = Class.new(Dry::View::Controller) do
|
309
|
+
configure do |config|
|
310
|
+
config.paths = SPEC_ROOT.join('fixtures/templates')
|
311
|
+
config.layout = 'app'
|
312
|
+
config.template = 'users_with_count_inherit'
|
313
|
+
config.default_format = :html
|
314
|
+
end
|
315
|
+
|
316
|
+
private_expose :prefix do
|
317
|
+
"COUNT: "
|
318
|
+
end
|
319
|
+
|
320
|
+
expose :users
|
321
|
+
|
322
|
+
expose :users_count do |prefix, users:|
|
323
|
+
"#{prefix}#{users.length} users"
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
child = Class.new(parent) do
|
328
|
+
expose :child_expose do
|
329
|
+
'Child expose'
|
330
|
+
end
|
331
|
+
end.new
|
332
|
+
|
333
|
+
users = [
|
334
|
+
{name: 'Jane', email: 'jane@doe.org'},
|
335
|
+
{name: 'Joe', email: 'joe@doe.org'}
|
336
|
+
]
|
337
|
+
|
338
|
+
input = {users: users, context: context}
|
339
|
+
|
340
|
+
expect(child.(input)).to eql(
|
341
|
+
'<!DOCTYPE html><html><head><title>dry-view rocks!</title></head><body><ul><li>Jane (jane@doe.org)</li><li>Joe (joe@doe.org)</li></ul><div class="count">COUNT: 2 users</div><div class="inherit">Child expose</div></body></html>'
|
342
|
+
)
|
343
|
+
|
344
|
+
expect(child.locals(input)).to include(:users, :users_count, :child_expose)
|
345
|
+
expect(child.locals(input)).not_to include(:prefix)
|
346
|
+
end
|
347
|
+
|
348
|
+
it 'inherit exposures from parent class and allow to override them' do
|
349
|
+
parent = Class.new(Dry::View::Controller) do
|
350
|
+
configure do |config|
|
351
|
+
config.paths = SPEC_ROOT.join('fixtures/templates')
|
352
|
+
config.layout = 'app'
|
353
|
+
config.template = 'users_with_count_inherit'
|
354
|
+
config.default_format = :html
|
355
|
+
end
|
356
|
+
|
357
|
+
private_expose :prefix do
|
358
|
+
"COUNT: "
|
359
|
+
end
|
360
|
+
|
361
|
+
expose :users
|
362
|
+
|
363
|
+
expose :users_count do |prefix, users:|
|
364
|
+
"#{prefix}#{users.length} users"
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
child = Class.new(parent) do
|
369
|
+
expose :child_expose do
|
370
|
+
'Child expose'
|
371
|
+
end
|
372
|
+
|
373
|
+
expose :users_count do |prefix, users:|
|
374
|
+
"#{prefix}#{users.length} users overrided"
|
375
|
+
end
|
376
|
+
end.new
|
377
|
+
|
378
|
+
users = [
|
379
|
+
{name: 'Jane', email: 'jane@doe.org'},
|
380
|
+
{name: 'Joe', email: 'joe@doe.org'}
|
381
|
+
]
|
382
|
+
|
383
|
+
input = {users: users, context: context}
|
384
|
+
|
385
|
+
expect(child.(input)).to eql(
|
386
|
+
'<!DOCTYPE html><html><head><title>dry-view rocks!</title></head><body><ul><li>Jane (jane@doe.org)</li><li>Joe (joe@doe.org)</li></ul><div class="count">COUNT: 2 users overrided</div><div class="inherit">Child expose</div></body></html>'
|
387
|
+
)
|
388
|
+
|
389
|
+
expect(child.locals(input)).to include(:users, :users_count, :child_expose)
|
390
|
+
expect(child.locals(input)).not_to include(:prefix)
|
391
|
+
end
|
306
392
|
end
|
data/spec/unit/exposures_spec.rb
CHANGED
@@ -90,4 +90,14 @@ RSpec.describe Dry::View::Exposures do
|
|
90
90
|
expect(locals).to eq(:name=>"WILLIAM")
|
91
91
|
end
|
92
92
|
end
|
93
|
+
|
94
|
+
describe "#import" do
|
95
|
+
it "imports a exposure to the exposures" do
|
96
|
+
exposures_b = described_class.new
|
97
|
+
exposures.add(:name, -> name: { name.upcase }, default: 'John')
|
98
|
+
exposures_b.import(:name, exposures[:name])
|
99
|
+
|
100
|
+
expect(exposures_b[:name]).to eq(exposures[:name])
|
101
|
+
end
|
102
|
+
end
|
93
103
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tilt
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- spec/fixtures/templates/users/_row.html.slim
|
162
162
|
- spec/fixtures/templates/users/_tbody.html.slim
|
163
163
|
- spec/fixtures/templates/users_with_count.html.slim
|
164
|
+
- spec/fixtures/templates/users_with_count_inherit.html.slim
|
164
165
|
- spec/fixtures/templates_override/_hello.html.slim
|
165
166
|
- spec/fixtures/templates_override/users.html.slim
|
166
167
|
- spec/integration/decorator_spec.rb
|
@@ -195,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
196
|
version: '0'
|
196
197
|
requirements: []
|
197
198
|
rubyforge_project:
|
198
|
-
rubygems_version: 2.7.
|
199
|
+
rubygems_version: 2.7.5
|
199
200
|
signing_key:
|
200
201
|
specification_version: 4
|
201
202
|
summary: Functional view rendering system
|
@@ -219,6 +220,7 @@ test_files:
|
|
219
220
|
- spec/fixtures/templates/users/_row.html.slim
|
220
221
|
- spec/fixtures/templates/users/_tbody.html.slim
|
221
222
|
- spec/fixtures/templates/users_with_count.html.slim
|
223
|
+
- spec/fixtures/templates/users_with_count_inherit.html.slim
|
222
224
|
- spec/fixtures/templates_override/_hello.html.slim
|
223
225
|
- spec/fixtures/templates_override/users.html.slim
|
224
226
|
- spec/integration/decorator_spec.rb
|