Skip to content
This repository
tree: e3be585c55
Fetching contributors…

Cannot retrieve contributors at this time

file 133 lines (96 sloc) 4.099 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
require 'rubygems'
require 'sinatra/base'
require 'lib/interview'
require 'lib/link'
require 'yaml'
require 'erubis'
require 'kramdown'

class TheSetup < Sinatra::Base
        
        configure do
                begin
                        config = YAML::load_file(File.join(Dir.pwd, 'config', 'database.yml'))
                        Resource.database = Mysql2::Client.new(config[:database])
                        
                        set :markdown, :auto_ids => false
                        
                rescue Exception => e
                        puts "Failed to configure database via config - I'ma quit now."
                        exit
                end
        end
        
        helpers do
                
                def url_for(url)
                        @interview && settings.environment == :production ? "http://usesthis.com" + url : url
                end
                
        end
        
        not_found do
                @interview = Interview.new
                
                @interview.name = "Four O'Four"
                @interview.slug = '404'
                @interview.summary = "HTTP error code (The Internet)"
                
                @title = "What's that?"
                erb :not_found
        end
        
        error do
                @title = "Uh oh"
                erb :error
        end
        
        get '/' do
                @interviews = Interview.recent(:summary => true)
                erb :index
        end
        
        get '/feed/?' do
                content_type "application/atom+xml;charset=utf-8"
                
                @interviews = Interview.recent
                erb :'services/feeds/interviews', :layout => false
        end
        
        get '/sitemap/?' do
                @interviews = Interview.all
                @counts = Interview.years
                @categories = Category.all
                
                content_type "application/xml;charset=utf-8"
                
                erb :sitemap, :layout => false
        end
        
        get '/interviews/?' do
                @title = "Interviews"
                
                @counts = Interview.counts
                @categories = Category.all
                
                erb :archives
        end
        
        get '/interviews/in/?' do
                @title = "Years"
                @counts = Interview.counts
                
                erb :archives
        end
        
        get %r{/interviews/in/([\d]{4})/?$} do |year|
                
                @interviews = Interview.by_year(year, :summary => true)
                @title = "In #{year}" if @interviews.count
                
                erb :index
        end

        get %r{/interviews/([a-z]+)/feed/?$} do |slug|
                content_type "application/atom+xml;charset=utf-8"
                
                @interviews = Interview.for_category_slug(slug, :limit => 10)
                @title = slug.capitalize if @interviews.count
                
                erb :'services/feeds/interviews', :layout => false
        end
        
        get %r{/interviews/([a-z]+)/?$} do |slug|
                @interviews = Interview.for_category_slug(slug, :summary => true)
                @title = slug.capitalize if @interviews.count
                
                erb :index
        end
        
        get '/interview/with/:slug/?' do |slug|
                @interview = Interview.with_slug(slug)
                raise Sinatra::NotFound unless @interview
                
                @title = @interview.name
                @heading = "Interview"

                erb :interview
        end
        
        get '/about/?' do
                @title = "About"
                erb :about
        end
        
        get '/community/?' do
                @title = "Community"
                
                @inspired_links = Link.inspired_by
                @personal_links = Link.personal
                
                erb :community
        end
end
Something went wrong with that request. Please try again.