Class: Vipergen::TemplateManager

Inherits:
Object
  • Object
show all
Defined in:
lib/vipergen/templatemanager.rb

Class Method Summary collapse

Class Method Details

.template_description(template_path) ⇒ Object

Returns the description of a given template

Parameters:

  • template

    String with the template path whose description is going to be returned

Returns:

  • String with the template description



43
44
45
46
47
48
49
50
51
# File 'lib/vipergen/templatemanager.rb', line 43

def self.template_description(template_path)
  template_description = ""

  # Reading yaml
  template_content = YAML.load_file(File.join(template_path,'viperspec.yml'))

  # Generating string
  template_description+= "| #{template_name_from_path(template_path)} by #{template_content["author"]} |: #{template_content["template_description"]}"
end

.template_name_from_path(template_path) ⇒ Object

Returns the template name from a given template_path

Returns:

  • String with the template name



25
26
27
# File 'lib/vipergen/templatemanager.rb', line 25

def self.template_name_from_path(template_path)
  return template_path.split("/").last
end

.templatesObject

Get the templates names



19
20
21
# File 'lib/vipergen/templatemanager.rb', line 19

def self.templates()
  templates_paths.map{|template_path| template_name_from_path(template_path)}
end

.templates_descriptionObject

Returns the description of all the templates available

Returns:

  • String with the entire description



31
32
33
34
35
36
37
38
# File 'lib/vipergen/templatemanager.rb', line 31

def self.templates_description()
  description = "\nAvailable templates \n"
  description += "------------------- \n"
  self.templates_paths.each do |template_path|
    description += "> #{template_description(template_path)} \n"
  end
  return description
end

.templates_dirObject

Returns the templates dir



6
7
8
# File 'lib/vipergen/templatemanager.rb', line 6

def self.templates_dir
  t = "#{File.expand_path File.dirname(__FILE__)}/../templates"
end

.templates_pathsObject

Get the available templates paths



12
13
14
15
# File 'lib/vipergen/templatemanager.rb', line 12

def self.templates_paths()
  template_dir = Vipergen::TemplateManager.templates_dir
  return Vipergen::DirUtils.directories_in(template_dir)
end