Module: ClockworkComicPDF::PDFSectionMaker
- Included in:
- PDFMaker
- Defined in:
- lib/clockwork_comic_pdf/pdf_section_maker.rb
Overview
this parses the sections of a book into a pdf file
Instance Method Summary collapse
- #make_name(file_path) ⇒ Object
- #make_text_box(pdf, text, content) ⇒ Object
- #print_comic_image(pdf, version, image) ⇒ Object
- #print_comic_pages(pdf, version, comic_pages) ⇒ Object
- #print_formatted_text_box(pdf, version, content) ⇒ Object
- #print_section(pdf, version, section) ⇒ Object
- #print_section_break(pdf, text) ⇒ Object
- #print_sections(pdf, version) ⇒ Object
- #print_text_box(pdf, version, content) ⇒ Object
Instance Method Details
#make_name(file_path) ⇒ Object
61 62 63 |
# File 'lib/clockwork_comic_pdf/pdf_section_maker.rb', line 61 def make_name(file_path) File.basename(file_path, '.*').split(' ').slice(1..-1).join(' ') end |
#make_text_box(pdf, text, content) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/clockwork_comic_pdf/pdf_section_maker.rb', line 75 def make_text_box(pdf, text, content) new_page(pdf) page_index << { page: current_page, name: content.name } if printing_body = (pdf, content.) pdf.formatted_text_box(text, ) end |
#print_comic_image(pdf, version, image) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/clockwork_comic_pdf/pdf_section_maker.rb', line 50 def print_comic_image(pdf, version, image) new_page(pdf) name = make_name(image) page_index << { page: current_page, name: "#{name}" } if printing_body content = [[name], [{ image: image, scale: 72.0 / version.dpi }]] table = Prawn::Table.new(content, pdf, cell_style: { borders: [] }, position: :center) pdf.move_down((pdf.bounds.height - table.height) / 2.0) table.draw end |
#print_comic_pages(pdf, version, comic_pages) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/clockwork_comic_pdf/pdf_section_maker.rb', line 29 def print_comic_pages(pdf, version, comic_pages) puts comic_pages.name if comic_pages.print_section_intro print_section_break(pdf, comic_pages.name) end section_dir = "./#{version.name}/#{comic_pages.directory}/" Dir["#{section_dir}*.*"].each do |image| print_comic_image(pdf, version, image) end end |
#print_formatted_text_box(pdf, version, content) ⇒ Object
70 71 72 73 |
# File 'lib/clockwork_comic_pdf/pdf_section_maker.rb', line 70 def print_formatted_text_box(pdf, version, content) text = YAML.load_file(content.file) make_text_box(pdf, text, content) end |
#print_section(pdf, version, section) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/clockwork_comic_pdf/pdf_section_maker.rb', line 16 def print_section(pdf, version, section) section.each do |item| case item.type when :text_box print_text_box(pdf, version, item) when :formatted_text_box print_formatted_text_box(pdf, version, item) when :comic_pages print_comic_pages(pdf, version, item) end end end |
#print_section_break(pdf, text) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/clockwork_comic_pdf/pdf_section_maker.rb', line 40 def print_section_break(pdf, text) new_page(pdf) pdf.move_cursor_to pdf.bounds.top = { valign: :center, align: :center, width: pdf.bounds.width, height: pdf.bounds.height, size: 18, at: pdf.bounds.top_left } page_index << { page: current_page, name: text } if printing_body pdf.text_box(text, ) end |
#print_sections(pdf, version) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/clockwork_comic_pdf/pdf_section_maker.rb', line 4 def print_sections(pdf, version) print_section(pdf, version, book.sections.front_matter) self.printing_body = true self.current_page = 0 self.content_start = pdf.page_number + 1 print_section(pdf, version, book.sections.body) self.printing_body = false print_section(pdf, version, book.sections.end_matter) new_page(pdf) if pdf.page_number.odd? print_toc(pdf) if book.print_toc end |
#print_text_box(pdf, version, content) ⇒ Object
65 66 67 68 |
# File 'lib/clockwork_comic_pdf/pdf_section_maker.rb', line 65 def print_text_box(pdf, version, content) text = File.new(content.file).read make_text_box(pdf, [{ text: text }], content) end |