Module: Mimas::Template

Included in:
CLI::Commands::BaseCommand, Deployment, Server
Defined in:
lib/mimas/template.rb

Constant Summary collapse

BASE_DIRECTORY =
Pathname.new(__dir__).join("templates")

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.lookup_pathsObject



24
25
26
# File 'lib/mimas/template.rb', line 24

def self.lookup_paths
  MUTEX.synchronize { @lookup_paths ||= [BASE_DIRECTORY] }
end

Instance Method Details

#copy_file(destination, source_file_name, rename: nil) ⇒ Object



18
19
20
21
# File 'lib/mimas/template.rb', line 18

def copy_file(destination, source_file_name, rename: nil)
  source = find_in_lookup_paths(source_file_name)
  FileUtils.copy(source, File.join(destination, rename || source_file_name))
end

#read_file(file_name, dir: nil) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/mimas/template.rb', line 10

def read_file(file_name, dir: nil)
  if dir
    File.read(File.join(dir, file_name))
  else
    File.read(find_in_lookup_paths(file_name))
  end
end

#template(file_name, dir: nil, **vars) ⇒ Object



5
6
7
8
# File 'lib/mimas/template.rb', line 5

def template(file_name, dir: nil, **vars)
  template = read_template(file_name, dir: dir)
  template.result_with_hash(vars)
end