From d56d77daef69f7c14ea0470cabdd6cc1de8581d9 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 26 Apr 2015 18:08:46 +0200 Subject: [PATCH] create_pdf --- app/controllers/application_controller.rb | 4 +++ app/controllers/documents_controller.rb | 8 ++++++ app/models/ability.rb | 2 +- app/models/document.rb | 21 ++++++++++++++++ app/views/documents/footer.html | 29 ++++++++++++++++++++++ app/views/documents/header.html | 28 +++++++++++++++++++++ app/views/documents/logo2014_64.png | Bin 0 -> 2455 bytes app/views/documents/show.html.erb | 3 ++- config/initializers/pdf_convert.rb | 2 ++ config/routes.rb | 2 +- 10 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 app/views/documents/footer.html create mode 100644 app/views/documents/header.html create mode 100644 app/views/documents/logo2014_64.png create mode 100644 config/initializers/pdf_convert.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c083ab4..3002d5b 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -52,6 +52,10 @@ def get_theme #else "blue1" #end +end + +def current_ability + @current_ability ||= Ability.new(current_user, request) end def default_url_options {locale: I18n.locale, theme: (theme_name=="blue1") ? nil : theme_name , ansicht: nil} diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index dc335fc..2e16645 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -25,6 +25,14 @@ class DocumentsController < ApplicationController end end + def show + @document = Document.find(params[:id]) + respond_to do |format| + format.pdf { send_file @document.create_pdf.path } + format.html + end + end + def dump_to_etherpad @document = Document.find(params[:id]) @document.dump_to_etherpad diff --git a/app/models/ability.rb b/app/models/ability.rb index 4516e34..73b5237 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- class Ability include CanCan::Ability - def initialize(user) + def initialize(user,request=nil) loggedin=!(user.nil?) user ||= User.new # guest user (not logged in) diff --git a/app/models/document.rb b/app/models/document.rb index f98535c..9ee5526 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -26,6 +26,27 @@ class Document < ActiveRecord::Base def self.ether EtherpadLite.connect('http://www.fet.at/etherpad', File.new('/srv/etherpad/etherpad-lite/APIKEY.txt')) end + def create_pdf + require "open3" + + #url=blank_document_url({id: self.id, host: host, port: port}) + # url=Rails.application.routes.url_helpers.blank_document_url({id: self.id, host: host, port: port}) + + file = Tempfile.new(['document', '.pdf']) + bin=Rails.application.config.pdf_bin + sin,sout,serr=Open3.popen3("#{bin} --header-html \"file://#{Rails.root}/app/views/documents/header.html\" --footer-html \"file://#{Rails.root}/app/views/documents/footer.html\" --replace title1 \"#{self.name}\" - #{file.path}") +#Rails.logger.puts("#{bin} --header-html \"file://#{Rails.root}/app/views/documents/header.html\" --footer-html \"file://#{Rails.root}/app/views/documents/footer.html\" --replace title1 \"#{self.name}\" \"#{url}\" \"#{file.path}\" ") +# `#{bin} --header-html "file://#{Rails.root}/app/views/documents/header.html" --footer-html "file://#{Rails.root}/app/views/documents/footer.html" --replace title1 "#{self.name}" #{url} #{file.path} ` + sin.puts("

#{self.name}

") + t=self.text + t.gsub!(/src="[\.\/]*(uploads[^"]*)"/){|s| "src=\"#{Rails.root}/public/"+$1.to_s+'"'} + sin.puts(t) + sin.close + Rails.logger.puts(serr.read) + file + end + + def ether if @ep.nil? @ep=Document.ether diff --git a/app/views/documents/footer.html b/app/views/documents/footer.html new file mode 100644 index 0000000..69c4e53 --- /dev/null +++ b/app/views/documents/footer.html @@ -0,0 +1,29 @@ + + + + + + + + + + +
+ + + Fachschaft Elektrotechnik - Service-Offizielles-Freizeit + +
+ + diff --git a/app/views/documents/header.html b/app/views/documents/header.html new file mode 100644 index 0000000..2968f0e --- /dev/null +++ b/app/views/documents/header.html @@ -0,0 +1,28 @@ + + + + + + + + + +
+ + + + +
+ + diff --git a/app/views/documents/logo2014_64.png b/app/views/documents/logo2014_64.png new file mode 100644 index 0000000000000000000000000000000000000000..10b2ecf27a0780c3942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v}e{RG9CC6PyAvSaC@M>4IC?4h|r=@XCHtnO8d}zQ0jn@ zpuc6rg&Q^M90bs)b5PxIZAv$&>ndA-l|AjsC?Ghx+rW>XK1}o^ge|9s4KmL`pZN(gd{|O>UG%q6i`C)AV`7d z5q<+~O1hV4S6l$X!Fx4X*}N=Y zRV%xR)<&KKp2JOavr193v-?ySL2=7pfxiXndlM(xhH@9in%j^2NkV_-0>SWqkJ9>P zL}EZEDlaElMSTHuGH_j*Hf8`#BGPb$?N%hd3}I}~*ChETRaF!4y5mG_MCC4!ty)`t zn5)DUBS1uof!hL?pCi9xI?5@KHCkKVnq;-($1oufod`S+oCbm)LPq*qI-CRE0_$c_ zo2KHiRIIm%+b`nH0}?;2bpe|YT?nkY(!KPCzFvVzq;^*uHR`kisSBF`ZDZRgJl%!J zWK})q4}l$^u%Ddvs%pDL+*TAY)&!tU-SC@I>&ye5O7Lw|)sw)+e%76WPc$3svr@-x z0NJl@c%ekx`%&4YZus?X`%l)4q9cDk9q~QXR~{o0y`8w-sI}#LyL}?=Vw9IamSD%< zrHh$d8otv{Yy*Z&tqLFQUgcFD0rNnTwY{JSBU{J|Eu*Y%G)A_7NzOHK)8rkP33OSj z5bHIDUl=~nL^C9SHlj?CWt(ka93o9gW^Z*ERL3AX-e+^E~P$*d^K2}Fxf@s`LfN%wRQq0B~^1-d&ER5KI-_I|(mZ+SZtT%-V@4Y(Fn zuQxGPONx)TSTYC5LwPR~Ofw^ZW&CWeo&d%=lO+cj44S$YKk^dJ7gzjXELu2j1@4h%(P zE|Rj2=hYA^Yb3vODrX9VqtO9F=6;b;do5ya1$ip1UF4|0l6O7GtG!m^^#&P3#stvX z@;6BL6}a0$4tXJ$<`o1{s+RewHx!vvjTr <% end %> - +
<%= render_attachments_for(@document) %> +
diff --git a/config/initializers/pdf_convert.rb b/config/initializers/pdf_convert.rb new file mode 100644 index 0000000..c54cfac --- /dev/null +++ b/config/initializers/pdf_convert.rb @@ -0,0 +1,2 @@ +#Fetsite::Application.config.pdf_bin="~/www/wkhtmltopdf/bin/wkhtmltopdf" +Fetsite::Application.config.pdf_bin="wkhtmltopdf" diff --git a/config/routes.rb b/config/routes.rb index 1eb5a2b..76a8568 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -192,7 +192,7 @@ get :write_etherpad get :read_from_etherpad get :dump_to_etherpad - end + end end resources :meetings do member do