svggvs 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29c1636f89126ee8986e8cf114eed283f2440e6b
4
- data.tar.gz: 709063890719e5e75b6dbcc0ab2a010e25cc5ef8
3
+ metadata.gz: a0d8732594ac89df68876713b8aa039126ea6de9
4
+ data.tar.gz: f89a9f042223f2f46295b16013edea94fe7e4905
5
5
  SHA512:
6
- metadata.gz: 76f3ddacf87dc548dfe2b89a00acd18c4b5a3448f5957d6d73a1220d4fae399bf0cc3a23d87a60aa9bf0b4ccaad92cb3869b1caebbfb3b99a3c7503e65463c68
7
- data.tar.gz: b74974b4db359bed549423b7c5e0fdc6c19b55b3388d239bb73ee878e48915d9a085566aab05f506169da1af5bb898e56e25f298c77accd214e14810751f16e4
6
+ metadata.gz: 325bc63df8ea205bec22df72ba0e7a9f14bc671a9165dddece6f885bbe750f7f29f0cafdfd4cc79954ac97a72fdf3ce4d9138ca4f4d7daf4fa64a4a0d677a23f
7
+ data.tar.gz: 2ac8833777e80fc0b1b0253c8fe06cc3b07dd5aa8fb7e36c75e5293db7617e43ebe793e48946d4a7bbefdd88ed9faf60392b6fca743480c2acae7400054d7799
data/README.md CHANGED
@@ -83,6 +83,8 @@ Create a `Cardfile` in your working directory. It should look something like thi
83
83
  @session.configure do |c|
84
84
  # manipulate the data after reading from the spreadsheet
85
85
  # c.post_read_data = proc { |data|
86
+ # data[:active_layers] << "My Cool Layer"
87
+ # data[:active_layers] << /a regular expression/i
86
88
  # data[:replacements]['Superpower Text'] << '!!'
87
89
  # }
88
90
 
@@ -13,7 +13,7 @@ module SVGGVS
13
13
  def settings
14
14
  settings = {}
15
15
 
16
- doc.each_with_pagename do |name, sheet|
16
+ sheets.each do |name, sheet|
17
17
  if name['SVGGVS Settings']
18
18
  sheet.each do |setting, value|
19
19
  settings[setting.spunderscore.to_sym] = value
@@ -24,8 +24,20 @@ module SVGGVS
24
24
  settings
25
25
  end
26
26
 
27
- def each_card(card_sheet_identifier)
27
+ def sheets
28
+ return @sheets if @sheets
29
+
30
+ @sheets = []
31
+
28
32
  doc.each_with_pagename do |name, sheet|
33
+ @sheets << [ name, sheet.dup ]
34
+ end
35
+
36
+ @sheets
37
+ end
38
+
39
+ def each_card(card_sheet_identifier)
40
+ sheets.each do |name, sheet|
29
41
  if name[card_sheet_identifier]
30
42
  headers = sheet.row(1)
31
43
 
@@ -1,4 +1,5 @@
1
1
  require 'nokogiri'
2
+ require 'delegate'
2
3
 
3
4
  module SVGGVS
4
5
  class File
@@ -58,12 +59,42 @@ module SVGGVS
58
59
  target.children.each(&:remove)
59
60
  end
60
61
 
62
+ class SVGCache < SimpleDelegator
63
+ def initialize(doc)
64
+ @doc = doc
65
+ end
66
+
67
+ def __getobj__
68
+ @doc
69
+ end
70
+
71
+ def is_clone_dup_type(href)
72
+ @is_clone_dup_type ||= {}
73
+
74
+ return @is_clone_dup_type[href] if @is_clone_dup_type[href] != nil
75
+
76
+ if source = css(href).first
77
+ if source.name == 'flowRoot' || source.name == 'text'
78
+ @is_clone_dup_type[href] = source
79
+ end
80
+ end
81
+
82
+ @is_clone_dup_type[href] ||= false
83
+
84
+ @is_clone_dup_type[href]
85
+ end
86
+ end
87
+
88
+ def svg_cache
89
+ @svg_cache ||= SVGCache.new(source)
90
+ end
91
+
61
92
  def with_new_target
62
93
  new_target = source.dup
63
94
  new_target[:id] = new_target[:id] + "_#{@instance}"
64
95
  new_target['inkscape:label'] = new_target['inkscape:label'] + "_#{@instance}"
65
96
 
66
- target_obj = Target.new(new_target)
97
+ target_obj = Target.new(new_target, cache: svg_cache)
67
98
 
68
99
  reset_defs!
69
100
 
@@ -55,6 +55,27 @@ module SVGGVS
55
55
  card_finished!
56
56
  end
57
57
 
