lib/lncs/paper.rb in lncs-0.0.3 vs lib/lncs/paper.rb in lncs-0.0.4
- old
+ new
@@ -30,11 +30,10 @@
def type
name.match(/(pdf|zip)/)[1]
end
def generate_title_to(dst, start_page)
- raise "Error: Cannot generate title from PDF for paper ##{id}" if type == "pdf"
check_pdf_exists
captured = title_page_from_manifest_or_latex
captured += "\n" + authors_from_manifest_or_latex.map do |a|
a.gsub!(/(?<forename>\S*) (?<surname>.*)/, '\k<surname>, \k<forename>') if a
@@ -59,10 +58,33 @@
end
else
actions.copy_file(path, File.join(dst, name))
end
end
+
+ def data_for_manifest(existing_data)
+ if existing_data.key?(id)
+ { id => existing_data[id] }
+
+ elsif type == "zip"
+ data = { pdf: paths_to_pdfs }
+
+ case data[:pdf].size
+ when 1
+ data[:pdf] = data[:pdf].first
+ when 0
+ data[:FIXME] = "Change the PDF key to the path (relative, within the ZIP) of the compiled PDF."
+ else
+ data[:FIXME] = "Reduce the PDF key from an array to a single value which corresponds to the compiled PDF."
+ end
+
+ { id => data }
+
+ else
+ {}
+ end
+ end
def page_count
check_pdf_exists
PDF::Reader.new(open_pdf).page_count
@@ -76,10 +98,23 @@
pdf_exists = Zip::ZipFile.open(path) { |zipfile| zipfile.find_entry(pdf) }
raise "Error: no PDF file found at path '#{pdf}' within the ZIP file #{path}" unless pdf_exists
end
end
+ # Locate all PDF files within the ZIP
+ def paths_to_pdfs
+ paths = []
+
+ Zip::ZipFile.open(path) do |zipfile|
+ zipfile.select { |file| zipfile.get_entry(file).file? }.each do |file|
+ paths << file.name if file.name.end_with? ".pdf"
+ end
+ end
+
+ paths
+ end
+
def open_pdf
if type == "zip"
extracted_pdf = File.join(Dir.tmpdir, pdf)
Zip::ZipFile.open(path) do |zipfile|
FileUtils.mkdir_p(File.dirname(extracted_pdf))
@@ -127,9 +162,10 @@
"""
\\title{#{title}}\n
\\author{#{authors_from_manifest_or_latex.join(" \\and ")}}\n
"""
else
+ raise "Error: lncs cannot extract title and authors from a PDF file. Please specify the title and authors in the manifest for paper ##{id})" if type == "pdf"
captured = ""
each_tex do |tex|
capturing = false
while (line = tex.gets)
break if line.include? '\maketitle'
\ No newline at end of file