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.

"/"
TemplateNotFoundError =

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.

Class.new(StandardError)

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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

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

#lookup(name) ⇒ 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.



54
55
56
57
58
59
# File 'lib/dry/view/renderer.rb', line 54

def lookup(name)
  paths.inject(false) { |_, path|
    result = path.lookup(name, format, include_shared: false)
    break result if result
  }
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.



40
41
42
# File 'lib/dry/view/renderer.rb', line 40

def partial(name, scope, &block)
  template(name_for_partial(name), scope, &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.



44
45
46
# File 'lib/dry/view/renderer.rb', line 44

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

#template(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.



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

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

  if path
    render(path, scope, &block)
  else
    msg = "Template #{name.inspect} could not be found in paths:\n#{paths.map { |pa| "- #{pa.to_s}" }.join("\n")}"
    raise TemplateNotFoundError, msg
  end
end