victor 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6540ebf1d8dba779d9da76d9755fb2fc65e6eb7f9119c0cc904fc3ad5d2f9cf
4
- data.tar.gz: 332cb3428d65f3095f580229ed6ce5180de3b57fd41bc79d23c45f5ed72c7abd
3
+ metadata.gz: f4fb744c40ffdf04d89198bbe192150e73fc6776f2fc92f26bfd246c1f107c98
4
+ data.tar.gz: 1360dae8be0520d6357ec7300c19cb7a7769cc656081fa1f66dd5bfdbe2895b0
5
5
  SHA512:
6
- metadata.gz: 5cf0bc30d5201b6f2d2ec271b67d9e8ebf5ae18b4f3bba9324a655b22b3f20f19d259188a174ae40cf2ef41674a2f4c1cbc35953e2ad499cf1122702138bda3f
7
- data.tar.gz: 81811e7d304675e2f5585b4debe09867c8a771b131f9f228fad15b7785d0754191b72f44306ce9acbcf5a686d9bb7c56a653d02ef2349821b695bb41ce887888
6
+ metadata.gz: ed68e9abbe74e3abe5c910f24c6dc988365da107317836649c0f9aef22a7876e7b27c7ea7f18c77d07e436951bb092123f9432a1faa3189e4900b8f3fcb217fe
7
+ data.tar.gz: 313a4bd4034c8ea18d5e111fb22e7f4073d6f9dff7cf3f57ddabd980074ffd113afcfb9313d3d33db39f9fd81ba1be493dae0b2f972fc4197bdfa57c74dfe5af
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![Victor](/examples//15_victor_logo.svg)
1
+ ![Victor](/examples/16_victor_logo.svg)
2
2
 
3
3
  # Victor - Ruby SVG Image Builder
4
4
 
@@ -71,7 +71,7 @@ svg.save 'pacman'
71
71
 
72
72
  Output:
73
73
 
74
- [![pacman](https://cdn.rawgit.com/DannyBen/victor/master/examples/09_pacman.svg)](https://github.com/DannyBen/victor/blob/master/examples/09_pacman.rb)
74
+ [![pacman](https://cdn.rawgit.com/DannyBen/victor/master/examples/10_pacman.svg)](https://github.com/DannyBen/victor/blob/master/examples/10_pacman.rb)
75
75
 
76
76
 
77
77
  See the [examples] folder for several ruby scripts and their SVG output.
@@ -148,7 +148,7 @@ space delimited string:
148
148
 
149
149
  ```ruby
150
150
  svg.path d: ['M', 150, 0, 'L', 75, 200, 'L', 225, 200, 'Z']
151
- # => <path d="M 159 9 L 75 200 L 225 200 Z"/>
151
+ # => <path d="M 150 0 L 75 200 L 225 200 Z"/>
152
152
  ```
153
153
 
154
154
  For SVG elements that have an inner content - such as text - simply pass it as
@@ -185,7 +185,7 @@ svg.text "Victor", x: 40, y: 50, font_family: 'arial', font_weight: 'bold', font
185
185
 
186
186
  ### Composite SVG
187
187
 
188
- Victor also supports the abiliy to combine several smaller SVG objects into
188
+ Victor also supports the ability to combine several smaller SVG objects into
189
189
  one using the `<<` operator or the `#append` method.
190
190
 
191
191
  This operator expects to receive any object that responds to `#to_s` (can be another `SVG` object).
@@ -215,7 +215,7 @@ svg.save 'framed-troll'
215
215
 
216
216
  Output:
217
217
 
218
- [![troll](https://cdn.rawgit.com/DannyBen/victor/master/examples/13_composite_svg.svg)](https://cdn.rawgit.com/DannyBen/victor/master/examples/13_composite_svg.svg)
218
+ [![troll](https://cdn.rawgit.com/DannyBen/victor/master/examples/14_composite_svg.svg)](https://cdn.rawgit.com/DannyBen/victor/master/examples/14_composite_svg.svg)
219
219
 
220
220
  These two calls are identical:
221
221
 
@@ -244,8 +244,8 @@ end
244
244
  Another approach to a more modular SVG composition, would be to subclass
245
245
  `Victor::SVG`.
246
246
 
247
- See the [composite svg example](https://github.com/DannyBen/victor/tree/master/examples#13-composite-svg)
248
- or the [subclassing example](https://github.com/DannyBen/victor/tree/master/examples#14-subclassing)
247
+ See the [composite svg example](https://github.com/DannyBen/victor/tree/master/examples#14-composite-svg)
248
+ or the [subclassing example](https://github.com/DannyBen/victor/tree/master/examples#15-subclassing)
249
249
  for more details.
250
250
 
251
251
 
@@ -294,8 +294,30 @@ svg.render template: :minimal
294
294
 
295
295
  ### CSS
296
296
 
297
- To add a CSS to your SVG, simply use the `css` command inside your `build`
298
- block, like this:
297
+ CSS gets a special treatment in `Victor::SVG`, with these objectives in mind:
298
+
299
+ - Hide implementation details (such as the need for a `CDATA` marker)
300
+ - Provide a DSL-like syntax for CSS rules
301
+
302
+ The `Victor::SVG` objects has a `css` property, which can contain either a
303
+ Hash or a String:
304
+
305
+ ```ruby
306
+ svg = Victor::SVG.new
307
+
308
+ svg.css = css_hash_or_string
309
+ # or without the equal sign:
310
+ svg.css css_hash_or_string
311
+
312
+ svg.build do
313
+ # ...
314
+ end
315
+ ```
316
+
317
+ This flexibility allows you to apply CSS in multiple ways. Below are some
318
+ examples.
319
+
320
+ #### Assigning CSS rules using the hash syntax
299
321
 
300
322
  ```ruby
301
323
  svg = Victor::SVG.new
@@ -311,7 +333,7 @@ svg.build do
311
333
  end
312
334
  ```
313
335
 
314
- You can also set CSS by providing a hash:
336
+ #### Assigning a full hash to the CSS property
315
337
 
316
338
  ```ruby
317
339
  svg.css = {
@@ -332,6 +354,13 @@ svg.css = {
332
354
  Underscore characters will be converted to dashes (`stroke_width` becomes
333
355
  `stroke-width`).
334
356
 
357
+ #### Importing CSS from an external file
358
+
359
+ ```ruby
360
+ svg.css = File.read 'styles.css'
361
+ ```
362
+
363
+ #### CSS `@import` directives
335
364
 
336
365
  If you need to add CSS statements , like `@import`, use the following syntax:
337
366
 
@@ -342,11 +371,13 @@ css['@import'] = [
342
371
  ]
343
372
  ```
344
373
 
345
- When the value of the CSS attribute is an array, Victor will simply use
346
- the values of the array and prefix each of them with the key, so the above
347
- will result in two `@import url(...)` rows.
374
+ This is achieved thanks to the fact that when Victor encounters an array
375
+ in the CSS hash, it will prefix each of the array elements with the hash
376
+ key, so the above will result in two `@import url(...)` rows.
348
377
 
349
- See the [custom fonts example](https://github.com/DannyBen/victor/tree/master/examples#12-custom-fonts).
378
+ See the [css example](https://github.com/DannyBen/victor/tree/master/examples#08-css),
379
+ [css string example](https://github.com/DannyBen/victor/tree/master/examples#09-css-string),
380
+ or the [custom fonts example](https://github.com/DannyBen/victor/tree/master/examples#13-custom-fonts).
350
381
 
351
382
 
352
383
  ### Tagless Elements
@@ -375,7 +406,7 @@ svg.build do
375
406
  end
376
407
  ```
377
408
 
378
- See the [targless elements example](https://github.com/DannyBen/victor/tree/master/examples#16-tagless-elements).
409
+ See the [tagless elements example](https://github.com/DannyBen/victor/tree/master/examples#17-tagless-elements).
379
410
 
380
411
 
381
412
  ### XML Encoding
@@ -398,7 +429,7 @@ end
398
429
  # <text>Ben & Jerry's</text>
399
430
  ```
400
431
 
401
- See the [xml encoding example](https://github.com/DannyBen/victor/tree/master/examples#17-xml-encoding).
432
+ See the [xml encoding example](https://github.com/DannyBen/victor/tree/master/examples#18-xml-encoding).
402
433
 
403
434
  ### DSL Syntax
404
435
 
@@ -424,7 +455,7 @@ puts render
424
455
  save 'output.svg'
425
456
  ```
426
457
 
427
- See the [dsl example](https://github.com/DannyBen/victor/tree/master/examples#18-dsl).
458
+ See the [dsl example](https://github.com/DannyBen/victor/tree/master/examples#19-dsl).
428
459
 
429
460
  ## Using with Rails
430
461
 
@@ -442,6 +473,13 @@ Victor Ruby scripts.
442
473
 
443
474
  A Victor playground that works in the browser.
444
475
 
476
+ ### [Minichart][minichart]
477
+
478
+ A Ruby gem that uses Victor to generate SVG charts
479
+
480
+ [![Minichart](assets/minichart.svg)][minichart]
481
+
482
+
445
483
  ### [Icodi][icodi]
446
484
 
447
485
  A Ruby gem that uses Victor to generate consistent random icon
@@ -460,6 +498,7 @@ to contribute, feel free to [open an issue][issues].
460
498
  [examples]: https://github.com/DannyBen/victor/tree/master/examples#examples
461
499
  [templates]: https://github.com/DannyBen/victor/tree/master/lib/victor/templates
462
500
  [icodi]: https://github.com/DannyBen/icodi
501
+ [minichart]: https://github.com/DannyBen/minichart
463
502
  [victor-opal]: https://kuboon.github.io/victor-opal/
464
503
  [victor-cli]: https://github.com/DannyBen/victor-cli
465
504
  [issues]: https://github.com/DannyBen/victor/issues
data/lib/victor/dsl.rb CHANGED
@@ -3,7 +3,7 @@ require 'forwardable'
3
3
  module Victor
4
4
  module DSL
5
5
  extend Forwardable
6
- def_delegators :svg, :setup, :build, :save, :render, :append, :element
6
+ def_delegators :svg, :setup, :build, :save, :render, :append, :element, :css
7
7
 
8
8
  def svg
9
9
  @svg ||= Victor::SVG.new
@@ -1,13 +1,12 @@
1
1
  module Victor
2
2
 
3
3
  class SVGBase
4
- attr_accessor :template, :css
4
+ attr_accessor :template
5
5
  attr_reader :content, :svg_attributes
6
6
 
7
7
  def initialize(attributes = nil, &block)
8
8
  setup attributes
9
9
  @content = []
10
- @css = {}
11
10
  build &block if block_given?
12
11
  end
13
12
 
@@ -63,13 +62,23 @@ module Victor
63
62
  end
64
63
  end
65
64
 
65
+ def css(defs = nil)
66
+ @css ||= {}
67
+ @css = defs if defs
68
+ @css
69
+ end
70
+
71
+ def css=(defs)
72
+ @css = defs
73
+ end
74
+
66
75
  def render(template: nil)
67
76
  @template = template if template
68
- css_string = CSS.new css
77
+ css_handler = CSS.new css
69
78
 
70
79
  svg_template % {
71
- css: css_string,
72
- style: css_string.render,
80
+ css: css_handler,
81
+ style: css_handler.render,
73
82
  attributes: svg_attributes,
74
83
  content: content.join("\n")
75
84
  }
@@ -1,3 +1,3 @@
1
1
  module Victor
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
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.2
4
+ version: 0.3.3
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: 2020-05-14 00:00:00.000000000 Z
11
+ date: 2021-05-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Build SVG images with ease
14
14
  email: db@dannyben.com
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  requirements: []
50
- rubygems_version: 3.1.2
50
+ rubygems_version: 3.2.16
51
51
  signing_key:
52
52
  specification_version: 4
53
53
  summary: SVG Builder