Sha256: c8f4e52555040a0a37e022f3b5e94e822871a541baaf0404f2fcaa4f1d5988f0
Contents?: true
Size: 1.61 KB
Versions: 5
Compression:
Stored size: 1.61 KB
Contents
require 'prawn' require 'how_is/chart' module HowIs class PdfReport < BaseReport def format :pdf end attr_accessor :pdf def title(_text) pdf.pad_bottom(10) { pdf.text(_text, size: 25) } end def header(_text) pdf.pad_top(15) { pdf.pad_bottom(3) { pdf.text _text, size: 20 } } end def link(_text, url) # TODO: Actually have links. _text end def horizontal_bar_graph(data) filename_base = "./issues-per-label" dat_file = filename_base + '.dat' png_file = filename_base + '.png' File.open(dat_file, 'w') do |f| data.each_with_index do |(label, n, link), i| f.puts "#{i}\t#{n}\t\"#{label}\"" end end Chart.gnuplot(label_font_size: 10, font_size: 16, data_file: dat_file, png_file: png_file) Chart.rotate(90, png_file) pdf.image png_file end def text(_text) pdf.text _text end # Prawn (afaict) doesn't let you export to a binary blob. # So export to a file, then read the file. def export(&block) # TODO: Use actual temporary file. export!('temp.pdf', &block) open('temp.pdf').read end def export!(file, &block) _self = self Prawn::Document.generate(file) do |pdf| _self.pdf = pdf pdf.font("Helvetica") pdf.span(450, position: :center) do _self.instance_eval(&block) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems