From 3ebd5934b3f1e9bd1b2cb4a0aaac4bad3ea74722 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 10 Apr 2014 18:29:58 -0400 Subject: [PATCH] Add file injection to help split apart big files without needing to prerender individual pieces --- README.md | 2 ++ lib/svggvs/session.rb | 1 + lib/svggvs/target.rb | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/README.md b/README.md index f037a80..1c8707b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ unless they have the following names: * (protect): The layer will not be deleted if it is hidden. Good for clone sources. * (child visible): The layer will be visible if its parent layer is also made visible. Good if you break artwork up into multiple layers (inks, colors, shading, etc.) +* (inject filename.svg): Include all the layers of another SVG file as child layers of this layer. + Does not copy patterns/gradients yet! Hiding/showing layers is the way that you make certain card elements appear/disappear on different types of cards with with different properties. You can also replace the text in diff --git a/lib/svggvs/session.rb b/lib/svggvs/session.rb index 6881a5a..3308b63 100644 --- a/lib/svggvs/session.rb +++ b/lib/svggvs/session.rb @@ -66,6 +66,7 @@ module SVGGVS end with_new_target do |target| + target.inject! target.active_layers = card[:active_layers] target.replacements = card[:replacements] end diff --git a/lib/svggvs/target.rb b/lib/svggvs/target.rb index 66eec2b..212bf35 100644 --- a/lib/svggvs/target.rb +++ b/lib/svggvs/target.rb @@ -12,6 +12,26 @@ module SVGGVS @target end + def injected_sources + @injected_sources ||= {} + end + + def inject! + css("g[inkscape|groupmode='layer']").each do |layer| + if filename = layer['inkscape:label'][/inject (.*\.svg)/, 1] + injected_sources[filename] ||= begin + data = Nokogiri::XML(::File.read(filename)) + + data.css("svg > g[inkscape|groupmode='layer']") + end + + injected_sources[filename].each do |additional_layer| + layer << additional_layer.to_xml + end + end + end + end + def active_layers=(layers) css("g[inkscape|groupmode='layer']").each do |layer| if layers.include?(layer['inkscape:label'])