58
+ class ActiveLayerMatcher < SimpleDelegator
59
+ def initialize(layers)
60
+ @layers = layers
61
+ end
62
+
63
+ def __getobj__
64
+ @layers
65
+ end
66
+
67
+ def include?(name)
68
+ @layers.any? { |layer|
69
+ case layer
70
+ when Regexp
71
+ layer =~ name
72
+ else
73
+ layer == name
74
+ end
75
+ }
76
+ end
77
+ end
78
+
58
79
  def data_source=(source)
59
80
  data_source = DataSource.new(source)
60
81
 
@@ -68,7 +89,7 @@ module SVGGVS
68
89
 
69
90
  with_new_target do |target|
70
91
  target.inject!
71
- target.active_layers = card[:active_layers]
92
+ target.active_layers = ActiveLayerMatcher.new(card[:active_layers])
72
93
  target.replacements = card[:replacements]
73
94
  end
74
95
  end
@@ -4,8 +4,8 @@ module SVGGVS
4
4
  class Target < SimpleDelegator
5
5
  attr_reader :target
6
6
 
7
- def initialize(target)
8
- @target = target
7
+ def initialize(target, options)
8
+ @target, @options = target, options
9
9
  end
10
10
 
11
11
  def __getobj__
@@ -20,8 +20,16 @@ module SVGGVS
20
20
  @injected_defs ||= {}
21
21
  end
22
22
 
23
+ def file_layers
24
+ @file_layers ||= css("g[inkscape|groupmode='layer']")
25
+ end
26
+
27
+ def child_visible_layers
28
+ @child_visible_layers ||= file_layers.find_all { |layer| layer['inkscape:label'].include?('(child visible)') }
29
+ end
30
+
23
31
  def inject!
24
- css("g[inkscape|groupmode='layer']").each do |layer|
32
+ file_layers.each do |layer|
25
33
  if filename = layer['inkscape:label'][/inject (.*\.svg)/, 1]
26
34
  injected_sources[filename] ||= begin
27
35
  data = Nokogiri::XML(::File.read(filename))
@@ -39,30 +47,36 @@ module SVGGVS
39
47
  end
40
48
 
41
49
  def active_layers=(layers)
42
- css("g[inkscape|groupmode='layer']").each do |layer|
50
+ file_layers.each do |layer|
51
+ layer['style'] = if layer['inkscape:label'].include?('(visible)')
52
+ ''
53
+ else
54
+ 'display:none'
55
+ end
56
+ end
57
+
58
+ file_layers.each do |layer|
43
59
  if layers.include?(layer['inkscape:label'])
44
60
  layer['style'] = ''
45
61
 
46
62
  current_parent = layer.parent
47
63
 
48
- while current_parent && current_parent.name == "g"
64
+ while current_parent && current_parent.name == "g" && current_parent['style'] != ''
49
65
  current_parent['style'] = ''
50
66
 
51
67
  current_parent = current_parent.parent
52
68
  end
53
- else
54
- layer['style'] = if layer['inkscape:label'].include?('(visible)')
55
- ''
56
- else
57
- 'display:none'
58
- end
69
+
70
+ layers.delete(layer)
59
71
  end
72
+
73
+ break if layers.empty?
60
74
  end
61
75
 
62
76
  loop do
63
77
  any_changed = false
64
- css("g[inkscape|groupmode='layer']").each do |layer|
65
- if layer['inkscape:label'].include?('(child visible)') && layer['style'] != '' && layer.parent['style'] == ''
78
+ child_visible_layers.each do |layer|
79
+ if layer['style'] != '' && layer.parent['style'] == ''
66
80
  layer['style'] = ''
67
81
 
68
82
  any_changed = true
@@ -106,11 +120,15 @@ module SVGGVS
106
120
  end
107
121
  end
108
122
 
123
+ def cache
124
+ @options[:cache]
125
+ end
126
+
109
127
  # only uncloning text
110
128
  def unclone
111
- css('svg|use').each do |clone|
112
- if source = css(clone['xlink:href']).first
113
- if source.name == 'flowRoot' || source.name == 'text'
129
+ file_layers.find_all { |layer| layer['style'] == '' }.each do |layer|
130
+ layer.css('svg|use').each do |clone|
131
+ if source = cache.is_clone_dup_type(clone['xlink:href'])
114
132
  new_group = clone.add_next_sibling("<g />").first
115
133
 
116
134
  clone.attributes.each do |key, attribute|
@@ -1,3 +1,3 @@
1
1
  module SVGGVS
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svggvs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bintz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-24 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 2.2.1
150
+ rubygems_version: 2.2.2
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: Generate sets of card game cards using Inkscape templates and Ruby