public

takes a csv file from tracker and makes story cards. be careful of the order when you are cutting them up.

  • Download Gist
tracker_csv_export_to_pdf.rb
Ruby
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
#!/usr/bin/env ruby
 
# Script to generate PDF cards suitable for planning poker
# from Pivotal Tracker [http://www.pivotaltracker.com/] CSV export.
 
# Inspired by Bryan Helmkamp's http://github.com/brynary/features2cards/
 
# Example output: http://img.skitch.com/20100522-d1kkhfu6yub7gpye97ikfuubi2.png
 
require 'rubygems'
require 'fastercsv'
require 'ostruct'
require 'term/ansicolor'
require 'prawn'
require 'prawn/layout/grid'
 
class String; include Term::ANSIColor; end
 
file = ARGV.first
 
unless file
puts "[!] Please provide a path to CSV file"
exit 1
end
 
label_filter = ARGV[1]
 
# --- Read the CSV file -------------------------------------------------------
 
stories = FasterCSV.read(file)
headers = stories.shift
 
# p headers
# p stories
 
# --- Hold story in Card class
 
class Card < OpenStruct
def type
@table[:type]
end
end
 
# --- Create cards objects
 
cards = stories.map do |story|
attrs = { :story_id => story[0] || '',
:title => story[1] || '',
:body => story[14] || '',
:type => story[6] || '',
:labels => story[2] || '',
:points => story[7] || '...',
:owner => story[13] || '.'*50}
 
Card.new attrs
end
 
cards.reject! { |card| !card.labels.include?(label_filter) } if label_filter
 
# p cards
 
# --- Generate PDF with Prawn & Prawn::Document::Grid
 
begin
 
outfile = File.basename(file, ".csv")
 
Prawn::Document.generate("#{outfile}.pdf",
:page_layout => :landscape,
:margin => [25, 25, 50, 25],
:page_size => 'A4') do |pdf|
 
@num_cards_on_page = 0
 
pdf.font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
 
cards.each_with_index do |card, i|
 
# --- Split pages
if i > 0 and i % 4 == 0
# puts "New page..."
pdf.start_new_page
@num_cards_on_page = 1
else
@num_cards_on_page += 1
end
 
# --- Define 2x2 grid
pdf.define_grid(:columns => 2, :rows => 2, :gutter => 42)
# pdf.grid.show_all
 
row = (@num_cards_on_page+1) / 4
column = i % 2
 
# p @num_cards_on_page
# p [ row, column ]
 
padding = 12
 
cell = pdf.grid( row, column )
cell.bounding_box do
 
pdf.stroke_color = "666666"
pdf.stroke_bounds
 
pdf.text card.labels, :size => 12
# --- Write content
pdf.bounding_box [pdf.bounds.left+padding, pdf.bounds.top-padding], :width => cell.width-padding*2 do
pdf.text card.title, :size => 14
pdf.text card.story_id.to_s, :size => 8
pdf.text "\n", :size => 14
pdf.fill_color "444444"
pdf.text card.body, :size => 10
pdf.fill_color "000000"
end
 
pdf.text_box "Points: " + card.points,
:size => 12, :at => [12, 50], :width => cell.width-18
pdf.text_box "Owner: " + card.owner,
:size => 8, :at => [12, 18], :width => cell.width-18
 
pdf.fill_color "999999"
pdf.text_box card.type.capitalize, :size => 8, :align => :right, :at => [12, 18], :width => cell.width-18
pdf.fill_color "000000"
 
end
 
end
 
# --- Footer
pdf.number_pages "#{outfile}.pdf", [pdf.bounds.left, -28]
pdf.number_pages "<page>/<total>", [pdf.bounds.right-16, -28]
end
 
puts ">>> Generated PDF file in '#{outfile}.pdf' with #{cards.size} stories:".black.on_green
 
cards.each do |card|
puts "* #{card.title}"
end
 
rescue Exception
puts "[!] There was an error while generating the PDF file... What happened was:".white.on_red
raise
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.