Module: Nyaplot::ExportToWeb
- Defined in:
- lib/nyaplot/export_to_web.rb
Constant Summary collapse
- @@server =
nil- @@web_root =
nil
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.shutdown_webserver ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/nyaplot/export_to_web.rb', line 45 def shutdown_webserver if @@server @@server.shutdown @@server = nil $stderr.puts "shutdown server" end if @@web_root FileUtils.remove_entry_secure @@web_root @@web_root = nil end end |
Instance Method Details
#show ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/nyaplot/export_to_web.rb', line 37 def show if defined? IRuby super else show_on_web end end |
#show_on_web(port = 28288, filename = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nyaplot/export_to_web.rb', line 13 def show_on_web(port=28288, filename=nil) filename ||= "plot.html" @@web_root ||= Dir.mktmpdir export_html(File.join(@@web_root, filename)) if !@@server @@server = WEBrick::HTTPServer.new(DocumentRoot: @@web_root, Port: port, ServerType: Thread, Logger: WEBrick::Log.new(File.open(File::NULL, 'w')), AccessLog: []) %w(INT TERM).each do |sig| trap(sig) do shutdown_webserver end end @@server.start $stderr.puts "start server on port #{port}." end Launchy.open "http://localhost:#{port}/#{filename}" end |