# 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
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) if File.exists? File.join(@inpath,'metadata.yml')
end
def self.gempath
File.expand_path('../../../', __FILE__)
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
lines.join('
')
end
def make_pdf
pdf = LatexRenderer.new(@name,@inpath,@metadata)
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
`makeindex preamble.idx`
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
def make_web
Dir.chdir @inpath
FileUtils.rm_rf 'out'
site = Webgen::Website.new '.'
site.init
message = site.render
FileUtils.rm_rf '.sass-cache'
FileUtils.rm_rf 'webgen.cache'
message
end
def make_images_local(kramdown)
images = []
processed_lines = []
kramdown.split("\n").each do |line|
match = /\!\[.*?\]\((.*?)\)/.match(line)
images << match[1] if match
processed_lines << line.gsub(/\!\[(.*?)\]\((.*?)\)/){ "![#{ $1 }](#{ File.basename($2) })" }
end
FileUtils.mkdir_p File.join(@inpath,'images')
FileUtils.chdir File.join(@inpath,'images')
output = ["The following files were downloaded into the image folder of your document:\n"]
images.each do |image|
FileUtils.rm_f File.join(@inpath,'images',File.basename(image))
output << `wget -nv #{image} 2>&1`
end
return processed_lines.join("\n"), output
end
end
end