Skip to content

Commit

Permalink
generate PDFs inline
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Mekelburg committed Oct 19, 2013
1 parent fd2e990 commit 0543e83
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
33 changes: 19 additions & 14 deletions app/models/registrant.rb
Expand Up @@ -825,13 +825,7 @@ def form_date_of_birth
end end


def wrap_up def wrap_up
if RockyConf.delayed_wrap_up complete!
action = Delayed::PerformableMethod.new(self, :complete!, [])
Delayed::Job.enqueue(action, {:priority=>WRAP_UP_PRIORITY, :run_at=>Time.now})
else
complete
save!
end
end end


def complete_registration def complete_registration
Expand All @@ -844,8 +838,7 @@ def complete_registration


# Enqueues final registration actions for API calls # Enqueues final registration actions for API calls
def enqueue_complete_registration_via_api def enqueue_complete_registration_via_api
action = Delayed::PerformableMethod.new(self, :complete_registration_via_api, []) self.complete_registration_via_api
Delayed::Job.enqueue(action, {:priority=>WRAP_UP_PRIORITY, :run_at=>Time.now})
end end


# Called from the worker queue to generate PDFs on the 'util' server # Called from the worker queue to generate PDFs on the 'util' server
Expand Down Expand Up @@ -980,13 +973,25 @@ def nvra_template_path
File.join(Rails.root, "data", "nvra_templates", "nvra_#{locale && locale.downcase}_#{home_state && home_state.abbreviation.downcase}.pdf") File.join(Rails.root, "data", "nvra_templates", "nvra_#{locale && locale.downcase}_#{home_state && home_state.abbreviation.downcase}.pdf")
end end


def pdf_path def pdf_path(pdfpre = nil)
"/pdf/#{bucket_code}/#{to_param}.pdf" "/#{pdf_dir(pdfpre)}/#{to_param}.pdf"
end

def pdf_dir(pdfpre = nil)
if pdfpre
"#{pdfpre}/#{bucket_code}"
else
if File.exists?(pdf_file_path("pdf"))
"pdf/#{bucket_code}"
else
"pdfs/#{bucket_code}"
end
end
end end


def pdf_file_path def pdf_file_path(pdfpre = nil)
FileUtils.mkdir_p(File.join(Rails.root, "pdf", bucket_code)) FileUtils.mkdir_p(File.join(Rails.root, pdf_dir(pdfpre)))
File.join(Rails.root, pdf_path) File.join(Rails.root, pdf_path(pdfpre))
end end


def bucket_code def bucket_code
Expand Down
14 changes: 12 additions & 2 deletions config/deploy.rb
Expand Up @@ -88,7 +88,7 @@






after "deploy:update_code", "deploy:symlink_configs", "deploy:symlink_pdf", "deploy:symlink_csv", "deploy:symlink_partners", "deploy:migrate" after "deploy:update_code", "deploy:symlink_configs", "deploy:symlink_util_pdf", "deploy:symlink_web_pdf", "deploy:symlink_csv", "deploy:symlink_partners", "deploy:migrate"


set :rake, 'bundle exec rake' set :rake, 'bundle exec rake'


Expand Down Expand Up @@ -166,14 +166,24 @@
end end




desc "Link the pdf dir to shared/pdfs"
task :symlink_web_pdf, :roles => [:web], :except => {:no_release => true} do
run <<-CMD
mkdir -p #{shared_path}/pdfs &&
cd #{latest_release} &&
ln -nfs #{shared_path}/pdfs #{latest_release}/public/pdfs
CMD
end

desc "Link the pdf dir to /data/rocky/pdf" desc "Link the pdf dir to /data/rocky/pdf"
task :symlink_pdf, :roles => [:util], :except => {:no_release => true} do task :symlink_util_pdf, :roles => [:util], :except => {:no_release => true} do
run <<-CMD run <<-CMD
cd #{latest_release} && cd #{latest_release} &&
rm -rf pdf && rm -rf pdf &&
ln -nfs #{ENV['SYMLINK_DATA_DIR']}/html pdf ln -nfs #{ENV['SYMLINK_DATA_DIR']}/html pdf
CMD CMD
end end



desc "Link the csv dir to /data/rocky/csv" desc "Link the csv dir to /data/rocky/csv"
task :symlink_csv, :roles => [:util], :except => {:no_release => true} do task :symlink_csv, :roles => [:util], :except => {:no_release => true} do
Expand Down
2 changes: 1 addition & 1 deletion lib/pdf_renderer.rb
Expand Up @@ -26,7 +26,7 @@ def initialize(registrant)


def logo_image_path def logo_image_path
if @registrant.partner && @registrant.partner.whitelabeled? && @registrant.partner.pdf_logo_present? if @registrant.partner && @registrant.partner.whitelabeled? && @registrant.partner.pdf_logo_present?
"http://#{RockyConf.pdf_host_name}#{@registrant.partner.pdf_logo_url}" @registrant.partner.absolute_pdf_logo_path
else else
"file:///#{Rails.root.join('app/assets/images', RockyConf.pdf.nvra.page1.default_logo).to_s}" "file:///#{Rails.root.join('app/assets/images', RockyConf.pdf.nvra.page1.default_logo).to_s}"
end end
Expand Down
1 change: 1 addition & 0 deletions pdfs/.gitignore
@@ -0,0 +1 @@
*.pdf

0 comments on commit 0543e83

Please sign in to comment.