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 +4 -4
- data/README.md +56 -17
- data/lib/victor/dsl.rb +1 -1
- data/lib/victor/svg_base.rb +14 -5
- data/lib/victor/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4fb744c40ffdf04d89198bbe192150e73fc6776f2fc92f26bfd246c1f107c98
|
4
|
+
data.tar.gz: 1360dae8be0520d6357ec7300c19cb7a7769cc656081fa1f66dd5bfdbe2895b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed68e9abbe74e3abe5c910f24c6dc988365da107317836649c0f9aef22a7876e7b27c7ea7f18c77d07e436951bb092123f9432a1faa3189e4900b8f3fcb217fe
|
7
|
+
data.tar.gz: 313a4bd4034c8ea18d5e111fb22e7f4073d6f9dff7cf3f57ddabd980074ffd113afcfb9313d3d33db39f9fd81ba1be493dae0b2f972fc4197bdfa57c74dfe5af
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-

|
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
|
-
[](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
|
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
|
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
|
-
[](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#
|
248
|
-
or the [subclassing example](https://github.com/DannyBen/victor/tree/master/examples#
|
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
|
-
|
298
|
-
|
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
|
-
|
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
|
-
|
346
|
-
the
|
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 [
|
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 [
|
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#
|
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#
|
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]
|
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
data/lib/victor/svg_base.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
module Victor
|
2
2
|
|
3
3
|
class SVGBase
|
4
|
-
attr_accessor :template
|
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
|
-
|
77
|
+
css_handler = CSS.new css
|
69
78
|
|
70
79
|
svg_template % {
|
71
|
-
css:
|
72
|
-
style:
|
80
|
+
css: css_handler,
|
81
|
+
style: css_handler.render,
|
73
82
|
attributes: svg_attributes,
|
74
83
|
content: content.join("\n")
|
75
84
|
}
|
data/lib/victor/version.rb
CHANGED
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.
|
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:
|
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.
|
50
|
+
rubygems_version: 3.2.16
|
51
51
|
signing_key:
|
52
52
|
specification_version: 4
|
53
53
|
summary: SVG Builder
|