From 6f78aac0b5730c3040ee9fb842279f1eced4c1fa Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 17 Nov 2013 13:56:58 -0500 Subject: [PATCH] parallelize the heck out of what i can --- bin/svggvs | 13 ++++++------- lib/svggvs/version.rb | 4 ++-- svggvs.gemspec | 3 ++- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/svggvs b/bin/svggvs index 44a1611..1ba9fc1 100755 --- a/bin/svggvs +++ b/bin/svggvs @@ -2,6 +2,7 @@ require 'thor' require 'digest/md5' +require 'parallel' require_relative '../lib/svggvs' @@ -35,15 +36,13 @@ module SVGGVS write_svgs ensure_tmp - @exported_pngs = [] - - context.individual_files.each_with_index do |svg_file, index| + @exported_pngs = Parallel.map(context.individual_files.each_with_index) do |svg_file, index| target = Pathname(context.session.png_files_path % index) target.parent.mkpath - @exported_pngs << target - system %{inkscape --export-area-page --export-png "#{target.expand_path}" --export-width #{context.session.png_export_width} --export-background="#ffffffff" "#{svg_file.expand_path}"} + + target end end @@ -51,7 +50,7 @@ module SVGGVS def pdf pngs - trimmed_pngs = @exported_pngs.collect do |png| + trimmed_pngs = Parallel.map(@exported_pngs) do |png| tmp_target = tmp_target_for(png) system %{convert #{png} -gravity Center -crop #{context.session.pdf_card_size}+0+0 +repage #{tmp_target}} @@ -66,7 +65,7 @@ module SVGGVS 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| + pages = Parallel.map(png_slices.each_with_index) do |files, page_index| tmp_pdf_target = tmp_path.join("page%05d.pdf" % page_index) files += Array.new(9 - files.length, placeholder) diff --git a/lib/svggvs/version.rb b/lib/svggvs/version.rb index a764edd..7e62da3 100644 --- a/lib/svggvs/version.rb +++ b/lib/svggvs/version.rb @@ -1,3 +1,3 @@ -module Svggvs - VERSION = "0.0.2" +module SVGGVS + VERSION = "0.0.3" end diff --git a/svggvs.gemspec b/svggvs.gemspec index 5bb3b22..4cc2140 100644 --- a/svggvs.gemspec +++ b/svggvs.gemspec @@ -5,7 +5,7 @@ require 'svggvs/version' Gem::Specification.new do |gem| gem.name = "svggvs" - gem.version = Svggvs::VERSION + gem.version = SVGGVS::VERSION gem.authors = ["John Bintz"] gem.email = ["john@coswellproductions.com"] gem.description = %q{Generate sets of card game cards using Inkscape templates and Ruby} @@ -19,4 +19,5 @@ Gem::Specification.new do |gem| gem.add_dependency 'nokogiri' gem.add_dependency 'thor' + gem.add_dependency 'parallel' end