Sha256: 7447a9ced92dbd1caadf7ac91c8d6e53b91344abba35868025f7e6d4f21a8935

Contents?: true

Size: 1.03 KB

Versions: 22

Compression:

Stored size: 1.03 KB

Contents

require 'pathname'
require 'fileutils'
require 'yaml'
require 'securerandom'

require 'ecrire/commands/base'

module Ecrire
  module Commands
    class New < Ecrire::Commands::Base
      attr_reader :path
      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

      def run!
        if Dir.exist?(@path)
          ask_to_overwrite!
          FileUtils.rm_rf(@path)
        end
        generate!
      end

      def generate!
        Dir.mkdir @path
        Dir.chdir @path
        template = File.expand_path '../../theme/template/*', __FILE__
        FileUtils.cp_r(Dir[template], @path)
      end

      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
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ecrire-0.31.2 lib/ecrire/commands/new.rb
ecrire-0.31.1 lib/ecrire/commands/new.rb
ecrire-0.31.0 lib/ecrire/commands/new.rb
ecrire-0.30.3 lib/ecrire/commands/new.rb
ecrire-0.30.2 lib/ecrire/commands/new.rb
ecrire-0.30.1 lib/ecrire/commands/new.rb
ecrire-0.30.0 lib/ecrire/commands/new.rb
ecrire-0.29.0 lib/ecrire/commands/new.rb
ecrire-0.28.3 lib/ecrire/commands/new.rb
ecrire-0.28.2 lib/ecrire/commands/new.rb
ecrire-0.28.1 lib/ecrire/commands/new.rb
ecrire-0.28.0 lib/ecrire/commands/new.rb
ecrire-0.27.0 lib/ecrire/commands/new.rb
ecrire-0.26.3 lib/ecrire/commands/new.rb
ecrire-0.26.2 lib/ecrire/commands/new.rb
ecrire-0.26.1 lib/ecrire/commands/new.rb
ecrire-0.26.0 lib/ecrire/commands/new.rb
ecrire-0.25.2 lib/ecrire/commands/new.rb
ecrire-0.25.1 lib/ecrire/commands/new.rb
ecrire-0.25.0 lib/ecrire/commands/new.rb