Module: Avm::Templates

Defined in:
lib/avm/templates.rb,
lib/avm/templates/file.rb,
lib/avm/templates/directory.rb

Defined Under Namespace

Classes: Directory, File

Class Method Summary collapse

Class Method Details

.included_pathsObject



31
32
33
# File 'lib/avm/templates.rb', line 31

def included_paths
  @included_paths ||= ::Set.new([::File.expand_path('../../template', __dir__)])
end

.template(subpath, required = true) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/avm/templates.rb', line 9

def template(subpath, required = true)
  path = template_path(subpath)
  if path.blank?
    return nil unless required

    raise "Template not found for subpath \"#{subpath}\" (Included paths: #{included_paths})"
  end
  return ::Avm::Templates::File.new(path) if ::File.file?(path)
  return ::Avm::Templates::Directory.new(path) if ::File.directory?(path)

  raise 'Invalid branching'
end

.template_path(subpath) ⇒ Object

Returns The absolute path of template if found, nil otherwise.

Returns:

  • The absolute path of template if found, nil otherwise.



23
24
25
26
27
28
29
# File 'lib/avm/templates.rb', line 23

def template_path(subpath)
  included_paths.each do |included_path|
    r = search_template_in_included_path(included_path, subpath)
    return r if r
  end
  nil
end