From 40cb9ad750a13940ffac56db3c32ce7df0c16d67 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 9 Nov 2013 18:06:23 -0500 Subject: [PATCH] add the things I need for lie your face off --- README.md | 4 ++++ lib/svggvs/file.rb | 1 + lib/svggvs/target.rb | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/README.md b/README.md index 81ec8ca..2942b37 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,10 @@ end # Any text with {% liquid_like_tags %} will have those tags replaced with the # values within the hash passed in. + # Additionally, you can label the following and have things replaced: + # * svg:flowRoot will replace the text in the svg:flowPara within + # * svg:text will replace the text in the first svg:tspan within + # * svg:image will replace the xlink:href of the tag, changing the image to load target.replacements = datum[:replacements] end end diff --git a/lib/svggvs/file.rb b/lib/svggvs/file.rb index c9c4c04..4c19ecc 100644 --- a/lib/svggvs/file.rb +++ b/lib/svggvs/file.rb @@ -52,6 +52,7 @@ module SVGGVS yield target_obj target_obj.replaced + target_obj.unclone target << target_obj.target diff --git a/lib/svggvs/target.rb b/lib/svggvs/target.rb index 36b96f3..90d69bc 100644 --- a/lib/svggvs/target.rb +++ b/lib/svggvs/target.rb @@ -34,10 +34,41 @@ module SVGGVS child.content = @replacements[match] || '' end else + if label = child['inkscape:label'] + if flow_para = child.css('svg|flowPara').first + flow_para.content = @replacements[label] || '' + end + + if span = child.css('svg|tspan').first + span.content = @replacements[label] || '' + end + + if child.name == "image" && !!@replacements[label] + child['xlink:href'] = @replacements[label] + end + end + replaced(child) end end end end + + def unclone + css('svg|use').each do |clone| + if source = css(clone['xlink:href']).first + new_group = clone.add_next_sibling("").first + + clone.attributes.each do |key, attribute| + new_group[attribute.name] = attribute.value + end + + new_group << source.dup + end + + clone.remove + end + end end end +