Quick-and-dirty <defs> copying from injected files into target file.

If using (inject) layers, the SVG <defs> are copied over, so that things
like clipping paths and masks make it across.
This commit is contained in:
John Bintz 2014-05-29 20:00:15 -04:00
parent 3ebd5934b3
commit 692f37f83e
3 changed files with 29 additions and 1 deletions

View File

@ -29,12 +29,28 @@ module SVGGVS
@target ||= doc.at_css('g[inkscape|label="Target"]') @target ||= doc.at_css('g[inkscape|label="Target"]')
end end
def defs
@defs ||= doc.at_css('defs')
end
def original_defs
@original_defs ||= defs.dup
end
def reset_defs!
defs.children.each(&:remove)
defs << original_defs.children
end
def doc def doc
return @doc if @doc return @doc if @doc
@doc = Nokogiri::XML(::File.read(@path)) @doc = Nokogiri::XML(::File.read(@path))
clear_targets! clear_targets!
original_defs
@doc @doc
end end
@ -49,6 +65,8 @@ module SVGGVS
target_obj = Target.new(new_target) target_obj = Target.new(new_target)
reset_defs!
yield target_obj yield target_obj
target_obj.replaced target_obj.replaced
@ -56,6 +74,10 @@ module SVGGVS
target << target_obj.target target << target_obj.target
target_obj.injected_defs.values.each do |v|
defs << v
end
@instance += 1 @instance += 1
end end

View File

@ -16,12 +16,18 @@ module SVGGVS
@injected_sources ||= {} @injected_sources ||= {}
end end
def injected_defs
@injected_defs ||= {}
end
def inject! def inject!
css("g[inkscape|groupmode='layer']").each do |layer| css("g[inkscape|groupmode='layer']").each do |layer|
if filename = layer['inkscape:label'][/inject (.*\.svg)/, 1] if filename = layer['inkscape:label'][/inject (.*\.svg)/, 1]
injected_sources[filename] ||= begin injected_sources[filename] ||= begin
data = Nokogiri::XML(::File.read(filename)) data = Nokogiri::XML(::File.read(filename))
injected_defs[filename] = data.css("svg > defs")
data.css("svg > g[inkscape|groupmode='layer']") data.css("svg > g[inkscape|groupmode='layer']")
end end

View File

@ -1,3 +1,3 @@
module SVGGVS module SVGGVS
VERSION = "0.0.9" VERSION = "0.0.10"
end end