Class: Bookmaker::Parser::PDF

Inherits:
Base
  • Object
show all
Defined in:
lib/bookmaker/parser/pdf.rb

Instance Attribute Summary

Attributes inherited from Base

#root_dir, #source

Instance Method Summary collapse

Methods inherited from Base

#config, #entries, #initialize, #name, parse, #read_content, #render_template, #spawn_command

Constructor Details

This class inherits a constructor from Bookmaker::Parser::Base

Instance Method Details

#contentObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bookmaker/parser/pdf.rb', line 6

def content
  raw = []
  entries.keys.each do |chapter|
    title = (chapter.empty?) ? "Untitled" : chapter.split('_')[1]
    raw << "\\Chapter{#{title.gsub('-',' ')}}\n\n"
    entries[chapter].each do |section|
      s = read_content(section)[0]
      raw << "#{s}\n\n* * *"
    end
  end
  
  raw
end

#parseObject



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
# File 'lib/bookmaker/parser/pdf.rb', line 19

def parse
  puts "-- Exporting PDF"
  locals = config.merge({ :contents => parse_layout(content) })
  locals['copyright'].gsub!("(C)", "\\copyright{}")
  output = render_template(root_dir.join("templates/pdf/layout.erb"), locals)
  File.open(root_dir.join(tex_file), 'w').write(output)
  puts "    - Pass 1"
  spawn_command ["xelatex", tex_file.to_s,]
  puts "    - Pass 2"
  spawn_command ["xelatex", tex_file.to_s,]
  if config['is_final'].to_i == 0
    puts "    - Pass 3 - Indexing"
    spawn_command ["makeindex #{name}.idx"]
    # spawn_command ["makeglossaries #{name}.glo"]
    spawn_command ["xelatex", tex_file.to_s,]
    spawn_command ["rm *ilg *ind "]
  end
  
  spawn_command ["rm *.glo *.idx *.log *.out *.toc *aux *ist"]
  spawn_command ["mv #{name}.pdf output/#{name}.pdf"]
  true
rescue Exception
  p $!, $@
  false
end

#parse_layout(text) ⇒ Object



44
45
46
47
# File 'lib/bookmaker/parser/pdf.rb', line 44

def parse_layout(text)
  text = text.join("\n\n")
  text.gsub!('* * *', "\n\n\\pbreak{}\n\n")
end

#tex_fileObject



48
49
50
# File 'lib/bookmaker/parser/pdf.rb', line 48

def tex_file
  root_dir.join("output/#{name}.tex")
end