lib/stackprof-webnav/server.rb in stackprof-webnav-0.0.1 vs lib/stackprof-webnav/server.rb in stackprof-webnav-0.0.2
- old
+ new
@@ -1,19 +1,30 @@
require 'nyny'
require 'haml'
require "stackprof"
-require 'sprockets'
+require 'sprockets/nyny'
+require 'net/http'
require_relative 'presenter'
module StackProf
module Webnav
class Server < NYNY::App
+ register Sprockets::NYNY
+ config.assets.paths << File.join(__dir__, 'css')
+
class << self
- attr_accessor :report_dump_path
+ attr_accessor :report_dump_path, :report_dump_url
def presenter
- report = StackProf::Report.new(Marshal.load(File.open(report_dump_path).read))
+ return @presenter unless @presenter.nil?
+ content = if report_dump_path.nil?
+ Net::HTTP.get(URI.parse(report_dump_url))
+ else
+ File.open(report_dump_path).read
+ end
+
+ report = StackProf::Report.new(Marshal.load(content))
@presenter ||= Presenter.new(report)
end
end
helpers do
@@ -37,16 +48,11 @@
def file_url path
"/file?path=#{URI.escape(path)}"
end
end
- sprockets = Sprockets::Environment.new do |env|
- env.append_path(File.join(__dir__, 'css'))
- end.index
- builder.map('/assets'){ run sprockets }
-
get '/' do
- @file = Server.report_dump_path
+ @file = Server.report_dump_path || Server.report_dump_url
@action = "overview"
@frames = presenter.overview_frames
render_with_layout :overview
end