Class: Staticpress::CLI

Inherits:
Thor
  • Object
show all
Includes:
Helpers, Thor::Actions
Defined in:
lib/staticpress/cli.rb

Instance Method Summary collapse

Methods included from Helpers

#config, #extensionless_basename, #extensionless_path, #hash_from_array, #hash_from_match_data, #paginate, #settings, #spider_map, #titleize

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



19
20
21
22
# File 'lib/staticpress/cli.rb', line 19

def initialize(*args)
  super
  Staticpress::Settings.set! options
end

Instance Method Details

#buildObject



101
102
103
# File 'lib/staticpress/cli.rb', line 101

def build
  Staticpress::Site.new.save
end

#create(title) ⇒ Object



58
59
60
# File 'lib/staticpress/cli.rb', line 58

def create(title)
  Staticpress::Content::Post.create config.preferred_format, title
end

#create_page(title, path = nil) ⇒ Object



63
64
65
# File 'lib/staticpress/cli.rb', line 63

def create_page(title, path = nil)
  Staticpress::Content::Page.create config.preferred_format, title, path
end

#deployObject



116
117
118
# File 'lib/staticpress/cli.rb', line 116

def deploy
  build and push
end

#fork_plugin(name, new_name = nil) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/staticpress/cli.rb', line 73

def fork_plugin(name, new_name = nil)
  source = Staticpress::Plugin.find name

  destination_name = new_name ? (new_name.end_with?('.rb') ? new_name : "#{new_name}.rb") : source.basename
  destination = Staticpress.blog_path + (config.plugins_path || 'plugins') + destination_name

  FileUtils.mkdir_p destination.dirname
  FileUtils.cp source, destination
end

#fork_theme(name = config.theme, new_name = name) ⇒ Object



88
89
90
91
# File 'lib/staticpress/cli.rb', line 88

def fork_theme(name = config.theme, new_name = name)
  theme = Staticpress::Theme.new name
  theme.copy_to new_name
end

#help(*args) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/staticpress/cli.rb', line 25

def help(*args)
  general_usage = <<-USAGE
Usage:
  staticpress <task> <required-argument> [option-argument] [--options...]

  USAGE
  puts general_usage if args.empty?
  super
end

#list(method = :to_s) ⇒ Object



94
95
96
97
98
# File 'lib/staticpress/cli.rb', line 94

def list(method = :to_s)
  Staticpress::Site.new.each do |content|
    puts(content.respond_to?(method) ? content.send(method) : content)
  end
end

#new(destination, name = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/staticpress/cli.rb', line 40

def new(destination, name = nil)
  Staticpress.blog_path = destination

  FileUtils.mkdir_p Staticpress.blog_path
  FileUtils.cp_r((Staticpress.root + 'skeleton').children, Staticpress.blog_path)

  config = self.config.clone

  config.title = if name.to_s.empty?
    Staticpress.blog_path.basename.to_s.split('_').map(&:capitalize).join(' ')
  else
    name
  end

  config.save
end

#pushObject



111
112
113
# File 'lib/staticpress/cli.rb', line 111

def push
  Staticpress::Pusher.push
end

#serveObject



106
107
108
# File 'lib/staticpress/cli.rb', line 106

def serve
  Rack::Server.new(:config => (Staticpress.blog_path + 'config.ru').to_s, :Port => config.port).start
end

#versionObject



121
122
123
# File 'lib/staticpress/cli.rb', line 121

def version
  puts "Staticpress #{Staticpress::Version}"
end