module Ryonan::Interactive

Public Class Methods

print_template_list(filer) click to toggle source
read_configs(template_root) click to toggle source
# File lib/ryonan/interactive.rb, line 39
def read_configs(template_root)
  puts 'Set the value to the variable in the template'
  variables = File.open(config_file_path(template_root)).readlines.map(&:chomp)
  variables.map { |line| read_config(line) }.to_h
end
read_template_name() click to toggle source
# File lib/ryonan/interactive.rb, line 24
      def read_template_name
        name = Readline.readline(<<~'EOS'.chomp + ' ')
            Input the destination directory name
            ( Deprecated: If the input is blank, to expand the template directory on one level up )
            ->
        EOS

        if name == Config.template_dir_name
          puts "#{Config.template_dir_name} will overlap with the template directory name"
          exit 1
        else
          name
        end
      end
select_template(filer) click to toggle source
# File lib/ryonan/interactive.rb, line 14
def select_template(filer)
  select = Readline.readline('Select Template[*] -> ')
  if select.match(/\d+/) && !filer.templatable_dirs[select.to_i].nil?
    filer.templatable_dirs[select.to_i]
  else
    puts 'The specified template does not exist'
    exit 1
  end
end

Private Class Methods

config_file_path(template_root) click to toggle source
# File lib/ryonan/interactive.rb, line 47
def config_file_path(template_root)
  "#{template_root}/#{Config.template_dir_name}/#{Config.config_file_name}"
end
read_config(line) click to toggle source
# File lib/ryonan/interactive.rb, line 51
def read_config(line)
  if line =~ /.+=/
    (variable_name, default) = line.split('=')
    input = Readline.readline("    #{variable_name} (Default: #{default}) -> ")
    variable_value = input.empty? ? default : input
  else
    variable_name = line
    variable_value = Readline.readline("    #{variable_name} -> ")
  end
  [variable_name, variable_value]
end