Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

77 lines (62 sloc) 2.222 kB
Thread.abort_on_exception = true
__DIR__ = File.dirname(__FILE__)
require "bananajour"
require 'sinatra'
require 'haml'
require 'json'
require 'active_support/core_ext/enumerable'
require 'active_support/core_ext/array'
set :server, 'thin'
set :haml, {:format => :html5, :attr_wrapper => '"'}
set :logging, false
require "#{__DIR__}/lib/mock_browsers" if Sinatra::Application.development?
set :bananajour_browser, Bananajour::Bonjour::BananajourBrowser.new
set :repository_browser, Bananajour::Bonjour::RepositoryBrowser.new
load "#{__DIR__}/lib/diff_helpers.rb"
helpers DiffHelpers
require "bananajour/helpers"
helpers Bananajour::GravatarHelpers, Bananajour::DateHelpers
helpers do
def bananajour_browser() options.bananajour_browser end
def repository_browser() options.repository_browser end
def json(body)
content_type "application/json"
params[:callback] ? "#{params[:callback]}(#{body});" : body
end
def local?
[
"0.0.0.0",
"127.0.0.1",
Socket.getaddrinfo(request.env["SERVER_NAME"], nil).map {|a| a[3]}
].flatten.include? request.env["REMOTE_ADDR"]
end
def pluralize(number, singular, plural)
"#{number} #{number == 1 ? singular : plural}"
end
end
get "/" do
@my_repositories = Bananajour.repositories
@other_repos_by_name = repository_browser.other_repositories.group_by {|r| r.name}
@people = bananajour_browser.other_bananajours
haml :home
end
get "/:repository/readme" do
@repository = Bananajour::Repository.for_name(params[:repository])
readme_file = @repository.readme_file
@rendered_readme = @repository.rendered_readme
@plain_readme = readme_file.data
haml :readme
end
get "/:repository/:commit" do
@repository = Bananajour::Repository.for_name(params[:repository])
@commit = @repository.grit_repo.commit(params[:commit])
haml :commit
end
get "/index.json" do
json Bananajour.to_hash.to_json
end
get "/:repository.json" do
response = Bananajour::Repository.for_name(params[:repository]).to_hash
response["recent_commits"].map! { |c| c["committed_date_pretty"] = time_ago_in_words(Time.parse(c["committed_date"])).gsub("about ","") + " ago"; c }
json response.to_json
end
Jump to Line
Something went wrong with that request. Please try again.