-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_odp2beamer.rb
executable file
·53 lines (41 loc) · 1.22 KB
/
test_odp2beamer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#! /usr/bin/env ruby
require 'treetop'
require 'zip/zip'
require File.expand_path(File.dirname(__FILE__) + '/odp2beamer_nodes')
Treetop.load "odp2beamer"
unless ARGV.length == 1
puts "USAGE: #{__FILE__} [odp_file]"
exit
end
parser = Odp2BeamerParser.new
odp_filename = ARGV[0]
unless File.readable?(odp_filename)
puts "File '#{odp_filename}' is not readable."
exit
end
# Extracting main 'content.xml' file
content_xml = 'content.xml'
Zip::ZipFile.open(odp_filename) do |zipfile|
content_file = zipfile.find_entry(content_xml)
#content_file.extract { true }
end
# Reading and parsing main 'content.xml'
file = File.open(content_xml, 'r')
buffer = file.readlines.join('')
file.close
result = parser.parse(buffer)
# Parse Results
if result.nil?
puts "Parse FAILURE => #{parser.failure_reason}"
exit
end
# Create directory to put outputs
dir_base = File.basename(odp_filename, File.extname(odp_filename))
FileUtils.mkdir(dir_base) unless File.exist?(dir_base)
# Create Beamer Latex file
tex_output_filename = "#{File.dirname(__FILE__)}/#{dir_base}/#{dir_base}.tex"
tex_output = File.new(tex_output_filename, 'w+')
tex_output.puts(result.value.strip)
tex_output.close
# Deleting temporal files
#File.delete(content_xml)