class EhcCommandTasks

Constants

COMMAND_WHITELIST
HELP_MESSAGE

Public Class Methods

new() click to toggle source
# File lib/ehc_command_tasks.rb, line 18
def initialize
  command = parse_command
  if COMMAND_WHITELIST.include?(command)
    send(command)
  else
    print_error(command)
  end
end

Public Instance Methods

generate() click to toggle source
# File lib/ehc_command_tasks.rb, line 62
def generate
  require 'generator/generator'
  Generator::Generator.new.generate
end
help() click to toggle source
# File lib/ehc_command_tasks.rb, line 49
def help
  puts HELP_MESSAGE
end
init() click to toggle source
# File lib/ehc_command_tasks.rb, line 53
def init
  puts "Creating dev_root and web_root with sample websites"

  init_dev_root
  init_web_root

  puts "All done, use \e[32m'ehc server'\e[0m to start the development server."
end
parse_command() click to toggle source
# File lib/ehc_command_tasks.rb, line 27
def parse_command
  return "" if ARGV.empty?

  command =  ARGV.first

  if command == 'g'
    command = 'generate'
  elsif command == 's'
    command = 'server'
  end
  return command
end
print_error(command) click to toggle source
server() click to toggle source
# File lib/ehc_command_tasks.rb, line 67
def server
  $options = parse_server_options
  require 'easy_html_creator'
end

Private Instance Methods

init_dev_root() click to toggle source
# File lib/ehc_command_tasks.rb, line 74
def init_dev_root
  source_dir = File.expand_path(File.dirname(__FILE__))[0..-4]
  output_folder = "#{Dir.pwd}/dev_root"

  unless File.directory? output_folder
    FileUtils::mkdir_p output_folder
    FileUtils::copy_entry("#{source_dir}dev_root", output_folder)
  end
end
init_web_root() click to toggle source
# File lib/ehc_command_tasks.rb, line 84
def init_web_root
  unless File.directory? "#{Dir.pwd}/web_root"
    FileUtils::mkdir_p "#{Dir.pwd}/web_root"
  end
end
parse_server_options() click to toggle source
# File lib/ehc_command_tasks.rb, line 90
def parse_server_options
  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: example.rb [options]"

    options[:port] = 5678
    opts.on( '-p=n', '--port=n', 'Port number for the webserver' ) do |port|
      options[:port] = port
    end

    options[:ip] = '127.0.0.1'
    opts.on( '-i=s', '--ip-adres=s', 'Ip adres for the webserver on' ) do |ip|
      options[:ip] = ip
    end

    opts.on('-h', '--help', 'Display this screen') do
      puts opts
      exit
    end
  end.parse!
  options
end