#!/usr/bin/env ruby require "thin" require "sinatra/base" require "dolt/repo_actions" require "dolt/template_renderer" require "dolt/view" require "dolt/disk_repo_resolver" if ARGV.length == 0 puts("Dolt should be run with a directory as its sole argument") puts("The directory should either be a Git repository or a directory") puts("that holds Git repositories.") exit(1) end ### TODO: Extract this into a testable API def is_git_repo?(dir) File.exists?(File.join(dir, ".git")) end def create_app(dir, view) if is_git_repo?(dir) dir = File.expand_path(dir) resolver = Dolt::DiskRepoResolver.new(File.dirname(dir)) actions = Dolt::RepoActions.new(resolver) view.helper(Dolt::View::SingleRepository) require "dolt/sinatra/single_repo_browser" Dolt::Sinatra::SingleRepoBrowser.new(File.basename(dir), actions, view) else resolver = Dolt::DiskRepoResolver.new(dir) actions = Dolt::RepoActions.new(resolver) view.helper(Dolt::View::MultiRepository) require "dolt/sinatra/multi_repo_browser" Dolt::Sinatra::MultiRepoBrowser.new(actions, view) end end base = File.join(File.dirname(__FILE__), "..") template_root = File.join(base, "views") view = Dolt::TemplateRenderer.new(template_root, { :cache => false, :layout => "layout" }) view.helper(Dolt::View::Object) view.helper(Dolt::View::Blob) view.helper(Dolt::View::Blame) view.helper(Dolt::View::Breadcrumb) view.helper(Dolt::View::Tree) view.helper(Dolt::View::Commit) view.helper(Dolt::View::Gravatar) Dolt::View::TabWidth.tab_width = 4 view.helper(Dolt::View::TabWidth) view.helper(Dolt::View::BinaryBlobEmbedder) # Configure blob rendering module # Attempt to syntax highlight every blob # view.helper(Dolt::View::SyntaxHighlight) # Attempt to render every blob as markup # view.helper(Dolt::View::Markup) # Render supported formats as markup, syntax highlight the rest view.helper(Dolt::View::SmartBlobRenderer) Sinatra::Base.set(:public_folder, File.join(base, "vendor/ui")) server = create_app(ARGV[0], view) Thin::Server.start("0.0.0.0", 3000, server)