-
-
Save mm53bar/433360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.DS_Store | |
*.csv | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
# Forked to add direct support for printing to 3x5 index cards. | |
# -- I haven't been able to test this yet so use at your own risk | |
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 | |
# --- 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 = { :title => story[1] || '', | |
:body => story[14] || '', | |
:type => story[6] || '', | |
:points => story[7] || '...', | |
:owner => story[13] || '.'*50} | |
Card.new attrs | |
end | |
# p cards | |
# --- Generate PDF with Prawn & Prawn::Document::Grid | |
begin | |
outfile = File.basename(file, ".csv") | |
Prawn::Document.generate("#{outfile}.pdf", | |
:page_layout => :landscape, | |
:margin => [10, 10, 10, 10], | |
:page_size => [216,360]) do |pdf| | |
pdf.font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf" | |
cards.each do |card| | |
pdf.start_new_page | |
padding = 12 | |
pdf.stroke_color = "666666" | |
pdf.stroke_bounds | |
# --- Write content | |
pdf.bounding_box [pdf.bounds.left+padding, pdf.bounds.top-padding], :width => 300 do | |
pdf.text card.title, :size => 14 | |
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 => 200 | |
pdf.text_box "Owner: " + card.owner, | |
:size => 8, :at => [12, 18], :width => 200 | |
pdf.fill_color "999999" | |
pdf.text_box card.type.capitalize, :size => 8, :align => :right, :at => [12, 18], :width => 314 | |
pdf.fill_color "000000" | |
end | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment