From 692f37f83e05f0d9e74191454feb8bfc13c9737a Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 29 May 2014 20:00:15 -0400 Subject: [PATCH] Quick-and-dirty copying from injected files into target file. If using (inject) layers, the SVG are copied over, so that things like clipping paths and masks make it across. --- lib/svggvs/file.rb | 22 ++++++++++++++++++++++ lib/svggvs/target.rb | 6 ++++++ lib/svggvs/version.rb | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/svggvs/file.rb b/lib/svggvs/file.rb index c724274..e7f8f19 100644 --- a/lib/svggvs/file.rb +++ b/lib/svggvs/file.rb @@ -29,12 +29,28 @@ module SVGGVS @target ||= doc.at_css('g[inkscape|label="Target"]') 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 return @doc if @doc @doc = Nokogiri::XML(::File.read(@path)) clear_targets! + original_defs + @doc end @@ -49,6 +65,8 @@ module SVGGVS target_obj = Target.new(new_target) + reset_defs! + yield target_obj target_obj.replaced @@ -56,6 +74,10 @@ module SVGGVS target << target_obj.target + target_obj.injected_defs.values.each do |v| + defs << v + end + @instance += 1 end diff --git a/lib/svggvs/target.rb b/lib/svggvs/target.rb index 212bf35..cd83dcb 100644 --- a/lib/svggvs/target.rb +++ b/lib/svggvs/target.rb @@ -16,12 +16,18 @@ module SVGGVS @injected_sources ||= {} end + def injected_defs + @injected_defs ||= {} + 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)) + injected_defs[filename] = data.css("svg > defs") + data.css("svg > g[inkscape|groupmode='layer']") end diff --git a/lib/svggvs/version.rb b/lib/svggvs/version.rb index 3103840..f22adc8 100644 --- a/lib/svggvs/version.rb +++ b/lib/svggvs/version.rb @@ -1,3 +1,3 @@ module SVGGVS - VERSION = "0.0.9" + VERSION = "0.0.10" end