Module: Hisyo

Defined in:
lib/hisyo.rb,
lib/hisyo/cli.rb,
lib/hisyo/version.rb,
lib/hisyo/generator.rb

Defined Under Namespace

Modules: CLI

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.generate_project(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hisyo/generator.rb', line 4

def self.generate_project(options = {})
  root = options[:root] || Dir.pwd
  klass = options[:dryrun] ? FileUtils::NoWrite : FileUtils
  %w!lib config views public spec app/views app/assets db tmp log!.each do |dir|
    dir = File.join(root, dir)
    if File.directory?(dir)
      puts "\e[31mskip: \e[0m#{dir.gsub(root + "/", "")}/" if options[:verbose]
    else
      puts "\e[1m\e[32mcreate:  \e[0m#{dir.gsub(root + "/", "")}/" if options[:verbose]
      klass.mkdir_p dir
    end
  end

  skelton = File.expand_path("../../../data/generators/project", __FILE__)
  Dir.glob("#{skelton}/**/*", File::FNM_DOTMATCH) do |file|
    next if File.directory?(file)
    path = File.join(root, file.gsub(skelton, ""))
    if File.file?(path)
      puts "\e[31mskip: \e[0m#{path.gsub(root + "/", "")}/" if options[:verbose]
    else
      puts "\e[1m\e[32mcopy to: \e[0m#{path.gsub(root + "/", "")}" if options[:verbose]
      klass.cp(file, path)
    end
  end

  puts "Complete."
  puts "  $ cd #{root}/"
  puts '  $ rackup (or `rspec spec/`, `vim app/helpers.rb`, etc)'
end