Class: Ritsu::ProjectGenerators::DefaultGenerator

Inherits:
Ritsu::ProjectGenerator show all
Includes:
Utility
Defined in:
lib/ritsu/project_generators/default_generator.rb

Instance Attribute Summary

Attributes inherited from Ritsu::ProjectGenerator

#name

Instance Method Summary collapse

Methods included from Utility

platform

Methods inherited from Ritsu::ProjectGenerator

generator_classes, is_valid_generator_name?, validate_instance

Constructor Details

#initializeDefaultGenerator

Returns a new instance of DefaultGenerator.



16
17
18
# File 'lib/ritsu/project_generators/default_generator.rb', line 16

def initialize
  super("default")
end

Instance Method Details

#copy_file(filename) ⇒ Object



51
52
53
54
55
# File 'lib/ritsu/project_generators/default_generator.rb', line 51

def copy_file(filename)
  source_filename = source_path(filename)
  source_content = Files.read(source_filename)
  create_file(filename, source_content)
end

#create_dir(dirname) ⇒ Object



36
37
38
# File 'lib/ritsu/project_generators/default_generator.rb', line 36

def create_dir(dirname)
  FileRobot.create_dir(target_path(dirname))
end

#create_file(filename, content) ⇒ Object



40
41
42
# File 'lib/ritsu/project_generators/default_generator.rb', line 40

def create_file(filename, content)
  FileRobot.create_file(target_path(filename), content)
end

#create_file_from_erb(filename) ⇒ Object



44
45
46
47
48
49
# File 'lib/ritsu/project_generators/default_generator.rb', line 44

def create_file_from_erb(filename)
  template_filename = source_path(filename + ".erb")
  template_content = Files.read(template_filename)
  template = ERB.new(template_content)
  create_file(filename, template.result(binding))
end

#generate(project_name, location, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ritsu/project_generators/default_generator.rb', line 57

def generate(project_name, location, options={})
  @location = File.expand_path(location)
  @project_name = project_name

  create_dir("")

  create_dir("build")
  create_dir("meta")
  create_dir("src")
  create_dir("src/cmake_modules")

  create_file_from_erb("Thorfile")
  create_file_from_erb("meta/project.rb")
end

#source_dirObject



20
21
22
# File 'lib/ritsu/project_generators/default_generator.rb', line 20

def source_dir
  File.dirname(__FILE__) + "/default_generator_files"
end

#source_path(path) ⇒ Object



24
25
26
# File 'lib/ritsu/project_generators/default_generator.rb', line 24

def source_path(path)
  source_dir + "/" + path
end

#target_dirObject



28
29
30
# File 'lib/ritsu/project_generators/default_generator.rb', line 28

def target_dir
  return @location + "/" + @project_name
end

#target_path(path) ⇒ Object



32
33
34
# File 'lib/ritsu/project_generators/default_generator.rb', line 32

def target_path(path)
  target_dir + "/" + path
end