Class: Snp::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/snp/path.rb

Overview

Snp::Path

This class is intended to wrap the logic of finding the paths in which template and data files should be placed.

Example

Snp::Path.new.which('jquery') # => '/etc/snp/jquery.erb'

Instance Method Summary collapse

Instance Method Details

#absolute_pathsObject

Public: returns the list of absolute paths to the directories in which the templates should be looked.



13
14
15
# File 'lib/snp/path.rb', line 13

def absolute_paths
  dir_list.map { |d| File.expand_path(d) }
end

#which(template, extension) ⇒ Object

Public: resolves a template file by looking in the template path.

template - the template name. extension - the extension of the desired template.

Returns a string with the full path of the template file, or nil if it is not found.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/snp/path.rb', line 24

def which(template, extension)
  template_with_extension = with_extension(template, extension)

  path = absolute_paths.find do |path|
    File.exists?(File.join(path, template_with_extension))
  end

  if path
    File.join(path, template_with_extension)
  end
end