Class: SVGGVS::Target
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- SVGGVS::Target
- Defined in:
- lib/svggvs/target.rb
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #active_layers=(layers) ⇒ Object
-
#initialize(target) ⇒ Target
constructor
A new instance of Target.
- #replaced(node = @target) ⇒ Object
- #replacements=(replacements) ⇒ Object
-
#unclone ⇒ Object
only uncloning text.
Constructor Details
#initialize(target) ⇒ Target
Returns a new instance of Target.
7 8 9 |
# File 'lib/svggvs/target.rb', line 7 def initialize(target) @target = target end |
Instance Attribute Details
#target ⇒ Object (readonly)
Returns the value of attribute target.
5 6 7 |
# File 'lib/svggvs/target.rb', line 5 def target @target end |
Instance Method Details
#__getobj__ ⇒ Object
11 12 13 |
# File 'lib/svggvs/target.rb', line 11 def __getobj__ @target end |
#active_layers=(layers) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/svggvs/target.rb', line 15 def active_layers=(layers) css("g[inkscape|groupmode='layer']").each do |layer| if layers.include?(layer['inkscape:label']) layer['style'] = '' current_parent = layer.parent while current_parent && current_parent.name == "g" current_parent['style'] = '' current_parent = current_parent.parent end else layer['style'] = 'display:none' end end end |
#replaced(node = @target) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/svggvs/target.rb', line 37 def replaced(node = @target) if !!@replacements node.children.each do |child| if child.text? if match = child.content[%r{\{% ([^ ]+) %\}}, 1] child.content = @replacements[match] || '' end else if label = child['inkscape:label'] if !!@replacements[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'] = ::File.(@replacements[label]) end end end replaced(child) end end end end |
#replacements=(replacements) ⇒ Object
33 34 35 |
# File 'lib/svggvs/target.rb', line 33 def replacements=(replacements) @replacements = replacements end |
#unclone ⇒ Object
only uncloning text
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/svggvs/target.rb', line 68 def unclone css('svg|use').each do |clone| if source = css(clone['xlink:href']).first if source.name == 'flowRoot' || source.name == 'text' new_group = clone.add_next_sibling("<g />").first clone.attributes.each do |key, attribute| new_group[attribute.name] = attribute.value end new_group << source.dup clone.remove end end end end |