module PlainSite::Commands

Constants

SELF_DIR

Public Class Methods

build(site,includes,opts) click to toggle source
# File lib/PlainSite/Commands.rb, line 43
def self.build(site,includes,opts)
  site.build(dest:opts.dest,all:opts.all,local:opts.local,includes:includes)
  puts 'Posts build finished.'
  self.clean(site)
end
clean(site,args=nil,opts=nil) click to toggle source
# File lib/PlainSite/Commands.rb, line 49
def self.clean(site,args=nil,opts=nil)
  if site.isolated_files.empty?
    puts "No isolated files found."
  else
    puts 'Do you really want to remove these isolated files?'
    puts ((site.isolated_files.map {|f| f[(site.dest.length+1)..-1]}).join "\n")
    puts "[y/N]"
    answer=$stdin.gets.strip.downcase
    answer='n' if answer.empty?
    if answer =='y'
      site.clean
      puts 'Clean finished.'
    end
  end
end
die(msg="\nExit now.\n") click to toggle source
# File lib/PlainSite/Commands.rb, line 11
def self.die(msg="\nExit now.\n")
  $stderr.puts msg
  exit 1
end
init(site,args,opts) click to toggle source
# File lib/PlainSite/Commands.rb, line 38
def self.init(site,args,opts)
  site.init_scaffold opts.override
  puts 'Site scaffold init success!'
end
newpost(site,args,opts) click to toggle source
# File lib/PlainSite/Commands.rb, line 69
def self.newpost(site,args,opts)
  path=site.newpost args[0],args[1]
  puts "New post created at:#{path}"
end
run(action,args,opts) click to toggle source
# File lib/PlainSite/Commands.rb, line 16
def self.run(action,args,opts)
  root=opts.root || Dir.pwd

  trap('INT') {self.die}
  trap('TERM') {self.die}

  unless File.exist? root
    say_error "Site root directory does not exist:#{root}"
    say_error "Create now? [Y/n]"
    answer=$stdin.gets.strip.downcase # `agree` cannot set default answer
    answer='y' if answer.empty?
    if answer =='y'
      FileUtils.mkdir_p root
    else
      self.die
    end
  end
  root=File.realpath root
  site=Site.new root
  self.send action,site,args,opts
end
serve(site,args,opts) click to toggle source
# File lib/PlainSite/Commands.rb, line 65
def self.serve(site,args,opts)
  site.serve(host:opts.host,port:opts.port)
end