inkscape_cli 1.0.0
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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +6 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +12 -0
- data/lib/inkscape_cli/command.rb +67 -0
- data/lib/inkscape_cli/configuration.rb +21 -0
- data/lib/inkscape_cli/version.rb +5 -0
- data/lib/inkscape_cli.rb +16 -0
- data/sig/inkscape_cli/command.rbs +15 -0
- data/sig/inkscape_cli/configuration.rbs +7 -0
- data/sig/inkscape_cli.rbs +4 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ae27b1a9b4ac0dc176a208e9d920be8cd546b8bf7d5d1b1acbcee201723f7c65
|
4
|
+
data.tar.gz: 5e7dff339cef1addadb37e8dcac4f536fd5b611b60d9542bbe79e0bb61df0ac7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bdea31313fbbe64747e9f7240dbf40c4a92d4a8061fae0c4bb77aff810d342c273128556e1a97ca07754ebe7230d905b66f52c35f8c41cdef01e54a377b4cb8e
|
7
|
+
data.tar.gz: 3b5b9fbd1f333f508f2ea8837bf58c40f231f446221326a96389fb45cfd4ab0da16ef4efeeb5ce61b940904499eb047b460f79b6f00a1b76c76d2f03458b3098
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
inkscape_cli (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
json (2.6.3)
|
12
|
+
parallel (1.22.1)
|
13
|
+
parser (3.2.1.1)
|
14
|
+
ast (~> 2.4.1)
|
15
|
+
rainbow (3.1.1)
|
16
|
+
rake (13.0.6)
|
17
|
+
regexp_parser (2.7.0)
|
18
|
+
rexml (3.2.5)
|
19
|
+
rspec (3.12.0)
|
20
|
+
rspec-core (~> 3.12.0)
|
21
|
+
rspec-expectations (~> 3.12.0)
|
22
|
+
rspec-mocks (~> 3.12.0)
|
23
|
+
rspec-core (3.12.1)
|
24
|
+
rspec-support (~> 3.12.0)
|
25
|
+
rspec-expectations (3.12.2)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.12.0)
|
28
|
+
rspec-mocks (3.12.5)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.12.0)
|
31
|
+
rspec-support (3.12.0)
|
32
|
+
rubocop (1.48.1)
|
33
|
+
json (~> 2.3)
|
34
|
+
parallel (~> 1.10)
|
35
|
+
parser (>= 3.2.0.0)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.8, < 3.0)
|
38
|
+
rexml (>= 3.2.5, < 4.0)
|
39
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
42
|
+
rubocop-ast (1.28.0)
|
43
|
+
parser (>= 3.2.1.0)
|
44
|
+
ruby-progressbar (1.13.0)
|
45
|
+
unicode-display_width (2.4.2)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
x86_64-darwin-20
|
49
|
+
x86_64-linux
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
inkscape_cli!
|
53
|
+
rake (~> 13.0)
|
54
|
+
rspec (~> 3.0)
|
55
|
+
rubocop (~> 1.21)
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.3.20
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Marco Adkins
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# InkscapeCLI
|
2
|
+
Simple ruby wrapper for inkscape cli
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Install the gem and add to the application's Gemfile by executing:
|
7
|
+
|
8
|
+
$ bundle add inkscape_cli
|
9
|
+
|
10
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
11
|
+
|
12
|
+
$ gem install inkscape_cli
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
```ruby
|
16
|
+
require 'inkscape_cli'
|
17
|
+
|
18
|
+
command = InkscapeCLI::Command.new
|
19
|
+
command.input_file = 'input.svg'
|
20
|
+
command.export_width(500)
|
21
|
+
command.export_filename('out.png')
|
22
|
+
command.execute
|
23
|
+
|
24
|
+
InkscapeCLI::Command.new.input_file('input.svg').export_filename('out.png').execute
|
25
|
+
|
26
|
+
InkscapeCLI::Command.new do |command|
|
27
|
+
command.input_file = 'input.svg'
|
28
|
+
command.export_filename = 'out.png'
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
## Configuration
|
33
|
+
```ruby
|
34
|
+
InkscapeCLI.configure do |config|
|
35
|
+
config.executable = 'inkscape'
|
36
|
+
config.timeout = 300
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
## Development
|
41
|
+
|
42
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
43
|
+
|
44
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/marcoadkins/inkscape_cli.
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InkscapeCLI
|
4
|
+
class Command
|
5
|
+
attr_reader :executable, :args, :timeout
|
6
|
+
|
7
|
+
def self.new(*args)
|
8
|
+
instance = super(*args)
|
9
|
+
|
10
|
+
if block_given?
|
11
|
+
yield instance
|
12
|
+
instance.execute
|
13
|
+
else
|
14
|
+
instance
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(executable: InkscapeCLI.executable, timeout: InkscapeCLI.timeout)
|
19
|
+
@executable = executable
|
20
|
+
@args = []
|
21
|
+
@timeout = timeout
|
22
|
+
end
|
23
|
+
|
24
|
+
def execute
|
25
|
+
Open3.popen3(executable, *args) do |_stdin, stdout, stderr, thread|
|
26
|
+
[stdout, stderr].each(&:binmode)
|
27
|
+
stdout_reader = Thread.new { stdout.read }
|
28
|
+
stderr_reader = Thread.new { stderr.read }
|
29
|
+
|
30
|
+
unless thread.join(timeout)
|
31
|
+
Process.kill("TERM", thread.pid) rescue nil
|
32
|
+
Process.waitpid(thread.pid) rescue nil
|
33
|
+
raise Timeout::Error, "Inkscape command timed out..."
|
34
|
+
end
|
35
|
+
|
36
|
+
exit_status = thread.value.exitstatus
|
37
|
+
if exit_status != 0
|
38
|
+
raise InkscapeCLI::Error,
|
39
|
+
"Inkscape command failed with status: #{exit_status} and error: #{stderr_reader.value}"
|
40
|
+
end
|
41
|
+
|
42
|
+
[stdout_reader.value, stderr_reader.value, exit_status]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def input_file(file)
|
47
|
+
self << file
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
alias_method :input_file=, :input_file
|
52
|
+
|
53
|
+
def <<(arg)
|
54
|
+
args << arg.to_s
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
def method_missing(name, *args)
|
59
|
+
option = "--#{name.to_s.tr('_', '-').gsub('=', '')}"
|
60
|
+
self.args << option
|
61
|
+
args.each do |arg|
|
62
|
+
self.args << arg.to_s
|
63
|
+
end
|
64
|
+
self
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InkscapeCLI
|
4
|
+
module Configuration
|
5
|
+
def configure
|
6
|
+
yield self
|
7
|
+
end
|
8
|
+
|
9
|
+
def define_setting(name, default = nil)
|
10
|
+
instance_variable_set("@#{name}", default)
|
11
|
+
|
12
|
+
define_singleton_method "#{name}=" do |value|
|
13
|
+
instance_variable_set("@#{name}", value)
|
14
|
+
end
|
15
|
+
|
16
|
+
define_singleton_method name do
|
17
|
+
instance_variable_get("@#{name}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/inkscape_cli.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'inkscape_cli/version'
|
4
|
+
require_relative 'inkscape_cli/command'
|
5
|
+
require 'inkscape_cli/configuration'
|
6
|
+
require 'open3'
|
7
|
+
require 'timeout'
|
8
|
+
|
9
|
+
module InkscapeCLI
|
10
|
+
extend InkscapeCLI::Configuration
|
11
|
+
|
12
|
+
define_setting :executable, 'inkscape'
|
13
|
+
define_setting :timeout, 300
|
14
|
+
|
15
|
+
class Error < StandardError; end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module InkscapeCLI
|
2
|
+
class Command
|
3
|
+
attr_reader args: Array[String]
|
4
|
+
attr_reader executable: String
|
5
|
+
attr_reader timeout: Integer
|
6
|
+
|
7
|
+
def self.new: -> Command
|
8
|
+
def initialize: (?executable:String, ?timeout:Integer) -> Command
|
9
|
+
def <<: (String) -> Command
|
10
|
+
def execute: -> Command
|
11
|
+
def input_file: (String) -> Command
|
12
|
+
def input_file=: (String) -> Command
|
13
|
+
def method_missing: -> Command
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inkscape_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marco Adkins
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Handles escaping and preventing malicious commands while shelling out
|
14
|
+
to inkscape.
|
15
|
+
email:
|
16
|
+
- marcoadkins88@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".rspec"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- CHANGELOG.md
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- lib/inkscape_cli.rb
|
30
|
+
- lib/inkscape_cli/command.rb
|
31
|
+
- lib/inkscape_cli/configuration.rb
|
32
|
+
- lib/inkscape_cli/version.rb
|
33
|
+
- sig/inkscape_cli.rbs
|
34
|
+
- sig/inkscape_cli/command.rbs
|
35
|
+
- sig/inkscape_cli/configuration.rbs
|
36
|
+
homepage: https://github.com/eezyinc/inkscape_cli
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata:
|
40
|
+
homepage_uri: https://github.com/eezyinc/inkscape_cli
|
41
|
+
source_code_uri: https://github.com/eezyinc/inkscape_cli
|
42
|
+
changelog_uri: https://github.com/eezyinc/inkscape_cli/CHANGELOG.md
|
43
|
+
rubygems_mfa_required: 'true'
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.6.0
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.1.6
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Safe inkscape command line interface
|
63
|
+
test_files: []
|