module Gyro::Template

Gyro Template Helper

Public Class Methods

config() click to toggle source

Hash of Yaml config for templates

# File lib/gyro/template.rb, line 136
def self.config
  @config ||= YAML.load_file(Gyro::Template.directory + 'config.yml')
end
directory() click to toggle source

Returns the Pathname representing the directory where all bundled templates are located

# File lib/gyro/template.rb, line 79
def self.directory
  Pathname.new(File.dirname(__FILE__)) + '../templates'
end
find(template_param, fail_on_error = true) click to toggle source

@param [String] template_param

The name or path of the template to find

@return [Pathname]

The path to the template corresponding to that name or path
# File lib/gyro/template.rb, line 100
def self.find(template_param, fail_on_error = true)
  template = if template_param.include?('/')
               find_by_path(template_param)
             else
               find_by_name(template_param)
             end
  if template.nil? && fail_on_error
    Gyro::Log.fail!('You need to specify a valid template directory or name' \
                    ' using the --template parameter (see --help for more info)')
  end
  template
end
find_by_name(name) click to toggle source

@param [String] name

The name of the template to find among the templates bundled with gyro

@return [Pathname]

The path to the template corresponding to that name or path
# File lib/gyro/template.rb, line 128
def self.find_by_name(name)
  target = Gyro::Template.resolve_alias(name)
  template_dir = Gyro::Template.directory + (target || name)
  return template_dir if template_dir.directory?
end
find_by_path(path) click to toggle source

@param [String] path

The path to the template to find

@return [Pathname]

The path to the template corresponding to that name or path
# File lib/gyro/template.rb, line 118
def self.find_by_path(path)
  template_dir = Pathname.new(path)
  return template_dir if template_dir.directory?
end
print_infos(template) click to toggle source
print_list() click to toggle source

Print template list representation

print_templates(array) click to toggle source
resolve_alias(name) click to toggle source

@param [Pathname] entry

The alias to resolve

@return [String]

The alias target name
Or nil if the entry does not correspond to a valid template alias
# File lib/gyro/template.rb, line 89
def self.resolve_alias(name)
  target = config['alias'][name]
  return nil unless target
  target
end
select_deprecated_templates(directories) click to toggle source

Select deprecated templates from the config file

@param [Array<String>] directories

The array of directories name

@return [Array<String>]

The array of deprecated templates
# File lib/gyro/template.rb, line 37
def self.select_deprecated_templates(directories)
  config['deprecated'].select { |t| config['alias'].key?(t) || directories.include?(t) }
end
select_non_deprecated_templates(directories) click to toggle source

Select non deprecated templates from the template directory and the config file

@param [Array<String>] directories

The array of directories name

@return [Array<String>]

The array of non deprecated templates
# File lib/gyro/template.rb, line 48
def self.select_non_deprecated_templates(directories)
  (directories + config['alias'].keys).reject { |t| config['deprecated'].include?(t) }
end