# PublishR -- Fast publishing for ebooks and paper # Copyright (C) 2012 Michael Franzl # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . module Publishr mattr_accessor :gempath @@gempath = File.expand_path('../../../', __FILE__) class Project def initialize(name,absolutepath,absoluteconverterspath,rails_resources_url='') @name = name @inpath = absolutepath @converterspath = absoluteconverterspath @rails_resources_url = rails_resources_url @metadata = YAML::load(File.open(File.join(@inpath,'metadata.yml'), 'r').read) end def make_kindle outpath = File.join(@inpath,'epub') epub = EpubRenderer.new(@name,@inpath,outpath,@metadata, @rails_resources_url) epub.render binaryfile = File.join(@converterspath,'kindlegen') epubfile = File.join(@inpath,"#{ @name }.epub") lines = [] IO.popen("#{ binaryfile } -verbose #{ epubfile }") do |io| while (line = io.gets) do puts line lines << line end end # FileUtils.rm_r outpath # FileUtils.cp File.join(@inpath,"#{ @name }.mobi"), '/media/Kindle/documents' lines.join('
') end def make_pdf pdf = LatexRenderer.new(@name,@inpath) pdf.render outpath = File.join(@inpath,'latex') binaryfile = File.join(@converterspath,'jpeg2ps 2>&1') Dir[File.join(outpath,'*.jpg')].each do |infilepath| outfilepath = File.join(outpath, File.basename(infilepath).gsub(/(.*).jpg/, '\1.eps')) `#{ binaryfile } -r 0 -o #{ outfilepath } #{ infilepath }` end Dir.chdir outpath lines = [] IO.popen('pdflatex -interaction=nonstopmode preamble.tex 2>&1') do |io| while (line = io.gets) do puts line lines << line end end FileUtils.mv(File.join(outpath,'preamble.pdf'), File.join(@inpath,"#{ @name }.pdf")) if File.exists?(File.join(outpath,'preamble.pdf')) lines.join('
') end end end