Add file injection to help split apart big files without needing to prerender individual pieces

This commit is contained in:
John Bintz 2014-04-10 18:29:58 -04:00
parent f12f23e8a3
commit 3ebd5934b3
3 changed files with 23 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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'])