class Ecrire::Commands::New

Attributes

path[R]

Public Class Methods

new(options = {}, *args) click to toggle source
# File lib/ecrire/commands/new.rb, line 12
def initialize(options = {}, *args)
  if args[0].nil?
    puts 'Please specify a blog name.'
    puts 'Example: ecrire new blog.domain.com'
    exit
  end
  @path = Pathname.new(Dir.pwd)
  @path += args[0]
end

Public Instance Methods

ask_to_overwrite!() click to toggle source
# File lib/ecrire/commands/new.rb, line 37
def ask_to_overwrite!
  puts "You are about to overwrite #{@path} with a new theme."
  puts "Are you sure? [y/n]"
  confirm = STDIN.gets.chomp
  if confirm != 'y'
    exit
  end
end
generate!() click to toggle source
# File lib/ecrire/commands/new.rb, line 30
def generate!
  Dir.mkdir @path
  Dir.chdir @path
  template = File.expand_path '../../theme/template/*', __FILE__
  FileUtils.cp_r(Dir[template], @path)
end
run!() click to toggle source
# File lib/ecrire/commands/new.rb, line 22
def run!
  if Dir.exist?(@path)
    ask_to_overwrite!
    FileUtils.rm_rf(@path)
  end
  generate!
end