Class: Hyla::Commands::New

Inherits:
Hyla::Command show all
Defined in:
lib/hyla/commands/new.rb

Class Method Summary collapse

Methods inherited from Hyla::Command

check_mandatory_option?

Class Method Details

.create_blank_project(path) ⇒ Object

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



87
88
89
90
91
92
# 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) ⇒ Object

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



99
100
101
102
103
104
105
# 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) ⇒ Boolean

Preserve source location is folder is not empty

Returns:

  • (Boolean)


109
110
111
# File 'lib/hyla/commands/new.rb', line 109

def self.preserve_content?(path)
  !Dir["#{path}/**/*"].empty?
end

.process(args, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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