Skip to content

Instantly share code, notes, and snippets.

@johnbintz
Last active December 18, 2015 13:49
Show Gist options
  • Save johnbintz/5792564 to your computer and use it in GitHub Desktop.
Save johnbintz/5792564 to your computer and use it in GitHub Desktop.
Basic Ruby script for generating nanDECK cards (untested)
CARD_INFO = {
animal: { color: '#aa0000', border: '#ff0000' },
vegetable: { color: '#00aa00', border: '#00ff00' },
mineral: { color: '#0000aa', border: '#0000ff' }
}.freeze
data = [
{ name: 'Cat', value: '1', type: :animal },
{ name: 'Rutabaga', value: '2', type: :vegetable },
{ name: 'Obsidian', value: '3', type: :mineral }
].freeze
output = [
"UNIT=INCH",
"CARDSIZE=2.5,3.5",
"BORDER=NONE",
"DPI=300",
"PAGE = 8.5, 11, PORTRAIT",
"MARGINS = 0.5, 0.5, 0.25, 0.25"
]
card_index = 1
data.each do |card_data|
info = CARD_INFO[card_data[:type]]
# borders are centered on paths, like inkscape. this will bleed a 0.125 border on the inside.
output << "RECTANGLE = #{card_index}, 0, 0, 2.5, 3.5, #{info[:border]}, #{info[:color]}, 0.25"
output << "FONT = Tahoma, 14, B, #000000"
output << %{TEXT = #{card_index}, "#{card_data[:name]}", 0.5, 0.5, 1.5, 0.5, center}
output << "FONT = Tahoma, 32, B, #000000"
output << %{TEXT = #{card_index}, "#{card_data[:value]}", 0.5, 1.5, 1.5, 1.0, center}
card_index += 1
end
File.open('output.txt', 'wb') { |fh| fh.print output.join("\n") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment