Class: Hanami::View::Renderer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/view/renderer.rb

Overview

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.

Since:

  • 2.1.0

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.

Since:

  • 2.1.0

"_"
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.

Since:

  • 2.1.0

"/"
CURRENT_PATH_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.

Since:

  • 2.1.0

"."

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ 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.

Since:

  • 2.1.0



28
29
30
31
# File 'lib/hanami/view/renderer.rb', line 28

def initialize(config)
  @config = config
  @prefixes = [CURRENT_PATH_PREFIX]
end

Instance Attribute Details

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

Since:

  • 2.1.0



24
25
26
# File 'lib/hanami/view/renderer.rb', line 24

def config
  @config
end

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

Since:

  • 2.1.0



24
25
26
# File 'lib/hanami/view/renderer.rb', line 24

def prefixes
  @prefixes
end

Instance Method Details

#partial(name, format, 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.

Since:

  • 2.1.0



52
53
54
# File 'lib/hanami/view/renderer.rb', line 52

def partial(name, format, scope, &block)
  template(name_for_partial(name), format, scope, &block)
end

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

Since:

  • 2.1.0



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/hanami/view/renderer.rb', line 35

def template(name, format, scope, &block)
  old_prefixes = @prefixes.dup

  template_path = lookup(name, format)

  raise TemplateNotFoundError.new(name, format, config.paths) unless template_path

  new_prefix = File.dirname(name)
  @prefixes << new_prefix unless @prefixes.include?(new_prefix)

  render(template_path, scope, &block)
ensure
  @prefixes = old_prefixes
end