Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 70 lines (57 sloc) 1.49 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
module Hopper
  class App < Sinatra::Base
    register Mustache::Sinatra

    dir = File.dirname(File.expand_path(__FILE__))

    set :public_folder, "#{dir}/frontend/public"
    set :static, true
    set :mustache, {
      :namespace => Hopper,
      :templates => "#{dir}/templates",
      :views => "#{dir}/views"
    }

    before do
      @path = request.path_info

      halt mustache(:dead)
    end

    get '/' do
      mustache :index
    end

    get '/stats' do
      mustache :stats
    end

    get '/probes' do
      @probes = Probe.all
      mustache :probes
    end

    get '/probes/:id' do
      @probe = Probe.find(params[:id])
      mustache :probe, :layout => !request.xhr?
    end

    get '/probes/:id/raw' do
      @probe = Probe.find(params[:id])
      @probe.to_csv
    end

    get '/projects' do
      mustache :projects
    end

    # whatever, deal with this monstrocity later
    get '/projects/jump' do
      path = params[:url].gsub('https://github.com/','')
      @project = Project.find_by_name(path)
      if @project
        redirect "/projects/#{@project.id}"
      else
        redirect :projects
      end
    end

    get '/projects/:id' do
      @project = Project.find(params[:id])
      mustache :project
    end

    get '/projects/:id/:probe' do
      @project = Project.find(params[:id])
      @probe = @project.probes.select{|probe| probe.name == params[:probe]}.first
      mustache :project_probe, :layout => !request.xhr?
    end
  end
end
Something went wrong with that request. Please try again.