Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 80 lines (65 sloc) 2.166 kb
50d7741 @jonmagic App and specs setup. Ready to start building.
jonmagic authored
1 $: << File.expand_path('../../lib', __FILE__)
2
3 require 'bundler'
4 Bundler.require
5
b4ccb53 @jonmagic Setup Document model and pdf attachment.
jonmagic authored
6 # Application module
7 module PdfArchive
8 def self.environment
9 ENV['RACK_ENV'] || 'development'
10 end
11
12 def self.root
13 @root ||= Pathname(File.expand_path('../..', __FILE__))
14 end
15 end
16
17 # MongoMapper setup
315cb32 @jonmagic Add MongoLab support.
jonmagic authored
18 mongo_url = ENV['MONGOHQ_URL'] || ENV['MONGOLAB_URI'] || "mongodb://localhost:27017/pdf_archive-#{PdfArchive.environment}"
b4ccb53 @jonmagic Setup Document model and pdf attachment.
jonmagic authored
19 uri = URI.parse(mongo_url)
20 database = uri.path.gsub('/', '')
21 MongoMapper.connection = Mongo::Connection.new(uri.host, uri.port, {})
22 MongoMapper.database = database
23ca74b @jonmagic Authenticated with the db.
jonmagic authored
23 if uri.user.present? && uri.password.present?
24 MongoMapper.database.authenticate(uri.user, uri.password)
25 end
b4ccb53 @jonmagic Setup Document model and pdf attachment.
jonmagic authored
26
27 # CarrierWave setup
28 require 'carrierwave/orm/mongomapper'
f2e945b @jonmagic Adding S3 config to CarrierWave.
jonmagic authored
29 CarrierWave.configure do |config|
30 config.fog_credentials = {
31 :provider => 'AWS',
32 :aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
33 :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
34 }
b4ccb53 @jonmagic Setup Document model and pdf attachment.
jonmagic authored
35
f2e945b @jonmagic Adding S3 config to CarrierWave.
jonmagic authored
36 config.fog_directory = ENV['BUCKET_NAME']
37 config.fog_public = true # optional, defaults to true
38 config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
39 end
40
5036a78 @jonmagic Add Grim MultiProcessor support.
jonmagic authored
41 # Grim Production Config
42 if PdfArchive.environment == "production"
43 Grim.processor = Grim::MultiProcessor.new([
44 Grim::ImageMagickProcessor.new({:ghostscript_path => PdfArchive.root.join('bin', '9.04', 'gs')}),
45 Grim::ImageMagickProcessor.new({:ghostscript_path => PdfArchive.root.join('bin', '9.02', 'gs')})
46 ])
47 end
48
442989e @rwdaigle Added exceptional error tracking
authored
49 require 'exceptional'
50 set :raise_errors, true
51 use Rack::Exceptional, ENV['EXCEPTIONAL_API_KEY'] if ENV['RACK_ENV'] == 'production' && ENV['EXCEPTIONAL_API_KEY']
52
f2e945b @jonmagic Adding S3 config to CarrierWave.
jonmagic authored
53 # require pdf uploader, document model, and process pdf job
14b3721 @rwdaigle Extracting common uploader logic to parent class
authored
54 require 'uploader'
b4ccb53 @jonmagic Setup Document model and pdf attachment.
jonmagic authored
55 require 'pdf_uploader'
c877042 @jonmagic Add a PreviewStore for the preview image.
jonmagic authored
56 require 'preview_store'
b4ccb53 @jonmagic Setup Document model and pdf attachment.
jonmagic authored
57 require 'document'
14016b5 @jonmagic Upload a PDF and then search thru archived PDFs.
jonmagic authored
58 require 'process_pdf'
b4ccb53 @jonmagic Setup Document model and pdf attachment.
jonmagic authored
59
60 # Routes
14016b5 @jonmagic Upload a PDF and then search thru archived PDFs.
jonmagic authored
61 set :public_folder, "#{PdfArchive.root}/public"
62
50d7741 @jonmagic App and specs setup. Ready to start building.
jonmagic authored
63 get '/' do
64 erb :home
14016b5 @jonmagic Upload a PDF and then search thru archived PDFs.
jonmagic authored
65 end
66
67 post '/' do
68 if params['pdf']
69 document = Document.create!(params)
70 Qu.enqueue(ProcessPdf, document.id)
71 end
72
73 erb :home
74 end
75
76 get '/search' do
77 @documents = Document.search(params['q'])
78 erb :home
14b3721 @rwdaigle Extracting common uploader logic to parent class
authored
79 end
Something went wrong with that request. Please try again.