/
rendering.rb
59 lines (49 loc) · 1.37 KB
/
rendering.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true
module Hanami
class View
# @api private
# @since 2.1.0
class Rendering
# @api private
# @since 2.1.0
attr_reader :config, :format
# @api private
# @since 2.1.0
attr_reader :inflector, :part_builder, :scope_builder
# @api private
# @since 2.1.0
attr_reader :context, :renderer
# @api private
# @since 2.1.0
def initialize(config:, format:, context:)
@config = config
@format = format
@inflector = config.inflector
@part_builder = config.part_builder
@scope_builder = config.scope_builder
@context = context.dup_for_rendering(self)
@renderer = Renderer.new(config)
end
# @api private
# @since 2.1.0
def template(name, scope, &block)
renderer.template(name, format, scope, &block)
end
# @api private
# @since 2.1.0
def partial(name, scope, &block)
renderer.partial(name, format, scope, &block)
end
# @api private
# @since 2.1.0
def part(name, value, as: nil)
part_builder.(name, value, as: as, rendering: self)
end
# @api private
# @since 2.1.0
def scope(name = nil, locals) # rubocop:disable Style/OptionalArguments
scope_builder.(name, locals: locals, rendering: self)
end
end
end
end