Module: Kckstrt

Extended by:
GLI::App
Defined in:
lib/kckstrt.rb,
lib/kckstrt/version.rb

Constant Summary collapse

VERSION =
'0.0.4'

Class Method Summary collapse

Class Method Details

.copy_templates(dest) ⇒ Object



47
48
49
50
# File 'lib/kckstrt.rb', line 47

def self.copy_templates(dest)
  src = File.expand_path('../kckstrt/templates', __FILE__)
  FileUtils.copy_entry(src, dest)
end

.generate_app(app_name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kckstrt.rb', line 27

def self.generate_app(app_name)
  return say('Please specify an app name. See `kckstrt generate --help`.') unless app_name

  @dirname = app_name.underscore
  @app_name = @dirname.camelize

  mkdir(@dirname)
  copy_templates(@dirname)
  init_templates

  say("=> cd #{@dirname} && script/setup")
end

.init_templatesObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/kckstrt.rb', line 52

def self.init_templates
  Dir["#{@dirname}/**/*.template"].each do |file|
    template = File.read(file)
    content = Erubis::Eruby.new(template, pattern: '{{ }}').result(binding)

    File.open(file, 'w+') do |f|
      f.write(content)
    end

    File.rename(file, file.sub('.template', ''))
  end
end

.mkdir(dirname) ⇒ Object



40
41
42
43
44
45
# File 'lib/kckstrt.rb', line 40

def self.mkdir(dirname)
  return say("#{dirname}” folder is not empty. Use the --force flag to overwrite.") if File.directory?(dirname) && !@options[:force]

  FileUtils.rm_rf(dirname)
  Dir.mkdir(dirname)
end