class Hyla::Commands::New

Public Class Methods

create_blank_project(path) click to toggle source

Create Blank Project with just a readme.adoc file and yaml config file

# File lib/hyla/commands/new.rb, line 87
def self.create_blank_project(path)
  Dir.chdir(path) do
    f = File.open('readme.adoc', 'w')
    f.puts @readme_content
  end
end
create_sample_project(path, type) click to toggle source

Create a Sample Project from a Template (asciidoc, slideshow) and add styles

# File lib/hyla/commands/new.rb, line 99
def self.create_sample_project(path, type)
  source = [Configuration::templates, type] * '/' + '/.'
  FileUtils.cp_r source, path

  # Add yaml config file
  FileUtils.cp_r [Configuration::configs, Configuration::YAML_CONFIG_FILE_NAME] * '/', path
end
preserve_content?(path) click to toggle source

Preserve source location is folder is not empty

# File lib/hyla/commands/new.rb, line 109
def self.preserve_content?(path)
  !Dir["#{path}/**/*"].empty?
end
process(args, options = {}) click to toggle source
# File lib/hyla/commands/new.rb, line 19
def self.process(args, options = {})

  # out_dir = options[:destination] if self.check_mandatory_option?('-d / --destination', options[:destination])
  out_dir = args.first;

  #
  # Calculate project path (rel/absolute)
  #
  new_project_path = File.expand_path(out_dir, Dir.pwd)

  if Dir.exist? new_project_path

    Hyla.logger2.debug("Dir exists: #{new_project_path}")

    # If force is selected, then we delete & recreate it to clean content
    if options[:force]
      Hyla.logger2.debug("Force option selected")
      # DOES NOT WORK ON Mac OS X
      # FileUtils.rmdir(new_project_path)
      FileUtils.rm_rf new_project_path
      # Create Directory
      FileUtils.mkdir_p new_project_path
      Hyla.logger2.debug("Dir recreated")
    end

    # Preserve content if it exists
    if preserve_content?(new_project_path)
      Hyla.logger2.error "Conflict: #{new_project_path} exists and is not empty."
      exit(1)
    end

  else
    # Create Directory when it does not exist
    FileUtils.mkdir_p new_project_path
  end

  #
  # Create blank project
  # or copy sample project from template directory
  #igs
  if options[:blank]
    create_blank_project new_project_path

    # Add yaml config file
    FileUtils.cp_r [Configuration::configs, Configuration::YAML_CONFIG_FILE_NAME] * '/', new_project_path

    # Copy styles
    FileUtils.cp_r Configuration::styles, new_project_path

    Hyla.logger2.info("Blank project created")

  else
    raise ArgumentError.new('You must specifiy a template type.') if options[:template_type].nil?

    create_sample_project(new_project_path, options[:template_type])

    # Copy styles
    FileUtils.cp_r Configuration::styles, new_project_path

    Hyla.logger2.info("Sample project created using template : #{options[:template_type]}")
  end

end