Class: Zwite::Engine

Inherits:
Object show all
Defined in:
lib/zwite.rb

Constant Summary collapse

@@sharedEngine =

singleton

Engine.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#siteObject

properties



48
49
50
# File 'lib/zwite.rb', line 48

def site
  @site
end

Class Method Details

.sharedEngineObject



55
56
57
# File 'lib/zwite.rb', line 55

def self.sharedEngine
  return @@sharedEngine
end

Instance Method Details

#run(options) ⇒ Object

actions



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/zwite.rb', line 63

def run(options)
  # variables
  @options = options
  @site = Zwite::Site.new(Pathname.new(@options["path"]))
  
  # build
  @site.build
  
  # server
  if @options["server"]
    self.run_server
  end
  
end

#run_serverObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/zwite.rb', line 78

def run_server
  require "webrick"
  
  # mime_types
  mime_types = WEBrick::HTTPUtils::DefaultMimeTypes
  mime_types.store("js", "application/javascript")
  
  # server callback
  server_callback = Proc.new do |request|
    @site.build
  end
  
  # server
  server = WEBrick::HTTPServer.new(
    :AccessLog => [nil, nil],
    :Logger => WEBrick::Log.new("/dev/null"),
    :Port => @options["server_port"], 
    :DirectoryIndex => ["index.html","index.htm", "index.xml"],
    :MimeTypes => mime_types,
  )
  server.mount("/", WEBrick::HTTPServlet::FileHandler, @site.output_path, 
    :FancyIndexing => true,
    :HandlerCallback => server_callback
  )

  # trap
  ["INT", "TERM"].each do |signal|
    trap(signal) do
      server.shutdown
      exit(1)
    end
  end
  
  server_thread = Thread.new do
    puts "Running Server: localhost:#{@options["server_port"]}"
    server.start
  end
  server_thread.join
  
  
end