Class: Amiba::Site::Preview

Inherits:
Thor::Group
  • Object
show all
Includes:
Generator
Defined in:
lib/amiba/site.rb

Instance Method Summary collapse

Methods included from Generator

included

Instance Method Details

#createObject


24
25
26
# File 'lib/amiba/site.rb', line 24

def create
  invoke Amiba::Site::Generate
end

#previewObject


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/amiba/site.rb', line 28

def preview
  root = File.expand_path(File.join(Amiba::Configuration.site_dir, "public"))
  logger = WEBrick::Log.new($stderr, WEBrick::Log::ERROR)
  server = WEBrick::HTTPServer.new({:Port => options[:port], :DocumentRoot => root, :Logger => logger})

  ['INT', 'TERM'].each {|signal| 
    trap(signal) {server.shutdown}
  }

  say ""
  say ""
  say "Preview available at http://localhost:#{options[:port]}/"
  say "To end, press Ctrl+C"

  server.start
end