lots more cleanups, skeleton project file

This commit is contained in:
John Bintz 2013-11-17 11:28:19 -05:00
parent cf9b2c224f
commit e0c0e0eb14
6 changed files with 662 additions and 15 deletions

View File

@ -1,6 +1,18 @@
# Process Inkscape files and create sets of cards for board games
Not much in the way of docs yet. You'll need `inkscape`, `convert`, `montage`, and `gs` in your `PATH`.
You'll need `inkscape`, `convert`, `montage`, and `gs` in your `PATH`.
## Initialize a starter project
Install the gem globally with `gem install svggvs` and then run `svggvs install <project>` where `project`
is the name of the directory to place the skeleton project files. You'll get a few files in there:
* `template.svg`, an Inkscape template that shoows how to do the basic SVGGVS template setup
* `Cardfile`, the file SVGGVS uses to define each card for printing
* `Gemfile`, in case you need additional gems. It has SVGGVS added already, but you may also want remote
data gems like `google_drive`, for instance.
## How it works
Create a `Cardfile` in your working directory. It should look
something like this:
@ -21,10 +33,6 @@ something like this:
end
@session.process do
require 'google_drive'
require 'virtus'
require 'active_support/inflector'
require './card_definitions.rb'
CardDefinitions.processed.each do |card|

View File

@ -7,8 +7,19 @@ require_relative '../lib/svggvs'
module SVGGVS
class Cli < Thor
include Thor::Actions
def self.source_root
::File.expand_path('../../skel', __FILE__)
end
class_option :cardfile, default: 'Cardfile'
desc "install [ dir ]", "Install a Cardfile and sample template"
def install(dir = '.')
directory '.', dir
end
desc "merged_file", "Write out a merged file"
def merged_file
context.write_merged_file
@ -36,12 +47,6 @@ module SVGGVS
end
end
no_tasks do
def tmp_target_for(file)
tmp_path.join(Digest::MD5.hexdigest(file.to_s) + '.png')
end
end
desc "pdf", "Create PDF of card images"
def pdf
pngs
@ -58,9 +63,14 @@ module SVGGVS
page_count = trimmed_pngs.length / 9
placeholder = tmp_target_for("placeholder.png")
system %{convert -size #{context.session.pdf_card_size} xc:white #{placeholder}}
pages = png_slices.each_with_index.collect do |files, page_index|
tmp_pdf_target = tmp_path.join("page%05d.pdf" % page_index)
files += Array.new(9 - files.length, placeholder)
system %{montage -density #{context.session.pdf_dpi} -geometry +0+0 #{files.join(' ')} #{tmp_pdf_target}}
tmp_pdf_target
@ -84,6 +94,10 @@ module SVGGVS
end
no_tasks do
def tmp_target_for(file)
tmp_path.join(Digest::MD5.hexdigest(file.to_s) + '.png')
end
def tmp_path
@tmp_path ||= Pathname(".tmp")
end

View File

@ -1,7 +1,7 @@
require 'svggvs/file'
require 'svggvs/target'
require 'svggvs/context'
require 'svggvs/session'
require_relative './svggvs/file'
require_relative './svggvs/target'
require_relative './svggvs/context'
require_relative './svggvs/session'
module SVGGVS
end

37
skel/Cardfile Normal file
View File

@ -0,0 +1,37 @@
@session.configure do |c|
c.svg_source = "template.svg"
c.svg_merged_target = "merged-template.svg"
c.png_export_width = 825
c.pdf_dpi = 300
c.pdf_card_size = "750x1050"
c.individual_files_path = "svgout/output_%03d.svg"
c.png_files_path = "pngout-svggvs/output_%03d.png"
c.pdf_target = "pnp/game.pdf"
end
card_data = [
{
active_layers: [ 'Action', 'Puppy', 'Name', 'Background' ],
replacements: { 'Name' => 'Woofie', 'Action' => 'Bark at the person who is ringing the doorbell.' }
},
{
active_layers: [ 'Action', 'Kitten', 'Name', 'Background' ],
replacements: { 'Name' => 'Hisshead', 'Action' => "Demand food by clawing at your owner's lap." }
},
]
@session.process do
card_data.each do |card|
@session.with_new_target do |target|
target.active_layers = card[:active_layers]
target.replacements = card[:replacements]
end
end
end

3
skel/Gemfile Normal file
View File

@ -0,0 +1,3 @@
source 'https://rubygems.org'
gem 'svggvs'

585
skel/template.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 50 KiB