Class: Lattice::Generators::AppBase

Inherits:
Object
  • Object
show all
Includes:
Lattice::Generator
Defined in:
lib/lattice/generators/app_base.rb

Constant Summary collapse

DEFAULT_APP_TEMPLATE =
File.expand_path("../../../../template", __FILE__)

Instance Method Summary collapse

Methods included from Lattice::Generator

#generate_directory, #generate_file, #ohai

Constructor Details

#initialize(name, options = {}) ⇒ AppBase

Returns a new instance of AppBase.



11
12
13
14
15
16
# File 'lib/lattice/generators/app_base.rb', line 11

def initialize(name, options = {})
  @name = name.to_s
  @app_const_base = @name.camelize

  @template_path = options[:template_path] || DEFAULT_APP_TEMPLATE
end

Instance Method Details

#generate(app_root) ⇒ Object

Generate a Lattice application at the given path



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lattice/generators/app_base.rb', line 19

def generate(app_root)
  app_root = File.expand_path(app_root)

  # Is this a brand spankin' new app?
  new_app = !File.exists?(app_root)

  template_paths = Dir[File.join(@template_path, '**', '*')]
  raise "No templates found. Something's wrong? :(" if template_paths.empty?

  template_paths.each do |input_path|
    relative_path = input_path.sub(@template_path, '')
    output_path   = File.join(app_root, relative_path)

    if File.directory?(input_path)
      generate_directory(output_path)
    else
      generate_file(input_path, output_path)
    end
  end

  ohai "NOTE: Don't forget to: ".light_yellow +
       "cd #{app_root} && bundle".light_white
end