Sha256: b665579897e39260de41a985e9b14078a8f1e6c85fa76cc43ba2bc14a80de4a6

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'kramdown'

module Bookmaker
  module Parser
    class PDF < Base
      def content
        raw = []
        entries.keys.each do |chapter|
          raw << "{::nomarkdown}\\Chapter{#{chapter.split(/_/)[1].gsub('-',' ')}}{:/}"
          entries[chapter].each do |section|
            raw << read_content(section)[0] + "\n\n* * *"
          end
        end
        raw
      end
      def parse
        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)
        spawn_command ["xelatex", tex_file.to_s,]
        spawn_command ["xelatex", tex_file.to_s,]
        spawn_command ["rm *.glo *.idx *.log *.out *.toc *aux"]
        spawn_command ["mv #{name}.pdf output/#{name}.pdf"]
        true
      rescue Exception
        p $!, $@
        false
      end
      def parse_layout(text)
        text = text.join("\n\n")
        text.gsub!('* * *', "\n\n{::nomarkdown}\\pbreak{:/}\n\n")
        Kramdown::Document.new(text).to_latex
      end
      def tex_file
        root_dir.join("output/#{name}.tex")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bookmaker-0.1.0 lib/bookmaker/parser/pdf.rb