victor 0.3.3 → 0.3.4

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
  SHA256:
3
- metadata.gz: f4fb744c40ffdf04d89198bbe192150e73fc6776f2fc92f26bfd246c1f107c98
4
- data.tar.gz: 1360dae8be0520d6357ec7300c19cb7a7769cc656081fa1f66dd5bfdbe2895b0
3
+ metadata.gz: 4f308143350a9236bbdf1c046de94a94728ecd90051004482e78cf9734484ef6
4
+ data.tar.gz: 36b35af10ea11a1bc39063384c6a23e247c257d0364edb24b5914cfd73029a88
5
5
  SHA512:
6
- metadata.gz: ed68e9abbe74e3abe5c910f24c6dc988365da107317836649c0f9aef22a7876e7b27c7ea7f18c77d07e436951bb092123f9432a1faa3189e4900b8f3fcb217fe
7
- data.tar.gz: 313a4bd4034c8ea18d5e111fb22e7f4073d6f9dff7cf3f57ddabd980074ffd113afcfb9313d3d33db39f9fd81ba1be493dae0b2f972fc4197bdfa57c74dfe5af
6
+ metadata.gz: 353fd957d007ad7dd020f84a8866634a799e39ae94ba2ea65edf4eb09b6e8a354aa09961492a6cac0a530bcee5e904738df13bffc68c3b00f983348844adc074
7
+ data.tar.gz: 3993f70f671cb4097e83279bc4b5b68d510aa74a40ae320960d56b4a6b1aa537270893975c473cbf66a263496cea39398cd742b217af6b327b595edef84ea36b
data/README.md CHANGED
@@ -27,6 +27,7 @@ directly to SVG elements.
27
27
  * [CSS](#css)
28
28
  * [Tagless Elements](#tagless-elements)
29
29
  * [XML Encoding](#xml-encoding)
30
+ * [XML Newlines](#xml-newlines)
30
31
  * [DSL Syntax](#dsl-syntax)
31
32
  * [Using with Rails](#using-with-rails)
32
33
  * [Related Projects](#related-projects)
@@ -431,6 +432,24 @@ end
431
432
 
432
433
  See the [xml encoding example](https://github.com/DannyBen/victor/tree/master/examples#18-xml-encoding).
433
434
 
435
+
436
+ ### XML Newlines
437
+
438
+ By default, the generated SVGs will have a newline glue between the elements.
439
+ You can change this (for example, to an empty string) if the default newlines
440
+ are not appropriate for your use case.
441
+
442
+ ```ruby
443
+ svg = Victor::SVG.new glue: ''
444
+ ```
445
+
446
+ The glue can also be provided when rendering or saving the output:
447
+
448
+ ```ruby
449
+ svg.save 'filename', glue: ''
450
+ svg.render glue: ''
451
+ ```
452
+
434
453
  ### DSL Syntax
435
454
 
436
455
  Victor also supports a DSL-like syntax. To use it, simply `require 'victor/script'`.
@@ -1,7 +1,7 @@
1
1
  module Victor
2
2
 
3
3
  class SVGBase
4
- attr_accessor :template
4
+ attr_accessor :template, :glue
5
5
  attr_reader :content, :svg_attributes
6
6
 
7
7
  def initialize(attributes = nil, &block)
@@ -20,11 +20,11 @@ module Victor
20
20
  attributes[:width] ||= "100%"
21
21
  attributes[:height] ||= "100%"
22
22
 
23
- if attributes[:template]
24
- @template = attributes.delete :template
25
- elsif !@template
26
- @template = :default
27
- end
23
+ @template = attributes[:template] || @template || :default
24
+ @glue = attributes[:glue] || @glue || "\n"
25
+
26
+ attributes.delete :template
27
+ attributes.delete :glue
28
28
 
29
29
  @svg_attributes = Attributes.new attributes
30
30
  end
@@ -72,25 +72,26 @@ module Victor
72
72
  @css = defs
73
73
  end
74
74
 
75
- def render(template: nil)
75
+ def render(template: nil, glue: nil)
76
76
  @template = template if template
77
+ @glue = glue if glue
77
78
  css_handler = CSS.new css
78
79
 
79
80
  svg_template % {
80
81
  css: css_handler,
81
82
  style: css_handler.render,
82
83
  attributes: svg_attributes,
83
- content: content.join("\n")
84
+ content: to_s
84
85
  }
85
86
  end
86
87
 
87
88
  def to_s
88
- content.join "\n"
89
+ content.join glue
89
90
  end
90
91
 
91
- def save(filename, template: nil)
92
+ def save(filename, template: nil, glue: nil)
92
93
  filename = "#{filename}.svg" unless filename =~ /\..{2,4}$/
93
- File.write filename, render(template: template)
94
+ File.write filename, render(template: template, glue: glue)
94
95
  end
95
96
 
96
97
  protected
@@ -1,3 +1,3 @@
1
1
  module Victor
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: victor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-15 00:00:00.000000000 Z
11
+ date: 2022-07-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Build SVG images with ease
14
14
  email: db@dannyben.com
@@ -40,14 +40,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 2.3.0
43
+ version: 2.6.0
44
44
  required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  requirements: []
50
- rubygems_version: 3.2.16
50
+ rubygems_version: 3.3.14
51
51
  signing_key:
52
52
  specification_version: 4
53
53
  summary: SVG Builder