victor-cli 0.3.8 → 0.4.1

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: ae572af3658e7deee923e58a2cf98291d33c3916002d02a236a61b444e93e54e
4
- data.tar.gz: c4c9b1075a852bfebfd008c45a14032d42df459356ec646ee12cd0bdc5c3fca4
3
+ metadata.gz: f0ed324cb5ba0472bebcb5eb497c288d88c90f4ec4edb2fdb6d7a752323424ba
4
+ data.tar.gz: 3ce04218f855f60ca6c303ac83a28f48d413508cad29619c02c3d9d3c1a05118
5
5
  SHA512:
6
- metadata.gz: f642ac864d24273b28c6539925cb109a725f2c21bf3f83fee7bb5cede14267f8af5a2e968aa9290738a2a2e3f5b15f10d9a416d6fafa13f91d6558f5eb2c85ef
7
- data.tar.gz: fdc56653a55b1f2d6a4a1cb5ef99c1856e62982611749a2a1ea99e0e114cfc5f5d66a800efb8839e5ff0d7c4c0934948b45c54a4a84c184b1a340c0615314964
6
+ metadata.gz: 688682610e101eb864750e8c2e3906b7bea4d50ce7c8bb96fe7c748ae561bc85e46c924a8f37122af7ffc5c58f6b2dac30e365c09953547ddcdc47967d6704cd
7
+ data.tar.gz: 989722f87a901add75dc40e2cf51f24d38209068178a4e6772d28940d8dcdc0e0a790c1fae8aeef6b782cb6b724b9ae7110ea7e7ea9ad25292f67cec04436e07
data/README.md CHANGED
@@ -1,15 +1,7 @@
1
1
  # Victor CLI
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/victor-cli.svg)](https://badge.fury.io/rb/victor-cli)
4
- [![Build Status](https://github.com/DannyBen/victor-cli/workflows/Test/badge.svg)](https://github.com/DannyBen/victor-cli/actions?query=workflow%3ATest)
5
- [![Maintainability](https://api.codeclimate.com/v1/badges/ab7a46b42d268e374ee1/maintainability)](https://codeclimate.com/github/DannyBen/victor-cli/maintainability)
6
-
7
- ---
8
-
9
3
  Command line interface for [Victor][victor], the SVG Library.
10
4
 
11
- ---
12
-
13
5
  ## Installation
14
6
 
15
7
  $ gem install victor-cli
@@ -32,21 +24,24 @@ Given this Ruby code:
32
24
  # example.rb
33
25
  setup width: 140, height: 100
34
26
 
27
+ # allow changing parameters from the command line
28
+ color = params[:color] || :yellow
29
+
35
30
  build do
36
- circle cx: 50, cy: 50, r: 30, fill: "yellow"
31
+ circle cx: 50, cy: 50, r: 30, fill: color
37
32
  end
38
33
  ```
39
34
 
40
35
  Run this command:
41
36
  ```shell
42
- $ victor render example.rb --template minimal
37
+ $ victor render example.rb --template minimal color=blue
43
38
  ```
44
39
 
45
40
  To generate this code:
46
41
 
47
42
  ```xml
48
43
  <svg width="140" height="100">
49
- <circle cx="50" cy="50" r="30" fill="yellow"/>
44
+ <circle cx="50" cy="50" r="30" fill="blue"/>
50
45
  </svg>
51
46
  ```
52
47
 
data/bin/victor CHANGED
@@ -3,6 +3,7 @@ require 'victor/cli'
3
3
  require 'pretty_trace/enable-trim'
4
4
 
5
5
  include Colsole
6
+
6
7
  PrettyTrace.filter [/gem/, /lib/, %r{bin/victor}, %r{bin/bundle}]
7
8
  PrettyTrace.debug_tip
8
9
 
@@ -6,7 +6,7 @@ module Victor
6
6
  module CLI
7
7
  class CommandLine
8
8
  def self.router
9
- router = MisterBin::Runner.new version: VERSION,
9
+ router = MisterBin::Runner.new version: "#{Victor::CLI::VERSION} (victor #{Victor::VERSION})",
10
10
  header: 'Victor SVG Utilities'
11
11
 
12
12
  router.route 'init', to: Commands::Init
@@ -4,7 +4,7 @@ module Victor
4
4
  class Convert < Base
5
5
  summary 'Convert SVG to Ruby code'
6
6
 
7
- usage 'victor convert SVG_FILE [RUBY_FILE --template NAME]'
7
+ usage 'victor convert SVG_FILE [--save RUBY_FILE --template NAME]'
8
8
  usage 'victor convert (-h|--help)'
9
9
 
10
10
  option '-t, --template NAME', <<~USAGE
@@ -14,21 +14,15 @@ module Victor
14
14
  cli a Victor CLI compatible DSL script (default)
15
15
  USAGE
16
16
 
17
- param 'SVG_FILE', 'Input SVG file'
17
+ option '-o, --save RUBY_FILE', 'Save to RUBY file instead of printing to stdout'
18
+
18
19
  param 'RUBY_FILE', 'Output Ruby file. Leave empty to write to stdout'
19
20
 
20
- example 'victor convert example.svg example.rb'
21
+ example 'victor convert example.svg --save example.rb'
21
22
 
22
23
  def run
23
- svg_file = args['SVG_FILE']
24
- template = args['--template']
25
- svg_node = SVGNode.load_file svg_file, layout: template
26
-
27
24
  validate_template template if template
28
25
 
29
- code = svg_node.render
30
- ruby_file = args['RUBY_FILE']
31
-
32
26
  if ruby_file
33
27
  File.write ruby_file, code
34
28
  say "Saved #{ruby_file}"
@@ -37,6 +31,17 @@ module Victor
37
31
  end
38
32
  end
39
33
 
34
+ protected
35
+
36
+ def svg_file = args['SVG_FILE']
37
+ def template = args['--template']
38
+ def ruby_file = args['--save']
39
+
40
+ def svg_node = @svg_node ||= SVGNode.load_file(svg_file, layout: template)
41
+ def code = @code ||= svg_node.render
42
+
43
+ private
44
+
40
45
  def validate_template(template)
41
46
  allowed = %w[cli dsl standalone]
42
47
  return if allowed.include? template
@@ -4,9 +4,11 @@ module Victor
4
4
  module CLI
5
5
  module Commands
6
6
  class Render < Base
7
+ using PairSplit
8
+
7
9
  summary 'Render Ruby code to SVG'
8
10
 
9
- usage 'victor render RUBY_FILE [SVG_FILE] [options]'
11
+ usage 'victor render RUBY_FILE [options] [PARAMS...]'
10
12
  usage 'victor render (-h|--help)'
11
13
 
12
14
  option '-t, --template TEMPLATE', <<~USAGE
@@ -15,28 +17,33 @@ module Victor
15
17
  USAGE
16
18
 
17
19
  option '-w, --watch', 'Watch the source file and regenerate on change'
20
+ option '-o, --save SVG_FILE', 'Save to SVG file instead of printing to stdout'
18
21
 
19
22
  param 'RUBY_FILE', 'Input Ruby file'
20
- param 'SVG_FILE', 'Output SVG file. Leave empty to write to stdout'
23
+ param 'PARAMS', 'One or more key=value pairs that will be available in the `params` hash for the Ruby script'
21
24
 
22
- example 'victor render input.rb output.svg'
23
- example 'victor render input.rb output.svg --watch'
25
+ example 'victor render input.rb -o output.svg'
26
+ example 'victor render input.rb --save output.svg --watch'
24
27
  example 'victor render input.rb --template minimal'
28
+ example 'victor render input.rb color=black "text=Hello World"'
25
29
 
26
30
  def run
27
- if args['--watch']
28
- watch_and_generate
29
- else
30
- generate
31
- end
31
+ args['--watch'] ? watch_and_generate : generate
32
32
  end
33
33
 
34
+ protected
35
+
36
+ def ruby_file = args['RUBY_FILE']
37
+ def svg_file = args['--save']
38
+ def template = args['--template']
39
+ def params = @params ||= args['PARAMS'].pair_split
40
+
34
41
  private
35
42
 
36
43
  def generate
37
44
  code = File.read ruby_file
38
45
 
39
- ruby_source = RubySource.new code, ruby_file
46
+ ruby_source = RubySource.new code, filename: ruby_file, params: params
40
47
  ruby_source.evaluate
41
48
  ruby_source.template template if template
42
49
 
@@ -68,18 +75,6 @@ module Victor
68
75
  def file_watcher
69
76
  @file_watcher ||= Filewatcher.new(ruby_file, immediate: true)
70
77
  end
71
-
72
- def ruby_file
73
- args['RUBY_FILE']
74
- end
75
-
76
- def svg_file
77
- args['SVG_FILE']
78
- end
79
-
80
- def template
81
- args['--template']
82
- end
83
78
  end
84
79
  end
85
80
  end
@@ -0,0 +1,13 @@
1
+ module Victor
2
+ module CLI
3
+ module PairSplit
4
+ refine Array do
5
+ def pair_split(operator = '=')
6
+ return {} if empty?
7
+
8
+ to_h { |pair| pair.split(operator, 2) }.transform_keys(&:to_sym)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,14 +2,18 @@ module Victor
2
2
  module CLI
3
3
  class RubySource
4
4
  include Victor::DSL
5
- attr_reader :code, :filename
6
5
 
7
- def initialize(code, filename = nil)
6
+ attr_reader :code, :filename, :global_params, :params
7
+
8
+ def initialize(code, filename: nil, params: nil)
8
9
  @code = code
9
10
  @filename = filename
11
+ @global_params = params || {}
12
+ @params = global_params
10
13
  end
11
14
 
12
- def evaluate
15
+ def evaluate(local_params = nil)
16
+ @params = local_params || global_params
13
17
  if filename
14
18
  instance_eval code, filename
15
19
  else
@@ -1,5 +1,5 @@
1
1
  module Victor
2
2
  module CLI
3
- VERSION = '0.3.8'
3
+ VERSION = '0.4.1'
4
4
  end
5
5
  end
data/lib/victor/cli.rb CHANGED
@@ -5,3 +5,4 @@ require_relative 'cli/ruby_source'
5
5
  require_relative 'cli/css_data'
6
6
  require_relative 'cli/command_line'
7
7
  require_relative 'cli/svg_node'
8
+ require_relative 'cli/version'
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: victor-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  - Max Brosnahan
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2024-08-25 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: colsole
@@ -137,6 +136,20 @@ dependencies:
137
136
  - - "~>"
138
137
  - !ruby/object:Gem::Version
139
138
  version: '0.4'
139
+ - !ruby/object:Gem::Dependency
140
+ name: logger
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.6'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.6'
140
153
  description: CLI for Victor, the SVG Library
141
154
  email: db@dannyben.com
142
155
  executables:
@@ -153,6 +166,7 @@ files:
153
166
  - lib/victor/cli/commands/init.rb
154
167
  - lib/victor/cli/commands/render.rb
155
168
  - lib/victor/cli/css_data.rb
169
+ - lib/victor/cli/refinements/pair_split.rb
156
170
  - lib/victor/cli/refinements/rendering.rb
157
171
  - lib/victor/cli/ruby_source.rb
158
172
  - lib/victor/cli/svg_node.rb
@@ -174,7 +188,6 @@ metadata:
174
188
  changelog_uri: https://github.com/DannyBen/victor-cli/blob/master/CHANGELOG.md
175
189
  source_code_uri: https://github.com/DannyBen/victor-cli
176
190
  rubygems_mfa_required: 'true'
177
- post_install_message:
178
191
  rdoc_options: []
179
192
  require_paths:
180
193
  - lib
@@ -182,15 +195,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
195
  requirements:
183
196
  - - ">="
184
197
  - !ruby/object:Gem::Version
185
- version: '3.1'
198
+ version: '3.2'
186
199
  required_rubygems_version: !ruby/object:Gem::Requirement
187
200
  requirements:
188
201
  - - ">="
189
202
  - !ruby/object:Gem::Version
190
203
  version: '0'
191
204
  requirements: []
192
- rubygems_version: 3.5.17
193
- signing_key:
205
+ rubygems_version: 3.6.9
194
206
  specification_version: 4
195
207
  summary: CLI for Victor, the SVG Library
196
208
  test_files: []