From e0c0e0eb147eaf76d594bf4c75510eaee2801e2d Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 17 Nov 2013 11:28:19 -0500 Subject: [PATCH] lots more cleanups, skeleton project file --- README.md | 18 +- bin/svggvs | 26 ++- lib/svggvs.rb | 8 +- skel/Cardfile | 37 +++ skel/Gemfile | 3 + skel/template.svg | 585 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 662 insertions(+), 15 deletions(-) create mode 100644 skel/Cardfile create mode 100644 skel/Gemfile create mode 100644 skel/template.svg diff --git a/README.md b/README.md index 9a91b15..20e8bb1 100644 --- a/README.md +++ b/README.md @@ -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 ` 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| diff --git a/bin/svggvs b/bin/svggvs index 47ec84a..44a1611 100755 --- a/bin/svggvs +++ b/bin/svggvs @@ -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 diff --git a/lib/svggvs.rb b/lib/svggvs.rb index 135744d..83f772b 100644 --- a/lib/svggvs.rb +++ b/lib/svggvs.rb @@ -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 diff --git a/skel/Cardfile b/skel/Cardfile new file mode 100644 index 0000000..115e216 --- /dev/null +++ b/skel/Cardfile @@ -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 + + diff --git a/skel/Gemfile b/skel/Gemfile new file mode 100644 index 0000000..f6d999f --- /dev/null +++ b/skel/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gem 'svggvs' diff --git a/skel/template.svg b/skel/template.svg new file mode 100644 index 0000000..42f68b7 --- /dev/null +++ b/skel/template.svg @@ -0,0 +1,585 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + Name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Perform this action, then pat the nearest animal of this type. + + + +