svggvs 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -29,6 +29,10 @@ unless they have the following names:
29
29
 
30
30
  * (visible): The layer is always visible, regardless if it's specified in `#active_layers`
31
31
  * (protect): The layer will not be deleted if it is hidden. Good for clone sources.
32
+ * (child visible): The layer will be visible if its parent layer is also made visible. Good if you
33
+ break artwork up into multiple layers (inks, colors, shading, etc.)
34
+ * (inject filename.svg): Include all the layers of another SVG file as child layers of this layer.
35
+ Does not copy patterns/gradients yet!
32
36
 
33
37
  Hiding/showing layers is the way that you make certain card elements appear/disappear on
34
38
  different types of cards with with different properties. You can also replace the text in
@@ -29,12 +29,28 @@ module SVGGVS
29
29
  @target ||= doc.at_css('g[inkscape|label="Target"]')
30
30
  end
31
31
 
32
+ def defs
33
+ @defs ||= doc.at_css('defs')
34
+ end
35
+
36
+ def original_defs
37
+ @original_defs ||= defs.dup
38
+ end
39
+
40
+ def reset_defs!
41
+ defs.children.each(&:remove)
42
+
43
+ defs << original_defs.children
44
+ end
45
+
32
46
  def doc
33
47
  return @doc if @doc
34
48
 
35
49
  @doc = Nokogiri::XML(::File.read(@path))
36
50
  clear_targets!
37
51
 
52
+ original_defs
53
+
38
54
  @doc
39
55
  end
40
56
 
@@ -49,6 +65,8 @@ module SVGGVS
49
65
 
50
66
  target_obj = Target.new(new_target)
51
67
 
68
+ reset_defs!
69
+
52
70
  yield target_obj
53
71
 
54
72
  target_obj.replaced
@@ -56,6 +74,10 @@ module SVGGVS
56
74
 
57
75
  target << target_obj.target
58
76
 
77
+ target_obj.injected_defs.values.each do |v|
78
+ defs << v
79
+ end
80
+
59
81
  @instance += 1
60
82
  end
61
83
 
@@ -66,6 +66,7 @@ module SVGGVS
66
66
  end
67
67
 
68
68
  with_new_target do |target|
69
+ target.inject!
69
70
  target.active_layers = card[:active_layers]
70
71
  target.replacements = card[:replacements]
71
72
  end
@@ -12,6 +12,32 @@ module SVGGVS
12
12
  @target
13
13
  end
14
14
 
15
+ def injected_sources
16
+ @injected_sources ||= {}
17
+ end
18
+
19
+ def injected_defs
20
+ @injected_defs ||= {}
21
+ end
22
+
23
+ def inject!
24
+ css("g[inkscape|groupmode='layer']").each do |layer|
25
+ if filename = layer['inkscape:label'][/inject (.*\.svg)/, 1]
26
+ injected_sources[filename] ||= begin
27
+ data = Nokogiri::XML(::File.read(filename))
28
+
29
+ injected_defs[filename] = data.css("svg > defs")
30
+
31
+ data.css("svg > g[inkscape|groupmode='layer']")
32
+ end
33
+
34
+ injected_sources[filename].each do |additional_layer|
35
+ layer << additional_layer.to_xml
36
+ end
37
+ end
38
+ end
39
+ end
40
+
15
41
  def active_layers=(layers)
16
42
  css("g[inkscape|groupmode='layer']").each do |layer|
17
43
  if layers.include?(layer['inkscape:label'])
@@ -32,6 +58,18 @@ module SVGGVS
32
58
  end
33
59
  end
34
60
  end
61
+
62
+ loop do
63
+ 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'] == ''
66
+ layer['style'] = ''
67
+
68
+ any_changed = true
69
+ end
70
+ end
71
+ break if !any_changed
72
+ end
35
73
  end
36
74
 
37
75
  def replacements=(replacements)
@@ -1,3 +1,3 @@
1
1
  module SVGGVS
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svggvs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-06 00:00:00.000000000 -05:00
12
+ date: 2014-05-29 00:00:00.000000000 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
17
- requirement: &72324050 !ruby/object:Gem::Requirement
17
+ requirement: &80918420 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *72324050
25
+ version_requirements: *80918420
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: thor
28
- requirement: &72323840 !ruby/object:Gem::Requirement
28
+ requirement: &80918210 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *72323840
36
+ version_requirements: *80918210
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: parallel
39
- requirement: &72323630 !ruby/object:Gem::Requirement
39
+ requirement: &80918000 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *72323630
47
+ version_requirements: *80918000
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: roo
50
- requirement: &72323420 !ruby/object:Gem::Requirement
50
+ requirement: &80917790 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *72323420
58
+ version_requirements: *80917790
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: activesupport
61
- requirement: &72323210 !ruby/object:Gem::Requirement
61
+ requirement: &80917580 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *72323210
69
+ version_requirements: *80917580
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rspec
72
- requirement: &72323000 !ruby/object:Gem::Requirement
72
+ requirement: &80959270 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *72323000
80
+ version_requirements: *80959270
81
81
  description: Generate sets of card game cards using Inkscape templates and Ruby
82
82
  email:
83
83
  - john@coswellproductions.com