victor 0.2.8 → 0.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +79 -36
- data/lib/victor.rb +1 -0
- data/lib/victor/dsl.rb +12 -0
- data/lib/victor/script.rb +3 -0
- data/lib/victor/svg_base.rb +17 -5
- data/lib/victor/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78e6037610dec3a931d3ef7609c4ff1c926a43e074ffec4bbc9b70bf8072ac42
|
4
|
+
data.tar.gz: 6411438f9c4a8f793f8a82acb3420d25447289b71327e68a12687c3bd1921c87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4e1e64a1078a877a56acc22019b34f209354c085f6d527b96f334c510575ed8ecad8d2d6faca570c04324f898370722d7b72458aaefafa3ea7ec46e4344582f
|
7
|
+
data.tar.gz: d7f2105b59660a86f181df83641875407086308714f052d7b7edaef4084fd1bf0a72e06d4301976cb9efd23c599a1f56636b3a9d782aad64e8c8d41fcdfba9ab
|
data/README.md
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
![Victor](/examples//15_victor_logo.svg)
|
2
2
|
|
3
|
-
Victor - Ruby SVG Image Builder
|
4
|
-
==================================================
|
3
|
+
# Victor - Ruby SVG Image Builder
|
5
4
|
|
6
5
|
[![Gem Version](https://badge.fury.io/rb/victor.svg)](https://badge.fury.io/rb/victor)
|
7
|
-
[![Build Status](https://
|
8
|
-
[![Code Quality](https://api.codacy.com/project/badge/Grade/a502c262875643eabb01a43f7f5131ff)](https://www.codacy.com/app/db/victor?utm_source=github.com&utm_medium=referral&utm_content=DannyBen/victor&utm_campaign=Badge_Grade)
|
6
|
+
[![Build Status](https://github.com/DannyBen/victor/workflows/Test/badge.svg)](https://github.com/DannyBen/victor/actions?query=workflow%3ATest)
|
9
7
|
[![Maintainability](https://api.codeclimate.com/v1/badges/85cc05c219d6d233ab78/maintainability)](https://codeclimate.com/github/DannyBen/victor/maintainability)
|
10
8
|
|
11
9
|
---
|
@@ -17,25 +15,26 @@ directly to SVG elements.
|
|
17
15
|
|
18
16
|
---
|
19
17
|
|
20
|
-
Table of Contents
|
21
|
-
--------------------------------------------------
|
18
|
+
## Table of Contents
|
22
19
|
|
23
20
|
* [Install](#install)
|
24
21
|
* [Examples](#examples)
|
25
22
|
* [Usage](#usage)
|
26
|
-
* [
|
27
|
-
* [
|
28
|
-
* [
|
29
|
-
* [
|
30
|
-
* [
|
31
|
-
* [
|
23
|
+
* [Features](#features)
|
24
|
+
* [Composite SVG](#composite-svg)
|
25
|
+
* [Saving the Output](#saving-the-output)
|
26
|
+
* [SVG Templates](#svg-templates)
|
27
|
+
* [CSS](#css)
|
28
|
+
* [Tagless Elements](#tagless-elements)
|
29
|
+
* [XML Encoding](#xml-encoding)
|
30
|
+
* [DSL Syntax](#dsl-syntax)
|
32
31
|
* [Using with Rails](#using-with-rails)
|
33
32
|
* [Related Projects](#related-projects)
|
33
|
+
* [Contributing / Support](#contributing--support)
|
34
34
|
|
35
35
|
---
|
36
36
|
|
37
|
-
Install
|
38
|
-
--------------------------------------------------
|
37
|
+
## Install
|
39
38
|
|
40
39
|
```
|
41
40
|
$ gem install victor
|
@@ -47,8 +46,7 @@ Or with bundler:
|
|
47
46
|
gem 'victor'
|
48
47
|
```
|
49
48
|
|
50
|
-
Examples
|
51
|
-
--------------------------------------------------
|
49
|
+
## Examples
|
52
50
|
|
53
51
|
```ruby
|
54
52
|
require 'victor'
|
@@ -79,8 +77,7 @@ Output:
|
|
79
77
|
See the [examples] folder for several ruby scripts and their SVG output.
|
80
78
|
|
81
79
|
|
82
|
-
Usage
|
83
|
-
--------------------------------------------------
|
80
|
+
## Usage
|
84
81
|
|
85
82
|
Initialize your SVG image:
|
86
83
|
|
@@ -99,6 +96,14 @@ svg = Victor::SVG.new width: '100%', height: '100%'
|
|
99
96
|
svg = Victor::SVG.new width: '100%', height: '100%', viewBox: "0 0 200 100"
|
100
97
|
```
|
101
98
|
|
99
|
+
As an alternative, you can set the root SVG attributes using the `setup` method:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
require 'victor'
|
103
|
+
svg = Victor::SVG.new
|
104
|
+
svg.setup width: 200, height: 150
|
105
|
+
```
|
106
|
+
|
102
107
|
Victor uses a single method (`element`) to generate all SVG elements:
|
103
108
|
|
104
109
|
```ruby
|
@@ -176,8 +181,10 @@ svg.text "Victor", x: 40, y: 50, font_family: 'arial', font_weight: 'bold', font
|
|
176
181
|
# </text>
|
177
182
|
```
|
178
183
|
|
179
|
-
|
180
|
-
|
184
|
+
## Features
|
185
|
+
|
186
|
+
### Composite SVG
|
187
|
+
|
181
188
|
Victor also supports the abiliy to combine several smaller SVG objects into
|
182
189
|
one using the `<<` operator or the `#append` method.
|
183
190
|
|
@@ -225,8 +232,7 @@ or the [subclassing example](https://github.com/DannyBen/victor/tree/master/exam
|
|
225
232
|
for more details.
|
226
233
|
|
227
234
|
|
228
|
-
Saving the Output
|
229
|
-
--------------------------------------------------
|
235
|
+
### Saving the Output
|
230
236
|
|
231
237
|
Generate the full SVG to a string with `render`:
|
232
238
|
|
@@ -241,8 +247,7 @@ svg.save 'filename'
|
|
241
247
|
# the '.svg' extension is optional
|
242
248
|
```
|
243
249
|
|
244
|
-
SVG Templates
|
245
|
-
--------------------------------------------------
|
250
|
+
### SVG Templates
|
246
251
|
|
247
252
|
The `:default` SVG template is designed to be a full XML document (i.e.,
|
248
253
|
a standalone SVG image). If you wish to use the output as an SVG element
|
@@ -263,8 +268,7 @@ See the [templates] folder for an understanding of how templates are
|
|
263
268
|
structured.
|
264
269
|
|
265
270
|
|
266
|
-
CSS
|
267
|
-
--------------------------------------------------
|
271
|
+
### CSS
|
268
272
|
|
269
273
|
To add a CSS to your SVG, simply use the `css` command inside your `build`
|
270
274
|
block, like this:
|
@@ -321,8 +325,7 @@ will result in two `@import url(...)` rows.
|
|
321
325
|
See the [custom fonts example](https://github.com/DannyBen/victor/tree/master/examples#12-custom-fonts).
|
322
326
|
|
323
327
|
|
324
|
-
Tagless Elements
|
325
|
-
--------------------------------------------------
|
328
|
+
### Tagless Elements
|
326
329
|
|
327
330
|
Using underscore (`_`) as the element name will simply add the value to the
|
328
331
|
generated SVG, without any surrounding element. This is designed to allow
|
@@ -351,8 +354,7 @@ end
|
|
351
354
|
See the [targless elements example](https://github.com/DannyBen/victor/tree/master/examples#16-tagless-elements).
|
352
355
|
|
353
356
|
|
354
|
-
XML Encoding
|
355
|
-
--------------------------------------------------
|
357
|
+
### XML Encoding
|
356
358
|
|
357
359
|
Plain text values are encoded automatically:
|
358
360
|
|
@@ -374,24 +376,65 @@ end
|
|
374
376
|
|
375
377
|
See the [xml encoding example](https://github.com/DannyBen/victor/tree/master/examples#17-xml-encoding).
|
376
378
|
|
379
|
+
### DSL Syntax
|
380
|
+
|
381
|
+
Victor supports another a cleaner DSL-like syntax. To use it, simply `require 'victor/script'`.
|
377
382
|
|
383
|
+
Once required, you have access to:
|
378
384
|
|
379
|
-
|
380
|
-
|
385
|
+
- `svg` - returns an instance of `Victor::SVG`
|
386
|
+
- All the methods that are available on the `SVG` object, are included at the root level.
|
387
|
+
|
388
|
+
For example:
|
389
|
+
|
390
|
+
```ruby
|
391
|
+
require 'victor/script'
|
392
|
+
|
393
|
+
setup width: 100, height: 100
|
394
|
+
|
395
|
+
build do
|
396
|
+
circle cx: 50, cy: 50, r: 30, fill: "yellow"
|
397
|
+
end
|
398
|
+
|
399
|
+
puts render
|
400
|
+
save 'output.svg'
|
401
|
+
```
|
402
|
+
|
403
|
+
See the [dsl example](https://github.com/DannyBen/victor/tree/master/examples#18-dsl).
|
404
|
+
|
405
|
+
## Using with Rails
|
381
406
|
|
382
407
|
See the [example_rails](example_rails) folder.
|
383
408
|
|
384
409
|
|
385
|
-
Related Projects
|
386
|
-
|
410
|
+
## Related Projects
|
411
|
+
|
412
|
+
### [victor-cli]
|
413
|
+
|
414
|
+
A command line utility that generates Victor Ruby code from SVG code.
|
387
415
|
|
388
|
-
[
|
416
|
+
### [victor-opal]
|
417
|
+
|
418
|
+
A Victor playground that works in the browser.
|
419
|
+
|
420
|
+
### [Icodi]
|
421
|
+
|
422
|
+
A Ruby gem that uses Victor to generate consistent random icon
|
389
423
|
images, similar to GitHub's identicon.
|
390
424
|
|
391
425
|
[![Icodi](assets/icodi.svg)][icodi]
|
392
426
|
|
427
|
+
|
428
|
+
## Contributing / Support
|
429
|
+
|
430
|
+
If you experience any issue, have a question or a suggestion, or if you wish
|
431
|
+
to contribute, feel free to [open an issue][issues].
|
432
|
+
|
393
433
|
---
|
394
434
|
|
395
435
|
[examples]: https://github.com/DannyBen/victor/tree/master/examples#examples
|
396
436
|
[templates]: https://github.com/DannyBen/victor/tree/master/lib/victor/templates
|
397
|
-
[icodi]: https://github.com/DannyBen/icodi
|
437
|
+
[icodi]: https://github.com/DannyBen/icodi
|
438
|
+
[victor-opal]: https://kuboon.github.io/victor-opal/
|
439
|
+
[victor-cli]: https://github.com/DannyBen/victor-cli
|
440
|
+
[issues]: https://github.com/DannyBen/victor/issues
|
data/lib/victor.rb
CHANGED
data/lib/victor/dsl.rb
ADDED
data/lib/victor/svg_base.rb
CHANGED
@@ -4,11 +4,8 @@ module Victor
|
|
4
4
|
attr_accessor :template, :css
|
5
5
|
attr_reader :content, :svg_attributes
|
6
6
|
|
7
|
-
def initialize(attributes=
|
8
|
-
|
9
|
-
@svg_attributes = Attributes.new attributes
|
10
|
-
svg_attributes[:width] ||= "100%"
|
11
|
-
svg_attributes[:height] ||= "100%"
|
7
|
+
def initialize(attributes = nil)
|
8
|
+
setup attributes
|
12
9
|
@content = []
|
13
10
|
@css = {}
|
14
11
|
end
|
@@ -18,6 +15,20 @@ module Victor
|
|
18
15
|
end
|
19
16
|
alias append <<
|
20
17
|
|
18
|
+
def setup(attributes = nil)
|
19
|
+
attributes ||= {}
|
20
|
+
attributes[:width] ||= "100%"
|
21
|
+
attributes[:height] ||= "100%"
|
22
|
+
|
23
|
+
if attributes[:template]
|
24
|
+
@template = attributes.delete :template
|
25
|
+
elsif !@template
|
26
|
+
@template = :default
|
27
|
+
end
|
28
|
+
|
29
|
+
@svg_attributes = Attributes.new attributes
|
30
|
+
end
|
31
|
+
|
21
32
|
def build(&block)
|
22
33
|
self.instance_eval(&block)
|
23
34
|
end
|
@@ -53,6 +64,7 @@ module Victor
|
|
53
64
|
|
54
65
|
def render
|
55
66
|
css_string = CSS.new css
|
67
|
+
|
56
68
|
svg_template % {
|
57
69
|
css: css_string,
|
58
70
|
style: css_string.render,
|
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.
|
4
|
+
version: 0.3.0.rc1
|
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: 2020-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Build SVG images with ease
|
14
14
|
email: db@dannyben.com
|
@@ -20,6 +20,8 @@ files:
|
|
20
20
|
- lib/victor.rb
|
21
21
|
- lib/victor/attributes.rb
|
22
22
|
- lib/victor/css.rb
|
23
|
+
- lib/victor/dsl.rb
|
24
|
+
- lib/victor/script.rb
|
23
25
|
- lib/victor/svg.rb
|
24
26
|
- lib/victor/svg_base.rb
|
25
27
|
- lib/victor/templates/default.svg
|
@@ -41,11 +43,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
43
|
version: 2.3.0
|
42
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
45
|
requirements:
|
44
|
-
- - "
|
46
|
+
- - ">"
|
45
47
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
48
|
+
version: 1.3.1
|
47
49
|
requirements: []
|
48
|
-
rubygems_version: 3.0.
|
50
|
+
rubygems_version: 3.0.3
|
49
51
|
signing_key:
|
50
52
|
specification_version: 4
|
51
53
|
summary: SVG Builder
|