Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rheaton
Created March 30, 2011 15:38
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save rheaton/894624 to your computer and use it in GitHub Desktop.
Save rheaton/894624 to your computer and use it in GitHub Desktop.
takes a csv file from tracker and makes story cards. be careful of the order when you are cutting them up.
#!/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
@dakoontz
Copy link

dakoontz commented Oct 1, 2014

@rheaton
Just tried to use this script - downloaded the gems and running it I get this superclass mismatch for class MultiBox (TypeError). Any idea what the MultiBox superclass issue may be?

Thanks!

ruby tracker_csv_export_to_pdf.rb
/Library/Ruby/Gems/2.0.0/gems/prawn-layout-0.8.4/lib/prawn/layout/grid.rb:191:in <class:Document>': superclass mismatch for class MultiBox (TypeError) from /Library/Ruby/Gems/2.0.0/gems/prawn-layout-0.8.4/lib/prawn/layout/grid.rb:2:inmodule:Prawn'
from /Library/Ruby/Gems/2.0.0/gems/prawn-layout-0.8.4/lib/prawn/layout/grid.rb:1:in <top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:inrequire'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in rescue in require' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:inrequire'
from tracker_csv_export_to_pdf.rb:15:in `

'

@bobhobelman
Copy link

Same issue here. Can someone point me in the right direction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment