Class: Hanami::View::Rendering::PartialTemplatesFinder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/view/rendering/partial_templates_finder.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.

Find partial templates in the file system

See Also:

Since:

  • 0.7.0

Constant Summary collapse

PARTIAL_PATTERN =

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.

Search pattern for partial file names

Since:

  • 0.7.0

'_*'.freeze
PARTIAL_PARTS_SEPARATOR =

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:

  • 0.7.0

'.'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ PartialTemplatesFinder

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.

Initializes a new PartialTemplatesFinder

Parameters:

Since:

  • 0.7.0



34
35
36
# File 'lib/hanami/view/rendering/partial_templates_finder.rb', line 34

def initialize(configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (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:

  • 0.7.0



26
27
28
# File 'lib/hanami/view/rendering/partial_templates_finder.rb', line 26

def configuration
  @configuration
end

Instance Method Details

#findArray

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.

Find partials under the given path

Returns:

  • (Array)

    array of PartialFinder objects

Since:

  • 0.7.0



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hanami/view/rendering/partial_templates_finder.rb', line 44

def find
  _find_partials(configuration.root).map do |template|
    partial_path, partial_base_name = Pathname(template).relative_path_from(configuration.root).split
    partial_base_parts              = partial_base_name.to_s.split(PARTIAL_PARTS_SEPARATOR)

    PartialFile.new(
      "#{partial_path}#{::File::SEPARATOR}#{partial_base_parts[0]}",
      partial_base_parts[1],
      View::Template.new(template, configuration.default_encoding)
    )
  end
end