Sha256: 716d8b4f8d76c76eaf96d3cc09a955dd853d751171d383f179787da1675e4b5f
Contents?: true
Size: 1.78 KB
Versions: 1
Compression:
Stored size: 1.78 KB
Contents
module Stastic::Command class Create < Base attr_accessor :name attr_accessor :template def initialize(args = []) if Stastic::Config.site_defined? printf("A site already exists in this directory.\n\n") raise(Stastic::Command::InvalidOptions) end 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::Command::InvalidOptions) unless args.first == "--template" self.template = "default" self.name = args.last else raise(Stastic::Command::InvalidOptions) end end def index print "Creating site... " 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 "Success!\n" 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| next if ['.','..'].include? file s = File.join(src, file) d = File.join(dest, file) if File.directory?(s) FileUtils.cp_r(s, d) else FileUtils.cp(s,d) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stastic-0.2.7 | lib/stastic/commands/create.rb |