Class: Stastic::Command::Create

Inherits:
Base
  • Object
show all
Defined in:
lib/stastic/commands/create.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = []) ⇒ Create

Returns a new instance of Create.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stastic/commands/create.rb', line 6

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/stastic/commands/create.rb', line 3

def name
  @name
end

#templateObject

Returns the value of attribute template.



4
5
6
# File 'lib/stastic/commands/create.rb', line 4

def template
  @template
end

Instance Method Details

#indexObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/stastic/commands/create.rb', line 29

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