victor-cli 0.3.7 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce744b2b082946dbf4de7f8520c64b21e6d1c36351bcf7713367e953dd392d37
4
- data.tar.gz: c76d15b13b96e4d4782b41b0ab74d5423f0024bd2d0a4ae58cfd7ee0e055144a
3
+ metadata.gz: 68eb51ef26c1d7c3c6caae0e57f92e0781b1291a141843216a9931c986a7364f
4
+ data.tar.gz: e185c0265b30bdb56f361d874aca8c5751617557896449189ff04d37772b5156
5
5
  SHA512:
6
- metadata.gz: 90b0c065db9774ff300ea7a0d848bd8b0cdf41355418113c9fbd07d27dcbcb52ff4412967b5cb4476148acf23de71b9a4b44ca11b54356c706aceeb1e8af47cc
7
- data.tar.gz: '097a7e56ff5d6f7d09c683d71ab2151a5eb49a10174ed4823e115e60872de5209e5663a79e688c1feb45f863ae141e8cd6125cfb049360eecd21e8b74e0dbba7'
6
+ metadata.gz: ddf03db760406c47377ce311e6047da11a1e357d8f36277de219aebdc9b35da303da97d27db491528015f11f9229c252d0bc00ca897b2427e36d1bebcd69009a
7
+ data.tar.gz: b87940516ed8144fc0a2a16da8e9e16ed7968838d3bcdab3497fe2cd75612a772b37c6c4869430591e66a26495dd4371d28865fcd3c6b791181bdb1222000b7b
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,7 +3,8 @@ require 'victor/cli'
3
3
  require 'pretty_trace/enable-trim'
4
4
 
5
5
  include Colsole
6
- PrettyTrace.filter [/gem/, /lib/, %r{bin/victor}]
6
+
7
+ PrettyTrace.filter [/gem/, /lib/, %r{bin/victor}, %r{bin/bundle}]
7
8
  PrettyTrace.debug_tip
8
9
 
9
10
  router = Victor::CLI::CommandLine.router
@@ -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
 
@@ -51,7 +58,7 @@ module Victor
51
58
  def watch
52
59
  say "Watching #{ruby_file} for changes"
53
60
  file_watcher.watch do |changes|
54
- changes.each do |_path, event|
61
+ changes.each_value do |event|
55
62
  yield unless event == :deleted
56
63
  end
57
64
  end
@@ -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.7'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
data/lib/victor/cli.rb CHANGED
@@ -5,8 +5,3 @@ 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
-
9
- if ENV['BYEBUG']
10
- require 'byebug'
11
- require 'lp'
12
- end
metadata CHANGED
@@ -1,36 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: victor-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0
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: 2023-03-20 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
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: 0.8.1
21
- - - "<"
17
+ - - "~>"
22
18
  - !ruby/object:Gem::Version
23
- version: '2.0'
19
+ version: '1.0'
24
20
  type: :runtime
25
21
  prerelease: false
26
22
  version_requirements: !ruby/object:Gem::Requirement
27
23
  requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- version: 0.8.1
31
- - - "<"
24
+ - - "~>"
32
25
  - !ruby/object:Gem::Version
33
- version: '2.0'
26
+ version: '1.0'
34
27
  - !ruby/object:Gem::Dependency
35
28
  name: css_parser
36
29
  requirement: !ruby/object:Gem::Requirement
@@ -93,14 +86,14 @@ dependencies:
93
86
  requirements:
94
87
  - - "~>"
95
88
  - !ruby/object:Gem::Version
96
- version: '0.2'
89
+ version: '0.3'
97
90
  type: :runtime
98
91
  prerelease: false
99
92
  version_requirements: !ruby/object:Gem::Requirement
100
93
  requirements:
101
94
  - - "~>"
102
95
  - !ruby/object:Gem::Version
103
- version: '0.2'
96
+ version: '0.3'
104
97
  - !ruby/object:Gem::Dependency
105
98
  name: requires
106
99
  requirement: !ruby/object:Gem::Requirement
@@ -135,14 +128,28 @@ dependencies:
135
128
  requirements:
136
129
  - - "~>"
137
130
  - !ruby/object:Gem::Version
138
- version: '0.3'
131
+ version: '0.4'
139
132
  type: :runtime
140
133
  prerelease: false
141
134
  version_requirements: !ruby/object:Gem::Requirement
142
135
  requirements:
143
136
  - - "~>"
144
137
  - !ruby/object:Gem::Version
145
- version: '0.3'
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'
146
153
  description: CLI for Victor, the SVG Library
147
154
  email: db@dannyben.com
148
155
  executables:
@@ -159,6 +166,7 @@ files:
159
166
  - lib/victor/cli/commands/init.rb
160
167
  - lib/victor/cli/commands/render.rb
161
168
  - lib/victor/cli/css_data.rb
169
+ - lib/victor/cli/refinements/pair_split.rb
162
170
  - lib/victor/cli/refinements/rendering.rb
163
171
  - lib/victor/cli/ruby_source.rb
164
172
  - lib/victor/cli/svg_node.rb
@@ -176,8 +184,10 @@ homepage: https://github.com/dannyben/victor-cli
176
184
  licenses:
177
185
  - MIT
178
186
  metadata:
187
+ bug_tracker_uri: https://github.com/DannyBen/victor-cli/issues
188
+ changelog_uri: https://github.com/DannyBen/victor-cli/blob/master/CHANGELOG.md
189
+ source_code_uri: https://github.com/DannyBen/victor-cli
179
190
  rubygems_mfa_required: 'true'
180
- post_install_message:
181
191
  rdoc_options: []
182
192
  require_paths:
183
193
  - lib
@@ -185,15 +195,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
195
  requirements:
186
196
  - - ">="
187
197
  - !ruby/object:Gem::Version
188
- version: 2.7.0
198
+ version: '3.2'
189
199
  required_rubygems_version: !ruby/object:Gem::Requirement
190
200
  requirements:
191
201
  - - ">="
192
202
  - !ruby/object:Gem::Version
193
203
  version: '0'
194
204
  requirements: []
195
- rubygems_version: 3.4.8
196
- signing_key:
205
+ rubygems_version: 3.6.9
197
206
  specification_version: 4
198
207
  summary: CLI for Victor, the SVG Library
199
208
  test_files: []