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 0000000..10b2ecf Binary files /dev/null and b/app/views/documents/logo2014_64.png differ diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb index 8dcb20b..f367a44 100644 --- a/app/views/documents/show.html.erb +++ b/app/views/documents/show.html.erb @@ -22,5 +22,6 @@ <% 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