Sha256: 09f6789c7e7e2562e94b10e5f1d92dd342dbccfb9380f68de86d80e6191697a8

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module Stastic::Command
  class Create < Base
    attr_accessor :name
    attr_accessor :template

    def initialize(args = [])
      case args.size
      when 0
        self.name = nil
      when 1
        if args.first == "--template"
          self.template = "default"
        else
          self.name = args.first
        end
      when 2
        raise(Stastic::InvalidOptions) unless args.first == "--template"
        self.template = "default"
        self.name = args.last
        puts self.template
      else
        raise(Stastic::InvalidOptions)
      end
    end

    def index
      if template
        copy_template("#{File.dirname(__FILE__)}/../../../templates/#{template}/")
      end

      response = with_valid_user do
        Stastic::Client.create(name)
      end

      if response["id"]
        Stastic::Config.add(:site_id => response["id"])
      end

      if response["name"]
        Stastic::Config.add(:name => response["name"])
        print "Your site has been created!\n\n"
        print "  Site Name: #{Stastic::Config.name}\n"
        print "  Site URL:  #{Stastic::Config.name}.stastic.com\n\n"
        print "Use `stastic publish` to publish your site whenever you're ready.\n"
      end

    end

    private

      def copy_template(src)
        dest = Dir.pwd
        Dir.foreach(src) do |file|
          s = File.join(src, file)
          d = File.join(dest, file)

          if File.directory?(s)
            FileUtils.cp_r(s, d, :preserve => true)
          else
            FileUtils.cp(s,d, :preserve => true)
          end
        end

      end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stastic-0.2.0 lib/stastic/commands/create.rb