Class: Dry::View::Renderer Private

Inherits:
Object
  • Object
show all
Extended by:
Core::Cache
Defined in:
lib/dry/view/renderer.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

PARTIAL_PREFIX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"_"
PATH_DELIMITER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths, format:, engine_mapping: nil, **options) ⇒ Renderer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Renderer.



21
22
23
24
25
26
# File 'lib/dry/view/renderer.rb', line 21

def initialize(paths, format:, engine_mapping: nil, **options)
  @paths = paths
  @format = format
  @engine_mapping = engine_mapping || {}
  @options = options
end

Instance Attribute Details

#engine_mappingObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/dry/view/renderer.rb', line 19

def engine_mapping
  @engine_mapping
end

#formatObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/dry/view/renderer.rb', line 19

def format
  @format
end

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/dry/view/renderer.rb', line 19

def options
  @options
end

#pathsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/dry/view/renderer.rb', line 19

def paths
  @paths
end

Instance Method Details

#chdir(dirname) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
55
56
# File 'lib/dry/view/renderer.rb', line 52

def chdir(dirname)
  new_paths = paths.map { |path| path.chdir(dirname) }

  self.class.new(new_paths, format: format, **options)
end

#partial(name, scope, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
41
42
43
44
45
46
# File 'lib/dry/view/renderer.rb', line 38

def partial(name, scope, &block)
  template(
    name_for_partial(name),
    scope,
    child_dirs: %w[shared],
    parent_dir: true,
    &block
  )
end

#render(path, scope, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/dry/view/renderer.rb', line 48

def render(path, scope, &block)
  tilt(path).render(scope, &block)
end

#template(name, scope, **lookup_options, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
34
35
36
# File 'lib/dry/view/renderer.rb', line 28

def template(name, scope, **lookup_options, &block)
  path = lookup(name, **lookup_options)

  if path
    render(path, scope, &block)
  else
    raise TemplateNotFoundError.new(name, paths)
  end
end